unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#37922: 26.3; move-file-to-trash puts wrong trash file name at name collision
@ 2019-10-25 13:59 Shingo Tanaka
       [not found] ` <handler.37922.B.15720144322418.ack@debbugs.gnu.org>
  2019-11-16 12:56 ` bug#37922: 26.3; move-file-to-trash puts wrong trash file name at name collision Eli Zaretskii
  0 siblings, 2 replies; 3+ messages in thread
From: Shingo Tanaka @ 2019-10-25 13:59 UTC (permalink / raw)
  To: 37922

[-- Attachment #1: Type: text/plain, Size: 2003 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 2345 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#37922: Acknowledgement (26.3; move-file-to-trash puts wrong trash file name at name collision)
       [not found] ` <handler.37922.B.15720144322418.ack@debbugs.gnu.org>
@ 2019-10-27  1:51   ` Shingo Tanaka
  0 siblings, 0 replies; 3+ messages in thread
From: Shingo Tanaka @ 2019-10-27  1:51 UTC (permalink / raw)
  To: 37922

# 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





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#37922: 26.3; move-file-to-trash puts wrong trash file name at name collision
  2019-10-25 13:59 bug#37922: 26.3; move-file-to-trash puts wrong trash file name at name collision Shingo Tanaka
       [not found] ` <handler.37922.B.15720144322418.ack@debbugs.gnu.org>
@ 2019-11-16 12:56 ` Eli Zaretskii
  1 sibling, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2019-11-16 12:56 UTC (permalink / raw)
  To: Shingo Tanaka; +Cc: 37922-done

> From: Shingo Tanaka <shingo.fg8@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.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-16 12:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-25 13:59 bug#37922: 26.3; move-file-to-trash puts wrong trash file name at name collision Shingo Tanaka
     [not found] ` <handler.37922.B.15720144322418.ack@debbugs.gnu.org>
2019-10-27  1:51   ` bug#37922: Acknowledgement (26.3; move-file-to-trash puts wrong trash file name at name collision) Shingo Tanaka
2019-11-16 12:56 ` bug#37922: 26.3; move-file-to-trash puts wrong trash file name at name collision Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).