summaryrefslogtreecommitdiff
path: root/src/fileio.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-10-12 13:44:56 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2017-10-12 13:44:56 -0700
commitd0f910cbf862db2a89d56e6414c93a93e46e202b (patch)
tree0504513f33cdb0a31e5b04ecd60c374a5d096dda /src/fileio.c
parenta346d5bd25acee99bb94f9b785507d4e4ccb554b (diff)
parent59b5dc60d660f81f8b781068d13727ed812ad555 (diff)
downloademacs-d0f910cbf862db2a89d56e6414c93a93e46e202b.tar.gz
Merge from origin/emacs-26
59b5dc60d6 Fix this-command-keys for "M-x foo" commands 2f4bd2fbda Let rename-file rename dirs across filesystems 413978727c Simplify Flymake user documentation 6ff18c3995 * etc/NEWS: Mention the new version of Org. b78332c3c6 Don't use (format "%s" ...) for string copying (Bug#28774) 078fb7f6df Make frame-list-z-order on NS match Windows behaviour (bug... # Conflicts: # etc/NEWS
Diffstat (limited to 'src/fileio.c')
-rw-r--r--src/fileio.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/fileio.c b/src/fileio.c
index d8ecccd7930..ca21b0a115a 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2261,7 +2261,7 @@ This is what happens in interactive use with M-x. */)
(Lisp_Object file, Lisp_Object newname, Lisp_Object ok_if_already_exists)
{
Lisp_Object handler;
- Lisp_Object encoded_file, encoded_newname, symlink_target;
+ Lisp_Object encoded_file, encoded_newname;
file = Fexpand_file_name (file, Qnil);
@@ -2335,12 +2335,22 @@ This is what happens in interactive use with M-x. */)
if (rename_errno != EXDEV)
report_file_errno ("Renaming", list2 (file, newname), rename_errno);
+ struct stat file_st;
bool dirp = !NILP (Fdirectory_name_p (file));
+ if (!dirp)
+ {
+ if (lstat (SSDATA (encoded_file), &file_st) != 0)
+ report_file_error ("Renaming", list2 (file, newname));
+ dirp = S_ISDIR (file_st.st_mode) != 0;
+ }
if (dirp)
call4 (Qcopy_directory, file, newname, Qt, Qnil);
else
{
- symlink_target = Ffile_symlink_p (file);
+ Lisp_Object symlink_target
+ = (S_ISLNK (file_st.st_mode)
+ ? emacs_readlinkat (AT_FDCWD, SSDATA (encoded_file))
+ : Qnil);
if (!NILP (symlink_target))
Fmake_symbolic_link (symlink_target, newname, ok_if_already_exists);
else