diff options
| author | Paul Eggert | 2017-08-26 18:36:38 -0700 |
|---|---|---|
| committer | Paul Eggert | 2017-08-26 18:36:38 -0700 |
| commit | e8001d4c27e1e33c83b9994aac4d5fc3feada2da (patch) | |
| tree | 6910256d7cf7723aa1b3f7ab7779b91627ba52f6 /src | |
| parent | 937d9d7f60460edb1d3f978151599fddcbba2214 (diff) | |
| download | emacs-e8001d4c27e1e33c83b9994aac4d5fc3feada2da.tar.gz emacs-e8001d4c27e1e33c83b9994aac4d5fc3feada2da.zip | |
Do not munge contents of local symbolic links
This lets Emacs deal with arbitrary local symlinks without
mishandling their contents (Bug#28156). For example,
(progn (shell-command "ln -fs '~' 'x'") (rename-file "x" "/tmp/x"))
now consistently creates a symbolic link from '/tmp/x' to '~'.
Formerly, it did that only if the working directory was on the
same filesystem as /tmp; otherwise, it expanded the '~' to
the user's home directory.
* lisp/dired.el (dired-get-filename): Use files--name-absolute-system-p
instead of rolling our own code.
* lisp/files.el (files--name-absolute-system-p): New function.
(file-truename, file-chase-links): Use it to avoid mishandling
symlink contents that begin with ~.
(copy-directory, move-file-to-trash):
Use concat rather than expand-file-name, to avoid mishandling
symlink contents that begin with ~.
* src/fileio.c (Fmake_symbolic_link): Do not expand leading "~" in the
target unless interactive. Strip leading "/:" if interactive.
(emacs_readlinkat): Do not prepend "/:" to the link target if
it starts with "/" and contains ":" before NUL.
* test/src/fileio-tests.el (try-link): Rename from try-char,
and accept a string instead of a char. All uses changed.
(fileio-tests--symlink-failure): Also test leading ~, and "/:",
to test the new behavior.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileio.c | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/src/fileio.c b/src/fileio.c index fa694249cb7..bbd1a4ef69c 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -2413,7 +2413,8 @@ DEFUN ("make-symbolic-link", Fmake_symbolic_link, Smake_symbolic_link, 2, 3, | |||
| 2413 | Both args must be strings. | 2413 | Both args must be strings. |
| 2414 | Signal a `file-already-exists' error if a file LINKNAME already exists | 2414 | Signal a `file-already-exists' error if a file LINKNAME already exists |
| 2415 | unless optional third argument OK-IF-ALREADY-EXISTS is non-nil. | 2415 | unless optional third argument OK-IF-ALREADY-EXISTS is non-nil. |
| 2416 | An integer third arg means request confirmation if LINKNAME already exists. | 2416 | An integer third arg means request confirmation if LINKNAME already |
| 2417 | exists, and expand leading "~" or strip leading "/:" in TARGET. | ||
| 2417 | This happens for interactive use with M-x. */) | 2418 | This happens for interactive use with M-x. */) |
| 2418 | (Lisp_Object target, Lisp_Object linkname, Lisp_Object ok_if_already_exists) | 2419 | (Lisp_Object target, Lisp_Object linkname, Lisp_Object ok_if_already_exists) |
| 2419 | { | 2420 | { |
| @@ -2421,21 +2422,15 @@ This happens for interactive use with M-x. */) | |||
| 2421 | Lisp_Object encoded_target, encoded_linkname; | 2422 | Lisp_Object encoded_target, encoded_linkname; |
| 2422 | 2423 | ||
| 2423 | CHECK_STRING (target); | 2424 | CHECK_STRING (target); |
| 2424 | /* If the link target has a ~, we must expand it to get | 2425 | if (INTEGERP (ok_if_already_exists)) |
| 2425 | a truly valid file name. Otherwise, do not expand; | 2426 | { |
| 2426 | we want to permit links to relative file names. */ | 2427 | if (SREF (target, 0) == '~') |
| 2427 | if (SREF (target, 0) == '~') | 2428 | target = Fexpand_file_name (target, Qnil); |
| 2428 | target = Fexpand_file_name (target, Qnil); | 2429 | else if (SREF (target, 0) == '/' && SREF (target, 1) == ':') |
| 2429 | 2430 | target = Fsubstring_no_properties (target, make_number (2), Qnil); | |
| 2431 | } | ||
| 2430 | linkname = expand_cp_target (target, linkname); | 2432 | linkname = expand_cp_target (target, linkname); |
| 2431 | 2433 | ||
| 2432 | /* If the file name has special constructs in it, | ||
| 2433 | call the corresponding file handler. */ | ||
| 2434 | handler = Ffind_file_name_handler (target, Qmake_symbolic_link); | ||
| 2435 | if (!NILP (handler)) | ||
| 2436 | return call4 (handler, Qmake_symbolic_link, target, | ||
| 2437 | linkname, ok_if_already_exists); | ||
| 2438 | |||
| 2439 | /* If the new link name has special constructs in it, | 2434 | /* If the new link name has special constructs in it, |
| 2440 | call the corresponding file handler. */ | 2435 | call the corresponding file handler. */ |
| 2441 | handler = Ffind_file_name_handler (linkname, Qmake_symbolic_link); | 2436 | handler = Ffind_file_name_handler (linkname, Qmake_symbolic_link); |
| @@ -2633,11 +2628,6 @@ emacs_readlinkat (int fd, char const *filename) | |||
| 2633 | return Qnil; | 2628 | return Qnil; |
| 2634 | 2629 | ||
| 2635 | val = build_unibyte_string (buf); | 2630 | val = build_unibyte_string (buf); |
| 2636 | if (buf[0] == '/' && strchr (buf, ':')) | ||
| 2637 | { | ||
| 2638 | AUTO_STRING (slash_colon, "/:"); | ||
| 2639 | val = concat2 (slash_colon, val); | ||
| 2640 | } | ||
| 2641 | if (buf != readlink_buf) | 2631 | if (buf != readlink_buf) |
| 2642 | xfree (buf); | 2632 | xfree (buf); |
| 2643 | val = DECODE_FILE (val); | 2633 | val = DECODE_FILE (val); |