GNU bug report logs - #37922
26.3; move-file-to-trash puts wrong trash file name at name collision

Previous Next

Package: emacs;

Reported by: Shingo Tanaka <shingo.fg8 <at> gmail.com>

Date: Fri, 25 Oct 2019 14:41:02 UTC

Severity: normal

Tags: easy

Found in version 26.3

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 37922 in the body.
You can then email your comments to 37922 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#37922; Package emacs. (Fri, 25 Oct 2019 14:41:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Shingo Tanaka <shingo.fg8 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 25 Oct 2019 14:41:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Shingo Tanaka <shingo.fg8 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.3; move-file-to-trash puts wrong trash file name at name collision
Date: Fri, 25 Oct 2019 22:59:28 +0900
[Message part 1 (text/plain, inline)]
Hi,

When delete-by-moving-to-trash is t and system-move-file-to-trash is not
defined, move-file-to-trash moves the deleted file to system trash can
following freedesktop.org trash can specification.

In this condition, when a file is deleted and it has the same name as the
one of an already deleted file in trash can, move-file-to-trash generates
another file name by using make-temp-file to avoid the name collision.
Unfortunately, it does put a wrong name with suffix ".trashinfo".

For example, when 2 "hoge.txt" are deleted, expected files are like:

/home/myusername/.local/share/Trash/files:
-rw-rw-rw- 1 myusername  10 2019-10-25 20:00 hoge.txt
-rw-rw-rw- 1 myusername  10 2019-10-25 20:00 hoge.txtwmWP0h

/home/myusername/.local/share/Trash/info:
-rw-rw-rw- 1 myusername  75 2019-10-25 20:00 hoge.txt.trashinfo
-rw------- 1 myusername  75 2019-10-25 20:00 hoge.txtwmWP0h.trashinfo

However, the reality is the 2nd trash file in files directory is named
wrongly with ".trashinfo" suffix like:

/home/myusername/.local/share/Trash/files:
-rw-rw-rw- 1 myusername  10 2019-10-25 20:00 hoge.txt
-rw-rw-rw- 1 myusername  10 2019-10-25 20:00 hoge.txtwmWP0h.trashinfo
                                                            ^^^^^^^^^
/home/myusername/.local/share/Trash/info:
-rw-rw-rw- 1 myusername  75 2019-10-25 20:00 hoge.txt.trashinfo
-rw------- 1 myusername  75 2019-10-25 20:00 hoge.txtwmWP0h.trashinfo

Here is a potential patch.

--- files.el.original 2019-09-17 05:14:45.000000000 +0900
+++ files.el 2019-10-25 20:52:13.899138800 +0900
@@ -7408,7 +7408,8 @@
     (setq info-fn (make-temp-file
    (expand-file-name files-base trash-info-dir)
    nil ".trashinfo"))
-    (setq files-base (file-name-nondirectory info-fn))
+    (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)

---
Shingo Tanaka
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#37922; Package emacs. (Sun, 27 Oct 2019 01:52:02 GMT) Full text and rfc822 format available.

Message #8 received at 37922 <at> debbugs.gnu.org (full text, mbox):

From: Shingo Tanaka <shingo.fg8 <at> gmail.com>
To: 37922 <at> debbugs.gnu.org
Subject: Re: bug#37922: Acknowledgement (26.3;
 move-file-to-trash puts wrong trash file name at name collision)
Date: Sun, 27 Oct 2019 10:51:01 +0900
# Resending it as I sent the original mail in HTML format by mistake...

Hi,

When delete-by-moving-to-trash is t and system-move-file-to-trash is not defined, move-file-to-trash moves the deleted file to system trash can following freedesktop.org trash can specification.

In this condition, when a file is deleted and it has the same name as the one of an already deleted file in trash can, move-file-to-trash generates another file name by using make-temp-file to avoid the name collision.  Unfortunatelly, it does the naming in a wrong way.

For example, when 2 "hoge.txt" are deleted, expected files are like:

/home/myusername/.local/share/Trash/files:
-rw-rw-rw- 1 myusername  10 2019-10-25 20:00 hoge.txt
-rw-rw-rw- 1 myusername  10 2019-10-25 20:00 hoge.txtwmWP0h

/home/myusername/.local/share/Trash/info:
-rw-rw-rw- 1 myusername  75 2019-10-25 20:00 hoge.txt.trashinfo
-rw------- 1 myusername  75 2019-10-25 20:00 hoge.txtwmWP0h.trashinfo

However, the reality is the 2nd trash file in files directory is named wrongly with ".trashinfo" suffix like:

/home/myusername/.local/share/Trash/files:
-rw-rw-rw- 1 myusername  10 2019-10-25 20:00 hoge.txt
-rw-rw-rw- 1 myusername  10 2019-10-25 20:00 hoge.txtwmWP0h.trashinfo
                                                            ^^^^^^^^^
/home/myusername/.local/share/Trash/info:
-rw-rw-rw- 1 myusername  75 2019-10-25 20:00 hoge.txt.trashinfo
-rw------- 1 myusername  75 2019-10-25 20:00 hoge.txtwmWP0h.trashinfo

Here is a potential patch.

--- files.el.original	2019-09-17 05:14:45.000000000 +0900
+++ files.el	2019-10-25 20:52:13.899138800 +0900
@@ -7408,7 +7408,8 @@
 		    (setq info-fn (make-temp-file
 				   (expand-file-name files-base trash-info-dir)
 				   nil ".trashinfo"))
-		    (setq files-base (file-name-nondirectory info-fn))
+		    (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)

---
Shingo Tanaka




Added tag(s) easy. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Fri, 08 Nov 2019 01:03:02 GMT) Full text and rfc822 format available.

Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Sat, 16 Nov 2019 12:57:01 GMT) Full text and rfc822 format available.

Notification sent to Shingo Tanaka <shingo.fg8 <at> gmail.com>:
bug acknowledged by developer. (Sat, 16 Nov 2019 12:57:02 GMT) Full text and rfc822 format available.

Message #15 received at 37922-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Shingo Tanaka <shingo.fg8 <at> gmail.com>
Cc: 37922-done <at> debbugs.gnu.org
Subject: Re: bug#37922: 26.3;
 move-file-to-trash puts wrong trash file name at name collision
Date: Sat, 16 Nov 2019 14:56:37 +0200
> From: Shingo Tanaka <shingo.fg8 <at> gmail.com>
> Date: Fri, 25 Oct 2019 22:59:28 +0900
> 
> When delete-by-moving-to-trash is t and system-move-file-to-trash is not
> defined, move-file-to-trash moves the deleted file to system trash can
> following freedesktop.org trash can specification.
> 
> In this condition, when a file is deleted and it has the same name as the
> one of an already deleted file in trash can, move-file-to-trash generates
> another file name by using make-temp-file to avoid the name collision.
> Unfortunately, it does put a wrong name with suffix ".trashinfo".
> 
> For example, when 2 "hoge.txt" are deleted, expected files are like:
> 
> /home/myusername/.local/share/Trash/files:
> -rw-rw-rw- 1 myusername  10 2019-10-25 20:00 hoge.txt
> -rw-rw-rw- 1 myusername  10 2019-10-25 20:00 hoge.txtwmWP0h
> 
> /home/myusername/.local/share/Trash/info:
> -rw-rw-rw- 1 myusername  75 2019-10-25 20:00 hoge.txt.trashinfo
> -rw------- 1 myusername  75 2019-10-25 20:00 hoge.txtwmWP0h.trashinfo
> 
> However, the reality is the 2nd trash file in files directory is named
> wrongly with ".trashinfo" suffix like:
> 
> /home/myusername/.local/share/Trash/files:
> -rw-rw-rw- 1 myusername  10 2019-10-25 20:00 hoge.txt
> -rw-rw-rw- 1 myusername  10 2019-10-25 20:00 hoge.txtwmWP0h.trashinfo
>                                                             ^^^^^^^^^
> /home/myusername/.local/share/Trash/info:
> -rw-rw-rw- 1 myusername  75 2019-10-25 20:00 hoge.txt.trashinfo
> -rw------- 1 myusername  75 2019-10-25 20:00 hoge.txtwmWP0h.trashinfo
> 
> Here is a potential patch.

Thanks, I installed this.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 15 Dec 2019 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 246 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.