diff options
| author | Richard M. Stallman | 1993-06-12 01:44:48 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1993-06-12 01:44:48 +0000 |
| commit | c3bf10c278bee183f267d9593a892021b89bc5e2 (patch) | |
| tree | 2629348a267cfcaeb417c6ccda4e1261a979add6 | |
| parent | a135645ac27ba7bc6e143e26852e99ab8708c848 (diff) | |
| download | emacs-c3bf10c278bee183f267d9593a892021b89bc5e2.tar.gz emacs-c3bf10c278bee183f267d9593a892021b89bc5e2.zip | |
(file-truename): Don't use expand-file-name to merge
a link target into the previous dir. Handle .. and . explicitly.
| -rw-r--r-- | lisp/files.el | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/lisp/files.el b/lisp/files.el index c31b75e1ce6..96cc510a61c 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -329,16 +329,25 @@ containing it, until no links are left at any level." | |||
| 329 | ;; If these are equal, we have the (or a) root directory. | 329 | ;; If these are equal, we have the (or a) root directory. |
| 330 | (or (string= dir dirfile) | 330 | (or (string= dir dirfile) |
| 331 | (setq dir (file-name-as-directory (file-truename dirfile)))) | 331 | (setq dir (file-name-as-directory (file-truename dirfile)))) |
| 332 | ;; Put it back on the file name. | 332 | (if (equal ".." (file-name-nondirectory filename)) |
| 333 | (setq filename (concat dir (file-name-nondirectory filename))) | 333 | (directory-file-name (file-name-directory (directory-file-name dir))) |
| 334 | ;; Is the file name the name of a link? | 334 | (if (equal "." (file-name-nondirectory filename)) |
| 335 | (setq target (file-symlink-p filename)) | 335 | (directory-file-name dir) |
| 336 | (if target | 336 | ;; Put it back on the file name. |
| 337 | ;; Yes => chase that link, then start all over | 337 | (setq filename (concat dir (file-name-nondirectory filename))) |
| 338 | ;; since the link may point to a directory name that uses links. | 338 | ;; Is the file name the name of a link? |
| 339 | (file-truename (expand-file-name target dir)) | 339 | (setq target (file-symlink-p filename)) |
| 340 | ;; No, we are done! | 340 | (if target |
| 341 | filename))))) | 341 | ;; Yes => chase that link, then start all over |
| 342 | ;; since the link may point to a directory name that uses links. | ||
| 343 | ;; We can't safely use expand-file-name here | ||
| 344 | ;; since target might look like foo/../bar where foo | ||
| 345 | ;; is itself a link. Instead, we handle . and .. above. | ||
| 346 | (if (file-name-absolute-p target) | ||
| 347 | (file-truename target) | ||
| 348 | (file-truename (concat dir target))) | ||
| 349 | ;; No, we are done! | ||
| 350 | filename))))))) | ||
| 342 | 351 | ||
| 343 | (defun file-chase-links (filename) | 352 | (defun file-chase-links (filename) |
| 344 | "Chase links in FILENAME until a name that is not a link. | 353 | "Chase links in FILENAME until a name that is not a link. |