From: Lars Ingebrigtsen Date: Sat, 24 Jul 2021 11:34:52 +0000 (+0200) Subject: Fix problem when moving files called ~ to the trash X-Git-Tag: emacs-28.0.90~1725 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=86a795f6dd6c690d83eddd753a4972c555a1ac5f;p=emacs.git Fix problem when moving files called ~ to the trash * lisp/files.el (move-file-to-trash): Construct the trash file name safely (bug#49711). This makes (move-file-to-trash "/tmp/~") etc work. --- diff --git a/lisp/files.el b/lisp/files.el index aab839eab10..78b76592bd0 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -8127,16 +8127,16 @@ Otherwise, trash FILENAME using the freedesktop.org conventions, ;; 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)) + (directory-append trash-files-dir files-base)) (setq overwrite t files-base (file-name-nondirectory (make-temp-file - (expand-file-name - files-base trash-files-dir) + (directory-append + trash-files-dir files-base) is-directory)))) - (setq info-fn (expand-file-name - (concat files-base ".trashinfo") - trash-info-dir)) + (setq info-fn (directory-append + trash-info-dir + (concat files-base ".trashinfo"))) ;; Re-check the existence (sort of). (condition-case nil (write-region nil nil info-fn nil 'quiet info-fn 'excl) @@ -8145,14 +8145,14 @@ Otherwise, trash FILENAME using the freedesktop.org conventions, ;; like Emacs-style backup file names. E.g.: ;; https://bugs.kde.org/170956 (setq info-fn (make-temp-file - (expand-file-name files-base trash-info-dir) + (directory-append trash-info-dir files-base) nil ".trashinfo")) (setq files-base (substring (file-name-nondirectory info-fn) 0 (- (length ".trashinfo")))) (write-region nil nil info-fn nil 'quiet info-fn))) ;; 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))) + (new-fn (directory-append trash-files-dir files-base))) (rename-file fn new-fn overwrite))))))))) (defsubst file-attribute-type (attributes)