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

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Shingo Tanaka <shingo.fg8@HIDDEN>; Keywords: easy; dated Fri, 25 Oct 2019 14:41:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Added tag(s) easy. Request was from Stefan Kangas <stefan@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 37922 <at> debbugs.gnu.org:


Received: (at 37922) by debbugs.gnu.org; 27 Oct 2019 01:51:14 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Oct 26 21:51:14 2019
Received: from localhost ([127.0.0.1]:41568 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iOXi5-0000Si-W1
	for submit <at> debbugs.gnu.org; Sat, 26 Oct 2019 21:51:14 -0400
Received: from mail-pf1-f179.google.com ([209.85.210.179]:38224)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <shingo.fg8@HIDDEN>) id 1iOXi2-0000SU-SM
 for 37922 <at> debbugs.gnu.org; Sat, 26 Oct 2019 21:51:12 -0400
Received: by mail-pf1-f179.google.com with SMTP id c13so4259630pfp.5
 for <37922 <at> debbugs.gnu.org>; Sat, 26 Oct 2019 18:51:10 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=date:message-id:from:to:subject:in-reply-to:references:user-agent
 :mime-version; bh=1xhi4ZuRroMOADE7T3H1nNMknLGOW62Rf1kEWqS0JDI=;
 b=NuFfetZPFB4JZihzJxDDnJuQmCDKHg5v9DcTMZbXLWlpva1Yv5aa4E1m/xV1GuDRsj
 CUND93skHGFg3fT9UpzpajRCc8VFevxgQMkBqcmdrrX1DnJKmMyvaXmshJpuyV3y5qbM
 K3WfspF8sYaqg0kKV9auQKxZrMceVrfDGomqKpb+lZ4wKFwllULeeI9+7DIwYg+lVz+Y
 kTPPq4f1SPo2/k/HnggvdQJzwh24b8h0rTBZ7u0QFrIEPPKQm7nkaBxA98Fd8FYpvujz
 Oru6F3iouhUQ8CS1H5EWaT7wUKsR308HMb0v8jeyb3R40k5pTsGQm5uMSG9yOyUI5H/l
 J/ag==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:date:message-id:from:to:subject:in-reply-to
 :references:user-agent:mime-version;
 bh=1xhi4ZuRroMOADE7T3H1nNMknLGOW62Rf1kEWqS0JDI=;
 b=aG1APIIwdCeBgLcxlRzhvt/5GaMtKfK8qmaoJqOjpD9qqN3K86qCXgfZStVJTf+i+r
 209RivR7mlJ2Bu3P1T5mwee3mGFONmUvyS1rf756uo30MtpI7n7hp1zjCGbbrDO8ZUK9
 YTSDElJ7WHo78gFpLnMnRzy4s45RkQkACkTlu2k4diQadQVkP+U/aG/0Vi8fIEhrLCuV
 PxG+Avs4Zi8Z5GmD+cW1acumFndF/r1HkYsl9SEM2D5sXGQs8VKNn9xP1bMY3M2+fACA
 hcrYIFc8MSYMy2SQGePSYoc5MkgwY07wnHdrKGfECQ5nHXqWSRS5QkkfP4m275c7EOwM
 80uQ==
X-Gm-Message-State: APjAAAVbmmhOCIRvw4LouZ3jSXzUgG6gt9n8xlLURPJkx5Qi40pVu+1f
 nzYgGjWJgaOjB9v4o5jb0SayeBBw
X-Google-Smtp-Source: APXvYqzihrNdK8tG6jP48H52Tyq3TprbFLbbFSyEgRBlwmyeSa4B9oY2LGfg1F/y/ajbcO1orFQVvg==
X-Received: by 2002:a63:d703:: with SMTP id d3mr13252414pgg.102.1572141064288; 
 Sat, 26 Oct 2019 18:51:04 -0700 (PDT)
Received: from P8E197343H.gmail.com ([240f:36:d353:1:3467:c0b7:d1f7:5162])
 by smtp.gmail.com with ESMTPSA id t11sm6260659pjy.10.2019.10.26.18.51.03
 for <37922 <at> debbugs.gnu.org>
 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
 Sat, 26 Oct 2019 18:51:03 -0700 (PDT)
Date: Sun, 27 Oct 2019 10:51:01 +0900
Message-ID: <87pnijufay.wl-shingo.fg8@HIDDEN>
From: Shingo Tanaka <shingo.fg8@HIDDEN>
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)
In-Reply-To: <handler.37922.B.15720144322418.ack <at> debbugs.gnu.org>
References: <CAH4H2-xqJ5Yd+03oF1-9gSa7mwzEcGLXcwMEUJevBaBnMyMbKA@HIDDEN>
 <handler.37922.B.15720144322418.ack <at> debbugs.gnu.org>
User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue)
 FLIM/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL/10.8 EasyPG/1.0.0 Emacs/26
 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO)
MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue")
Content-Type: text/plain; charset=US-ASCII
X-Spam-Score: 0.3 (/)
X-Debbugs-Envelope-To: 37922
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.7 (/)

# 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




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37922; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 25 Oct 2019 14:40:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Oct 25 10:40:31 2019
Received: from localhost ([127.0.0.1]:39204 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iO0lT-0000cq-Fu
	for submit <at> debbugs.gnu.org; Fri, 25 Oct 2019 10:40:31 -0400
Received: from lists.gnu.org ([209.51.188.17]:53859)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <shingo.fg8@HIDDEN>) id 1iO081-0007y2-0w
 for submit <at> debbugs.gnu.org; Fri, 25 Oct 2019 09:59:45 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:40199)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <shingo.fg8@HIDDEN>) id 1iO07z-00067s-6C
 for bug-gnu-emacs@HIDDEN; Fri, 25 Oct 2019 09:59:44 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: *
X-Spam-Status: No, score=1.1 required=5.0 tests=BAYES_50,
 FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,URIBL_BLOCKED
 autolearn=disabled version=3.3.2
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <shingo.fg8@HIDDEN>) id 1iO07x-0005tr-Rt
 for bug-gnu-emacs@HIDDEN; Fri, 25 Oct 2019 09:59:43 -0400
Received: from mail-qk1-x732.google.com ([2607:f8b0:4864:20::732]:36605)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
 (Exim 4.71) (envelope-from <shingo.fg8@HIDDEN>)
 id 1iO07x-0005tT-Ne
 for bug-gnu-emacs@HIDDEN; Fri, 25 Oct 2019 09:59:41 -0400
Received: by mail-qk1-x732.google.com with SMTP id y189so1834911qkc.3
 for <bug-gnu-emacs@HIDDEN>; Fri, 25 Oct 2019 06:59:41 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:from:date:message-id:subject:to;
 bh=nSrTLsmyemxYytFCeWxzQJx1jBfm87sIKW+WwFyjSnk=;
 b=NEPU0IlWpQDtyEDi6oy+OocrsL/ZT+3YLrueetvftJxVFrykypUr20U/FCLqpmgwZe
 YXhrp3K+RIVsVj6QySztQYbWnEuEdvAmkNXLIeo1SPimPrB1uBzP5+MZjFS1ihv0xoRf
 HAg2GdZn8fEOHVmeSHwabdWP62kNXyDk5wjfP+Ap191W5QkmeQDNZMLQlHxcCRgxRLm7
 UqRKC3BnnXsSnzGTLf++BFnIknmJuxFTzt/fZKhLGjliLg+wcDSRf1dfmYitl9yEoAjW
 nPtbx5PoDIRzPArqsLbQtG/LbJDqeAhMlxpwBnM/JEy+fJsdfbq6gGuUepGAcgn/6riP
 3/Fw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
 bh=nSrTLsmyemxYytFCeWxzQJx1jBfm87sIKW+WwFyjSnk=;
 b=NOEJtY9lxSvpxzIeCNKzi4sf6wz1XFXDpN543eWr6B/Isv0Z371WW5Op2kkKyU5Cn6
 za9rq9PaWF3t3qpYXE+cTcoZQMF0ewNC9lyYKjChSPV3v3AUFe7NkySRccyxwj7As9IS
 DHqyu0Y+GWzLXpSWwdOENiQzme9oS7BIjOwweJlkX6+uWp0jXj/9rK0r83b2jUY9icIB
 RU/+I9SkiRVVOuCCklqkSTgmtRYdO1SK7b0ul7SpbK5eS1to4Rnaw/fXpczBmnptaL5t
 qvrtpwuK3haFVutLDLNnZSEKIwUtf73S2xZTF0Yg91N1WLWIti2gPMVYfkHV9OQ5KWyG
 yntA==
X-Gm-Message-State: APjAAAU/RJ2Ak71mmptPEM/dhO1vq6Lfqw7BjTNZs1/BMvmj3GKjGRPT
 avpyLDsXGPnsmIgLGk0h2P3mjeAd0i3FsEYbJjUwB88y
X-Google-Smtp-Source: APXvYqw8U0je1/tQhP58zBWF8Lay7MoeZ2bDmQOErtU0p1ptN1/4bPYl5uqU/zsYJUFmHPJpG7M6sftZinV84arUVuo=
X-Received: by 2002:a37:4e82:: with SMTP id c124mr3085955qkb.228.1572011980518; 
 Fri, 25 Oct 2019 06:59:40 -0700 (PDT)
MIME-Version: 1.0
From: Shingo Tanaka <shingo.fg8@HIDDEN>
Date: Fri, 25 Oct 2019 22:59:28 +0900
Message-ID: <CAH4H2-xqJ5Yd+03oF1-9gSa7mwzEcGLXcwMEUJevBaBnMyMbKA@HIDDEN>
Subject: 26.3; move-file-to-trash puts wrong trash file name at name collision
To: bug-gnu-emacs@HIDDEN
Content-Type: multipart/alternative; boundary="000000000000ae78d50595bc8f90"
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
 recognized.
X-Received-From: 2607:f8b0:4864:20::732
X-Spam-Score: 0.9 (/)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Fri, 25 Oct 2019 10:40:30 -0400
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.1 (--)

--000000000000ae78d50595bc8f90
Content-Type: text/plain; charset="UTF-8"

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

--000000000000ae78d50595bc8f90
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hi,</div><div><br></div>When delete-by-moving-to-tras=
h is t and system-move-file-to-trash is not defined, move-file-to-trash mov=
es the deleted file to system trash can following <a href=3D"http://freedes=
ktop.org">freedesktop.org</a> trash can specification.<br><br>In this condi=
tion, when a file is deleted and it has the same name as the one of an alre=
ady deleted file in trash can, move-file-to-trash generates another file na=
me by using make-temp-file to avoid the name collision.=C2=A0 Unfortunately=
, it does put a wrong name with suffix &quot;.trashinfo&quot;.<br><br>For e=
xample, when 2 &quot;hoge.txt&quot; are deleted, expected files are like:<b=
r><br>/home/myusername/.local/share/Trash/files:<br>-rw-rw-rw- 1 myusername=
 =C2=A010 2019-10-25 20:00 hoge.txt<br>-rw-rw-rw- 1 myusername =C2=A010 201=
9-10-25 20:00 hoge.txtwmWP0h<br><br>/home/myusername/.local/share/Trash/inf=
o:<br>-rw-rw-rw- 1 myusername =C2=A075 2019-10-25 20:00 hoge.txt.trashinfo<=
br>-rw------- 1 myusername =C2=A075 2019-10-25 20:00 hoge.txtwmWP0h.trashin=
fo<br><br>However, the reality is the 2nd trash file in files directory is =
named wrongly with &quot;.trashinfo&quot; suffix like:<br><br>/home/myusern=
ame/.local/share/Trash/files:<br>-rw-rw-rw- 1 myusername =C2=A010 2019-10-2=
5 20:00 hoge.txt<br>-rw-rw-rw- 1 myusername =C2=A010 2019-10-25 20:00 hoge.=
txtwmWP0h.trashinfo<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 ^^^^^^^^^<br>/home/myusername/.local/share/Trash/info:<br>-rw-rw=
-rw- 1 myusername =C2=A075 2019-10-25 20:00 hoge.txt.trashinfo<br>-rw------=
- 1 myusername =C2=A075 2019-10-25 20:00 hoge.txtwmWP0h.trashinfo<br><br>He=
re is a potential patch.<br><br>--- files.el.original	2019-09-17 05:14:45.0=
00000000 +0900<br>+++ files.el	2019-10-25 20:52:13.899138800 +0900<br>@@ -7=
408,7 +7408,8 @@<br>=C2=A0		 =C2=A0 =C2=A0(setq info-fn (make-temp-file<br>=
=C2=A0				 =C2=A0 (expand-file-name files-base trash-info-dir)<br>=C2=A0			=
	 =C2=A0 nil &quot;.trashinfo&quot;))<br>-		 =C2=A0 =C2=A0(setq files-base =
(file-name-nondirectory info-fn))<br>+		 =C2=A0 =C2=A0(setq files-base (sub=
string (file-name-nondirectory info-fn)<br>+						0 (- (length &quot;.trash=
info&quot;))))<br>=C2=A0		 =C2=A0 =C2=A0(write-region nil nil info-fn nil &=
#39;quiet info-fn)))<br>=C2=A0		 ;; Finally, try to move the file to the tr=
ashcan.<br>=C2=A0		 (let ((delete-by-moving-to-trash nil)<br><br>---<br>Shi=
ngo Tanaka<br></div>

--000000000000ae78d50595bc8f90--




Acknowledgement sent to Shingo Tanaka <shingo.fg8@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#37922; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Fri, 8 Nov 2019 01:15:02 UTC

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