From: Lars Ingebrigtsen Date: Thu, 18 Mar 2021 06:36:15 +0000 (+0100) Subject: Fix problem of trashing files to an inconsistent trash directory X-Git-Tag: emacs-28.0.90~3241 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a5197e2240d3021ea1f301591227c389a476fd02;p=emacs.git 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). --- diff --git a/lisp/files.el b/lisp/files.el index 2868be77f28..60d60340114 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'.