emacs-pretest-bug
[Top][All Lists]
Advanced

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

Re: `file-relative-name' for compressed files


From: Michael Albinus
Subject: Re: `file-relative-name' for compressed files
Date: Sun, 13 Jun 2004 21:51:47 +0200
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux)

Emilio Lopes <address@hidden> writes:

> But while working on this I've found another problem:
>
>    (file-relative-name "/bar:/a/b/c/foo" "/xyz:/a/b/c/")
>    => "../../../../ssh:bar:/a/b/c/foo"
>
> It should return "/bar:/a/b/c/foo".
>
> The problem seems to come from TRAMP. TRAMP comes in because the
> handler for remote files is `tramp-file-name-handler'.
>
> For the example above the expansion of the arguments gives:
>
>    (expand-file-name "/bar:/a/b/c/foo")
>    => "/ssh:bar:/a/b/c/foo"
>
>    (expand-file-name "/xyz:/a/b/c/")
>    => "/ssh:xyz:/a/b/c/"
>
> The piece of code bellow from `file-relative-name' compares the
> host name part of the filenames, but it's fooled by TRAMP's method
> specification: because both filenames begin with "/ssh:" (that's
> what matching the names against `re' returns), they seem to reside
> on the same machine and `file-relative-name' returns a relative
> filename.
>
>          ;; Test for different remote file system identification
>          (and
>           hf
>           (let ((re (car (rassq hf file-name-handler-alist))))
>             (not
>              (equal
>               (and
>                (string-match re filename)
>                (substring filename 0 (match-end 0)))
>               (and
>                (string-match re directory)
>                (substring directory 0 (match-end 0)))))))
>
> It seems that TRAMP's `tramp-file-name-regexp-unified' ("\\`/[^/:]+:")
> should be reworked to account for its extended filename syntax.

Instead of trusting that a regexp in file-name-handler-alist matches
the "remote" part of a filename (that's not documented this way), it
would be more clean to ask explicitely for it. Maybe a new function:

(defun file-name-remote-part (filename &optional directory)
  "Return FILENAME part describing access to a remote host.
If FILENAME is not absolute, it returns the remote part of DIRECTORY
(default: `default-directory').  Missing defaults in FILENAME are expanded."

Example (with current Tramp syntax):

   (file-name-remote-part "/bar:/a/b/c/foo")
   => "/ssh:address@hidden:"

This would simplify the life.  An equivalent function returning the
local part could be the counterpart.

Best regards, Michael.




reply via email to

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