emacs-devel
[Top][All Lists]
Advanced

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

RE: testing for a remote file to include file on a Windows mappeddrive


From: Drew Adams
Subject: RE: testing for a remote file to include file on a Windows mappeddrive
Date: Sat, 26 Jan 2008 17:36:19 -0800

> But we shall come back to the original request of Drew: he wants to know
> whether a given file is "remote", independant of the syntax. Such
> information cannot be provided by 'file-remote-p', because that function
> has an important promise: "`file-remote-p' will never open a connection
> on its own." (from the doc-string). It also doesn't touch a local file;
> it works completely over the file name syntax. This promise is important
> because of performance.

I'm not looking for something that needs to be "independent of the syntax".
It could use the syntax sometimes, but it might need to go beyond the syntax
sometimes. On Windows, it would need to be able to tell when "h:/foo" might
name a file on a network drive, and the syntax alone won't suffice for that.
I think Stefan suggested something similar for symbolic links on other
platforms.

I'm looking for something that will, as you say, "never open a connection on
its own". I'm interested in saving time. I want to distinguish a string that
is likely to name a remote file or a file on a mapped network drive from a
string that is likely to name a local file. That's all.

The problem I posed was that I couldn't find a function that makes that
distinction. `file-remote-p', in particular, returns nil for a file that is
on a mapped network drive.

I don't care what the function is called - whether (a) `file-remote-p' is
tweaked to return non-nil for a file on a network drive or (b) some other
function is provided; either would be fine by me.

FWIW, I am currently using Eli's "NET USE" suggestion (thanks). It
distinguishes network drives from local drives and non-existent drives,
which is sufficient for my use. (AFAICT, it does not distinguish a local
drive from a non-existent drive, but that's OK.) This is what I have now:

(defun my-file-remote-p (file)
  "Non-nil means FILE is likely to name a file on a remote system.
For MS Windows, this includes a file on a mapped network drive."
  (or (and (eq system-type 'windows-nt)
           (let ((case-fold-search t))
             (and (string-match "\\`\\([a-z]:\\)" file)
                  (eq 0 (condition-case nil
                            (call-process
                             shell-file-name nil nil nil
                             shell-command-switch
                             (concat "NET USE "
                                     (match-string 1 file)))
                          (error nil))))))
      (and (fboundp 'ffap-file-remote-p)
           (ffap-file-remote-p file))
      (file-remote-p file)))

I'm not necessarily suggesting this for Emacs; I'm just saying that it seems
to work for me.

BTW: Can `file-remote-p' ever return non-nil when `ffap-remote-p' returns
nil? If not, I'll remove the `ffap-remote-p' test. My guess is that neither
is a proper subset of the other, so I use both.






reply via email to

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