tramp-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to cleanup connection for file-exists-p


From: Dan Davison
Subject: How to cleanup connection for file-exists-p
Date: Wed, 25 Aug 2010 19:31:25 -0400
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.2 (gnu/linux)

It seems that file-exists-p sometimes requires
`tramp-cleanup-connection' to be executed in order for its return value
to be reliable. Specifically, if I create the file in a way that tramp
does not know about, then tramp may report that the file does not
exist when it does[1].

I am using 

       (if (file-remote-p default-directory)
           (tramp-cleanup-connection default-directory))

to accomplish this cache flushing. Is it reasonable to pass the
connection as string to tramp-cleanup-connection like that? Or should I
create the argument in some different way? Or is there a different way
to ensure that file-exists-p reports the correct answer?

Thanks,

Dan

Footnotes:

[1] In testing I have done this by creating the file in a separate ssh
session, outside emacs. But the use case that I am working on involves
the file being created by an emacs comint process.

Here's my test code:

(defun user-create (&optional flush)
  (let* ((default-directory "/address@hidden:")
         (localname "/tmp/tramp-test")
         (tmp-file (concat (file-remote-p default-directory) localname)))
    (shell-command (format "rm -f %s" localname))
    (tramp-cleanup-all-connections)
    (insert "\n------------\n")
    (insert (format "file is %s\n" tmp-file))
    (insert (format "file exists?\t%S\n" (file-exists-p tmp-file)))
    (insert (format "go create %s now!\n" tmp-file))
    (sit-for 7)
    (if flush (tramp-cleanup-connection default-directory))
    (insert (format "file exists?\t%S\n" (file-exists-p tmp-file)))
    (insert "------------\n")))


(user-create)
------------
file is /scp:address@hidden:/tmp/tramp-test
file exists?    nil
go create /scp:address@hidden:/tmp/tramp-test now!
file exists?    nil
------------

(user-create 'flush)
------------
file is /scp:address@hidden:/tmp/tramp-test
file exists?    nil
go create /scp:address@hidden:/tmp/tramp-test now!
file exists?    t
------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]