emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master a5197e2: Fix problem of trashing files to an inconsistent trash d


From: Lars Ingebrigtsen
Subject: master a5197e2: Fix problem of trashing files to an inconsistent trash directory
Date: Thu, 18 Mar 2021 02:36:24 -0400 (EDT)

branch: master
commit a5197e2240d3021ea1f301591227c389a476fd02
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Fix problem of trashing files to an inconsistent trash directory
    
    * lisp/files.el (move-file-to-trash): Allow moving files to trash
    even if there's a file in trash with the same name (but no entry
    in info) (bug#47135).
---
 lisp/files.el | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index 2868be7..60d6034 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -7858,9 +7858,22 @@ Otherwise, trash FILENAME using the freedesktop.org 
conventions,
 
               ;; Make a .trashinfo file.  Use O_EXCL, as per trash-spec 1.0.
               (let* ((files-base (file-name-nondirectory fn))
-                     (info-fn (expand-file-name
+                      (overwrite nil)
+                      info-fn)
+                 ;; We're checking further down whether the info file
+                 ;; exists, but the file name may exist in the trash
+                 ;; directory even if there is no info file for it.
+                 (when (file-exists-p
+                        (expand-file-name files-base trash-files-dir))
+                   (setq overwrite t
+                         files-base (file-name-nondirectory
+                                     (make-temp-file
+                                      (expand-file-name
+                                       files-base trash-files-dir)))))
+                (setq info-fn (expand-file-name
                                (concat files-base ".trashinfo")
-                               trash-info-dir)))
+                               trash-info-dir))
+                 ;; Re-check the existence (sort of).
                 (condition-case nil
                     (write-region nil nil info-fn nil 'quiet info-fn 'excl)
                   (file-already-exists
@@ -7876,7 +7889,7 @@ Otherwise, trash FILENAME using the freedesktop.org 
conventions,
                 ;; Finally, try to move the file to the trashcan.
                 (let ((delete-by-moving-to-trash nil)
                       (new-fn (expand-file-name files-base trash-files-dir)))
-                  (rename-file fn new-fn)))))))))
+                  (rename-file fn new-fn overwrite)))))))))
 
 (defsubst file-attribute-type (attributes)
   "The type field in ATTRIBUTES returned by `file-attributes'.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]