aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2019-09-16 17:43:56 -0700
committerPaul Eggert2019-09-16 18:00:59 -0700
commitbc1c2cf009e30af77523fd87a8910fdbc4284704 (patch)
treee825b2ac67c0beb3b43f50ec100eed4c0d93570b
parentb124cb8f30d575fcda97507c40f16a499640bcd5 (diff)
downloademacs-bc1c2cf009e30af77523fd87a8910fdbc4284704.tar.gz
emacs-bc1c2cf009e30af77523fd87a8910fdbc4284704.zip
Fix some file-mode races
* lisp/emacs-lisp/autoload.el (autoload-ensure-file-writeable): * lisp/files.el (after-find-file): * lisp/gnus/gnus-start.el (gnus-dribble-read-file): * lisp/htmlfontify.el (hfy-copy-and-fontify-file): * lisp/server.el (server-ensure-safe-dir): Avoid a race when getting file permissions.
-rw-r--r--lisp/emacs-lisp/autoload.el3
-rw-r--r--lisp/files.el10
-rw-r--r--lisp/gnus/gnus-start.el5
-rw-r--r--lisp/htmlfontify.el6
-rw-r--r--lisp/server.el6
5 files changed, 14 insertions, 16 deletions
diff --git a/lisp/emacs-lisp/autoload.el b/lisp/emacs-lisp/autoload.el
index a2dbd402c52..ce2827162b9 100644
--- a/lisp/emacs-lisp/autoload.el
+++ b/lisp/emacs-lisp/autoload.el
@@ -398,9 +398,8 @@ FILE's name."
398 ;; Probably pointless, but replaces the old AUTOGEN_VCS in lisp/Makefile, 398 ;; Probably pointless, but replaces the old AUTOGEN_VCS in lisp/Makefile,
399 ;; which was designed to handle CVSREAD=1 and equivalent. 399 ;; which was designed to handle CVSREAD=1 and equivalent.
400 (and autoload-ensure-writable 400 (and autoload-ensure-writable
401 (file-exists-p file)
402 (let ((modes (file-modes file))) 401 (let ((modes (file-modes file)))
403 (if (zerop (logand modes #o0200)) 402 (if (and modes (zerop (logand modes #o0200)))
404 ;; Ignore any errors here, and let subsequent attempts 403 ;; Ignore any errors here, and let subsequent attempts
405 ;; to write the file raise any real error. 404 ;; to write the file raise any real error.
406 (ignore-errors (set-file-modes file (logior modes #o0200)))))) 405 (ignore-errors (set-file-modes file (logior modes #o0200))))))
diff --git a/lisp/files.el b/lisp/files.el
index ce4dd99bd53..5ceaacd744e 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2554,13 +2554,13 @@ unless NOMODES is non-nil."
2554 (auto-save-mode 1))) 2554 (auto-save-mode 1)))
2555 ;; Make people do a little extra work (C-x C-q) 2555 ;; Make people do a little extra work (C-x C-q)
2556 ;; before altering a backup file. 2556 ;; before altering a backup file.
2557 (when (backup-file-name-p buffer-file-name)
2558 (setq buffer-read-only t))
2559 ;; When a file is marked read-only, 2557 ;; When a file is marked read-only,
2560 ;; make the buffer read-only even if root is looking at it. 2558 ;; make the buffer read-only even if root is looking at it.
2561 (when (and (file-modes (buffer-file-name)) 2559 (unless buffer-read-only
2562 (zerop (logand (file-modes (buffer-file-name)) #o222))) 2560 (when (or (backup-file-name-p buffer-file-name)
2563 (setq buffer-read-only t)) 2561 (let ((modes (file-modes (buffer-file-name))))
2562 (and modes (zerop (logand modes #o222)))))
2563 (setq buffer-read-only t)))
2564 (unless nomodes 2564 (unless nomodes
2565 (when (and view-read-only view-mode) 2565 (when (and view-read-only view-mode)
2566 (view-mode -1)) 2566 (view-mode -1))
diff --git a/lisp/gnus/gnus-start.el b/lisp/gnus/gnus-start.el
index e8775c66673..cb369f07b92 100644
--- a/lisp/gnus/gnus-start.el
+++ b/lisp/gnus/gnus-start.el
@@ -897,9 +897,8 @@ If REGEXP is given, lines that match it will be deleted."
897 (set-buffer-modified-p t)) 897 (set-buffer-modified-p t))
898 ;; Set the file modes to reflect the .newsrc file modes. 898 ;; Set the file modes to reflect the .newsrc file modes.
899 (save-buffer) 899 (save-buffer)
900 (when (and (file-exists-p gnus-current-startup-file) 900 (when (and (setq modes (file-modes gnus-current-startup-file))
901 (file-exists-p dribble-file) 901 (file-exists-p dribble-file))
902 (setq modes (file-modes gnus-current-startup-file)))
903 (gnus-set-file-modes dribble-file modes)) 902 (gnus-set-file-modes dribble-file modes))
904 (goto-char (point-min)) 903 (goto-char (point-min))
905 (when (search-forward "Gnus was exited on purpose" nil t) 904 (when (search-forward "Gnus was exited on purpose" nil t)
diff --git a/lisp/htmlfontify.el b/lisp/htmlfontify.el
index b8442be1e89..c1aaab5e211 100644
--- a/lisp/htmlfontify.el
+++ b/lisp/htmlfontify.el
@@ -1938,9 +1938,9 @@ adding an extension of `hfy-extn'. Fontification is actually done by
1938 (set-buffer html) 1938 (set-buffer html)
1939 (write-file (concat target hfy-extn)) 1939 (write-file (concat target hfy-extn))
1940 (kill-buffer html)) 1940 (kill-buffer html))
1941 ;; #o0200 == 128, but emacs20 doesn't know that 1941 (let ((modes (file-modes target)))
1942 (if (and (file-exists-p target) (not (file-writable-p target))) 1942 (if (and modes (not (file-writable-p target)))
1943 (set-file-modes target (logior (file-modes target) 128))) 1943 (set-file-modes target (logior modes #o0200))))
1944 (copy-file (buffer-file-name source) target 'overwrite)) 1944 (copy-file (buffer-file-name source) target 'overwrite))
1945 (kill-buffer source)) )) 1945 (kill-buffer source)) ))
1946 1946
diff --git a/lisp/server.el b/lisp/server.el
index ac81cdbd483..45fa55ad6b0 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -563,9 +563,9 @@ See variable `server-auth-dir' for details."
563 (format "it is not owned by you (owner = %s (%d))" 563 (format "it is not owned by you (owner = %s (%d))"
564 (user-full-name uid) uid)) 564 (user-full-name uid) uid))
565 (w32 nil) ; on NTFS? 565 (w32 nil) ; on NTFS?
566 ((/= 0 (logand ?\077 (file-modes dir))) 566 ((let ((modes (file-modes dir)))
567 (format "it is accessible by others (%03o)" 567 (unless (zerop (logand (or modes 0) #o077))
568 (file-modes dir))) 568 (format "it is accessible by others (%03o)" modes))))
569 (t nil)))) 569 (t nil))))
570 (when unsafe 570 (when unsafe
571 (error "`%s' is not a safe directory because %s" 571 (error "`%s' is not a safe directory because %s"