1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

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.
This commit is contained in:
Lars Ingebrigtsen 2021-07-24 13:34:52 +02:00
parent 5431a58e86
commit 86a795f6dd

View file

@ -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)