GNU bug report logs -
#59986
30.0.50; Can't trash file with broken symbolic link
Previous Next
Reported by: Jean Louis <bugs <at> gnu.support>
Date: Mon, 12 Dec 2022 06:53:01 UTC
Severity: normal
Found in version 30.0.50
Done: Eli Zaretskii <eliz <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
Message #38 received at 59986 <at> debbugs.gnu.org (full text, mbox):
> Date: Thu, 15 Dec 2022 17:54:32 +0300
> From: Jean Louis <bugs <at> gnu.support>
> Cc: Michael Heerdegen <michael_heerdegen <at> web.de>, bugs <at> gnu.support,
> 59986 <at> debbugs.gnu.org
>
> If there is dangling symlink in Trash then even if the file to be
> deleted to Trash exists and is not symlink, I get the same error
> message:
Can you try the patch below and see if it solves the problem?
diff --git a/lisp/files.el b/lisp/files.el
index d785d4f..c74e7e8 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -8467,6 +8467,14 @@ trash--hexify-table
(declare-function system-move-file-to-trash "w32fns.c" (filename))
+(defun file-exists-in-trash-p (filename)
+ "Return non-nil if FILENAME exists in the trash.
+
+This is like `file-exists-p', but it also returns non-nil
+if FILENAME is a dangling symlink, to allow trashing such files."
+ (or (file-exists-p filename)
+ (file-symlink-p filename)))
+
(defun move-file-to-trash (filename)
"Move the file (or directory) named FILENAME to the trash.
When `delete-by-moving-to-trash' is non-nil, this function is
@@ -8497,7 +8505,7 @@ move-file-to-trash
(unless (file-directory-p trash-dir)
(make-directory trash-dir t))
;; Ensure that the trashed file-name is unique.
- (if (file-exists-p new-fn)
+ (if (file-exists-in-trash-p new-fn)
(let ((version-control t)
(backup-directory-alist nil))
(setq new-fn (car (find-backup-file-name new-fn)))))
@@ -8574,7 +8582,7 @@ move-file-to-trash
;; 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
+ (when (file-exists-in-trash-p
(file-name-concat trash-files-dir files-base))
(setq overwrite t
files-base (file-name-nondirectory
@@ -8612,7 +8620,7 @@ move-file-to-trash
(let ((delete-by-moving-to-trash nil)
(new-fn (file-name-concat trash-files-dir files-base)))
(if (or (not is-directory)
- (not (file-exists-p new-fn)))
+ (not (file-exists-in-trash-p new-fn)))
(rename-file fn new-fn overwrite)
(copy-directory fn
(file-name-as-directory new-fn)
This bug report was last modified 2 years and 215 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.