aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorPaul Eggert2020-03-07 12:04:05 -0800
committerPaul Eggert2020-03-07 12:15:43 -0800
commit5d4cf1fef85bc24bc4cd9705ebb14150263ad707 (patch)
treeaf696ed3ba7d2d0ab31951eba9482443d36c1456 /lisp
parent9f4b260c2b98ea05a02e0ab7213156ce2e60e5a9 (diff)
downloademacs-5d4cf1fef85bc24bc4cd9705ebb14150263ad707.tar.gz
emacs-5d4cf1fef85bc24bc4cd9705ebb14150263ad707.zip
Add ‘nofollow’ flag to set-file-times
This is a companion to the recent set-file-modes patch. It adds support for a ‘nofollow’ flag to set-file-times (Bug#39773). Like the set-file-modes patch, it needs work in the w32 port. * admin/merge-gnulib (GNULIB_MODULES): Add futimens, utimensat. Remove utimens. * doc/lispref/files.texi (Changing Files): * etc/NEWS: Mention the change. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate. * lisp/files.el (copy-directory): * lisp/gnus/gnus-cloud.el (gnus-cloud-replace-file): * lisp/net/tramp-adb.el (tramp-adb-handle-copy-file): * lisp/net/tramp-smb.el (tramp-smb-handle-copy-file): * lisp/tar-mode.el (tar-copy): * test/lisp/filenotify-tests.el (file-notify-test03-events): * test/lisp/files-tests.el: (files-tests-file-name-non-special-set-file-times): * test/lisp/net/tramp-tests.el (tramp-test22-file-times): When setting file times, avoid following symbolic links when the file is not supposed to be a symbolic link. * lib/futimens.c, lib/utimensat.c, m4/futimens.m4, m4/utimensat.m4: New files, copied from Gnulib. * lisp/gnus/gnus-cloud.el (gnus-cloud-replace-file): When creating a file that is not supposed to exist already, use the excl flag to check this. * lisp/net/tramp-adb.el (tramp-adb-handle-set-file-times): * lisp/net/tramp-sh.el (tramp-sh-handle-set-file-times): * lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-set-file-times): Accept an optional FLAG arg that is currently ignored, and add a FIXME comment for it. * lisp/net/tramp-gvfs.el (tramp-gvfs-handle-set-file-times): * src/fileio.c (Fset_file_times): Support an optional FLAG arg. * src/fileio.c (Fcopy_file): Use futimens instead of set_file_times, as it’s simpler and is a POSIX API. * src/sysdep.c (set_file_times): Move from here ... * src/w32.c (set_file_times): ... to here, and make it static, since it is now used only in w32.c. Presumably w32.c should also add support for futimens and utimensat (the POSIX APIs, which Emacs now uses) and it can remove fdutimens (the Gnulib API, which Emacs no longer uses).
Diffstat (limited to 'lisp')
-rw-r--r--lisp/files.el7
-rw-r--r--lisp/gnus/gnus-cloud.el4
-rw-r--r--lisp/net/tramp-adb.el6
-rw-r--r--lisp/net/tramp-gvfs.el4
-rw-r--r--lisp/net/tramp-sh.el3
-rw-r--r--lisp/net/tramp-smb.el3
-rw-r--r--lisp/net/tramp-sudoedit.el3
-rw-r--r--lisp/tar-mode.el2
8 files changed, 19 insertions, 13 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 2e7694d7677..8ce0187f5b7 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -5944,9 +5944,10 @@ into NEWNAME instead."
5944 ;; Set directory attributes. 5944 ;; Set directory attributes.
5945 (let ((modes (file-modes directory)) 5945 (let ((modes (file-modes directory))
5946 (times (and keep-time (file-attribute-modification-time 5946 (times (and keep-time (file-attribute-modification-time
5947 (file-attributes directory))))) 5947 (file-attributes directory))))
5948 (if modes (set-file-modes newname modes (unless follow 'nofollow))) 5948 (follow-flag (unless follow 'nofollow)))
5949 (if times (set-file-times newname times)))))) 5949 (if modes (set-file-modes newname modes follow-flag))
5950 (if times (set-file-times newname times follow-flag))))))
5950 5951
5951 5952
5952;; At time of writing, only info uses this. 5953;; At time of writing, only info uses this.
diff --git a/lisp/gnus/gnus-cloud.el b/lisp/gnus/gnus-cloud.el
index 4d8764bacca..da6231d7330 100644
--- a/lisp/gnus/gnus-cloud.el
+++ b/lisp/gnus/gnus-cloud.el
@@ -285,8 +285,8 @@ Use old data if FORCE-OLDER is not nil."
285 (insert new-contents) 285 (insert new-contents)
286 (when (file-exists-p file-name) 286 (when (file-exists-p file-name)
287 (rename-file file-name (car (find-backup-file-name file-name)))) 287 (rename-file file-name (car (find-backup-file-name file-name))))
288 (write-region (point-min) (point-max) file-name) 288 (write-region (point-min) (point-max) file-name nil nil nil 'excl)
289 (set-file-times file-name (parse-iso8601-time-string date)))) 289 (set-file-times file-name (parse-iso8601-time-string date) 'nofollow)))
290 290
291(defun gnus-cloud-file-covered-p (file-name) 291(defun gnus-cloud-file-covered-p (file-name)
292 (let ((matched nil)) 292 (let ((matched nil))
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index 2c9674fa36f..7ee740f93cb 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -674,8 +674,9 @@ But handle the case, if the \"test\" command is not available."
674 (tramp-adb-send-command-and-check 674 (tramp-adb-send-command-and-check
675 v (format "chmod %o %s" mode localname))))) 675 v (format "chmod %o %s" mode localname)))))
676 676
677(defun tramp-adb-handle-set-file-times (filename &optional time) 677(defun tramp-adb-handle-set-file-times (filename &optional time flag)
678 "Like `set-file-times' for Tramp files." 678 "Like `set-file-times' for Tramp files."
679 flag ;; FIXME: Support 'nofollow'.
679 (with-parsed-tramp-file-name filename nil 680 (with-parsed-tramp-file-name filename nil
680 (tramp-flush-file-properties v localname) 681 (tramp-flush-file-properties v localname)
681 (let ((time (if (or (null time) 682 (let ((time (if (or (null time)
@@ -777,7 +778,8 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
777 (set-file-times 778 (set-file-times
778 newname 779 newname
779 (tramp-compat-file-attribute-modification-time 780 (tramp-compat-file-attribute-modification-time
780 (file-attributes filename)))))) 781 (file-attributes filename))
782 (unless ok-if-already-exists 'nofollow)))))
781 783
782(defun tramp-adb-handle-rename-file 784(defun tramp-adb-handle-rename-file
783 (filename newname &optional ok-if-already-exists) 785 (filename newname &optional ok-if-already-exists)
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el
index 3ce7bbbd4a3..1ad57c59a5b 100644
--- a/lisp/net/tramp-gvfs.el
+++ b/lisp/net/tramp-gvfs.el
@@ -1571,7 +1571,7 @@ If FILE-SYSTEM is non-nil, return file system attributes."
1571 (tramp-gvfs-url-file-name (tramp-make-tramp-file-name v)) 1571 (tramp-gvfs-url-file-name (tramp-make-tramp-file-name v))
1572 "unix::mode" (number-to-string mode)))) 1572 "unix::mode" (number-to-string mode))))
1573 1573
1574(defun tramp-gvfs-handle-set-file-times (filename &optional time) 1574(defun tramp-gvfs-handle-set-file-times (filename &optional time flag)
1575 "Like `set-file-times' for Tramp files." 1575 "Like `set-file-times' for Tramp files."
1576 (with-parsed-tramp-file-name filename nil 1576 (with-parsed-tramp-file-name filename nil
1577 (tramp-flush-file-properties v localname) 1577 (tramp-flush-file-properties v localname)
@@ -1582,7 +1582,7 @@ If FILE-SYSTEM is non-nil, return file system attributes."
1582 (current-time) 1582 (current-time)
1583 time))) 1583 time)))
1584 (tramp-gvfs-send-command 1584 (tramp-gvfs-send-command
1585 v "gvfs-set-attribute" "-t" "uint64" 1585 v "gvfs-set-attribute" (if flag "-nt" "-t") "uint64"
1586 (tramp-gvfs-url-file-name (tramp-make-tramp-file-name v)) 1586 (tramp-gvfs-url-file-name (tramp-make-tramp-file-name v))
1587 "time::modified" (format-time-string "%s" time))))) 1587 "time::modified" (format-time-string "%s" time)))))
1588 1588
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 84b8191bd3d..560941c4d5b 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -1495,11 +1495,12 @@ of."
1495 mode (tramp-shell-quote-argument localname)) 1495 mode (tramp-shell-quote-argument localname))
1496 "Error while changing file's mode %s" filename)))) 1496 "Error while changing file's mode %s" filename))))
1497 1497
1498(defun tramp-sh-handle-set-file-times (filename &optional time) 1498(defun tramp-sh-handle-set-file-times (filename &optional time flag)
1499 "Like `set-file-times' for Tramp files." 1499 "Like `set-file-times' for Tramp files."
1500 (with-parsed-tramp-file-name filename nil 1500 (with-parsed-tramp-file-name filename nil
1501 (when (tramp-get-remote-touch v) 1501 (when (tramp-get-remote-touch v)
1502 (tramp-flush-file-properties v localname) 1502 (tramp-flush-file-properties v localname)
1503 flag ;; FIXME: Support 'nofollow'.
1503 (let ((time 1504 (let ((time
1504 (if (or (null time) 1505 (if (or (null time)
1505 (tramp-compat-time-equal-p time tramp-time-doesnt-exist) 1506 (tramp-compat-time-equal-p time tramp-time-doesnt-exist)
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index 42954cbda3d..d91362c879c 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -619,7 +619,8 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
619 (set-file-times 619 (set-file-times
620 newname 620 newname
621 (tramp-compat-file-attribute-modification-time 621 (tramp-compat-file-attribute-modification-time
622 (file-attributes filename)))))) 622 (file-attributes filename))
623 (unless ok-if-already-exists 'nofollow)))))
623 624
624(defun tramp-smb-handle-delete-directory (directory &optional recursive _trash) 625(defun tramp-smb-handle-delete-directory (directory &optional recursive _trash)
625 "Like `delete-directory' for Tramp files." 626 "Like `delete-directory' for Tramp files."
diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el
index 7d8c8a90618..c054f405e3d 100644
--- a/lisp/net/tramp-sudoedit.el
+++ b/lisp/net/tramp-sudoedit.el
@@ -523,10 +523,11 @@ the result will be a local, non-Tramp, file name."
523 (string-to-number (match-string 2))) 523 (string-to-number (match-string 2)))
524 (string-to-number (match-string 3))))))))) 524 (string-to-number (match-string 3)))))))))
525 525
526(defun tramp-sudoedit-handle-set-file-times (filename &optional time) 526(defun tramp-sudoedit-handle-set-file-times (filename &optional time flag)
527 "Like `set-file-times' for Tramp files." 527 "Like `set-file-times' for Tramp files."
528 (with-parsed-tramp-file-name filename nil 528 (with-parsed-tramp-file-name filename nil
529 (tramp-flush-file-properties v localname) 529 (tramp-flush-file-properties v localname)
530 flag ;; FIXME: Support 'nofollow'.
530 (let ((time 531 (let ((time
531 (if (or (null time) 532 (if (or (null time)
532 (tramp-compat-time-equal-p time tramp-time-doesnt-exist) 533 (tramp-compat-time-equal-p time tramp-time-doesnt-exist)
diff --git a/lisp/tar-mode.el b/lisp/tar-mode.el
index 97d883eebd9..a3c1715b1e1 100644
--- a/lisp/tar-mode.el
+++ b/lisp/tar-mode.el
@@ -1056,7 +1056,7 @@ extracted file."
1056 (write-region start end to-file nil nil nil t)) 1056 (write-region start end to-file nil nil nil t))
1057 (when (and tar-copy-preserve-time 1057 (when (and tar-copy-preserve-time
1058 date) 1058 date)
1059 (set-file-times to-file date))) 1059 (set-file-times to-file date 'nofollow)))
1060 (message "Copied tar entry %s to %s" name to-file))) 1060 (message "Copied tar entry %s to %s" name to-file)))
1061 1061
1062(defun tar-new-entry (filename &optional index) 1062(defun tar-new-entry (filename &optional index)