(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);
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