master ed1fc1b6be1: Simplify implementation of 'make-empty-file'

Philipp Stephani <[email protected]>
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: master
commit ed1fc1b6be1bb7f9365577527d13b8045b232160
Author: Philipp Stephani <[email protected]>
Commit: Philipp Stephani <[email protected]>

    Simplify implementation of 'make-empty-file'
    
    * lisp/files.el (make-empty-file): Remove superfluous existence
    check; 'write-region' with 'excl' already checks for existence
    without TOCTTOU.  Don't check whether the parent directory exists;
    'make-directory' already does the right thing.
---
 lisp/files.el | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index c2f030e0b77..b045ee88c46 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -6757,12 +6757,9 @@ If called interactively, then PARENTS is non-nil."
   (interactive
    (let ((filename (read-file-name "Create empty file: ")))
      (list filename t)))
-  (when (and (file-exists-p filename) (null parents))
-    (signal 'file-already-exists `("File exists" ,filename)))
   (when parents
-    (let ((paren-dir (file-name-directory filename)))
-      (when (and paren-dir (not (file-exists-p paren-dir)))
-        (make-directory paren-dir parents))))
+    (when-let* ((paren-dir (file-name-directory filename)))
+      (make-directory paren-dir :parents)))
   ;; The `excl' is crucial, in case someone else has created the file in
   ;; the meantime (TOCTTOU).
   (write-region "" nil filename nil 0 nil 'excl))
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.