From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Shingo Tanaka Newsgroups: gmane.emacs.bugs Subject: bug#37922: 26.3; move-file-to-trash puts wrong trash file name at name collision Date: Fri, 25 Oct 2019 22:59:28 +0900 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000ae78d50595bc8f90" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="25807"; mail-complaints-to="usenet@blaine.gmane.org" To: 37922@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Oct 25 16:55:41 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iO108-0006Vc-Kn for geb-bug-gnu-emacs@m.gmane.org; Fri, 25 Oct 2019 16:55:40 +0200 Original-Received: from localhost ([::1]:33270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iO106-0001GX-RZ for geb-bug-gnu-emacs@m.gmane.org; Fri, 25 Oct 2019 10:55:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47938) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iO0m2-0003nI-7n for bug-gnu-emacs@gnu.org; Fri, 25 Oct 2019 10:41:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iO0m0-0002HV-8z for bug-gnu-emacs@gnu.org; Fri, 25 Oct 2019 10:41:06 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:58618) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iO0ly-0002Gv-RE for bug-gnu-emacs@gnu.org; Fri, 25 Oct 2019 10:41:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iO0ly-0000eB-Oi for bug-gnu-emacs@gnu.org; Fri, 25 Oct 2019 10:41:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Shingo Tanaka Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 25 Oct 2019 14:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 37922 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.15720144322418 (code B ref -1); Fri, 25 Oct 2019 14:41:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 25 Oct 2019 14:40:32 +0000 Original-Received: from localhost ([127.0.0.1]:39204 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iO0lT-0000cq-Fu for submit@debbugs.gnu.org; Fri, 25 Oct 2019 10:40:31 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:53859) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iO081-0007y2-0w for submit@debbugs.gnu.org; Fri, 25 Oct 2019 09:59:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40199) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iO07z-00067s-6C for bug-gnu-emacs@gnu.org; Fri, 25 Oct 2019 09:59:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iO07x-0005tr-Rt for bug-gnu-emacs@gnu.org; Fri, 25 Oct 2019 09:59:43 -0400 Original-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 ) id 1iO07x-0005tT-Ne for bug-gnu-emacs@gnu.org; Fri, 25 Oct 2019 09:59:41 -0400 Original-Received: by mail-qk1-x732.google.com with SMTP id y189so1834911qkc.3 for ; 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) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Mailman-Approved-At: Fri, 25 Oct 2019 10:40:30 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:170162 Archived-At: --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
Hi,

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 freedesktop.org trash can specification.

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 ".trashinfo".

For e= xample, when 2 "hoge.txt" are deleted, expected files are like:
/home/myusername/.local/share/Trash/files:
-rw-rw-rw- 1 myusername= =C2=A010 2019-10-25 20:00 hoge.txt
-rw-rw-rw- 1 myusername =C2=A010 201= 9-10-25 20:00 hoge.txtwmWP0h

/home/myusername/.local/share/Trash/inf= o:
-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

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

/home/myusern= ame/.local/share/Trash/files:
-rw-rw-rw- 1 myusername =C2=A010 2019-10-2= 5 20:00 hoge.txt
-rw-rw-rw- 1 myusername =C2=A010 2019-10-25 20:00 hoge.= txtwmWP0h.trashinfo
=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 ^^^^^^^^^
/home/myusername/.local/share/Trash/info:
-rw-rw= -rw- 1 myusername =C2=A075 2019-10-25 20:00 hoge.txt.trashinfo
-rw------= - 1 myusername =C2=A075 2019-10-25 20:00 hoge.txtwmWP0h.trashinfo

He= re is a potential patch.

--- files.el.original 2019-09-17 05:14:45.0= 00000000 +0900
+++ files.el 2019-10-25 20:52:13.899138800 +0900
@@ -7= 408,7 +7408,8 @@
=C2=A0 =C2=A0 =C2=A0(setq info-fn (make-temp-file
= =C2=A0 =C2=A0 (expand-file-name files-base trash-info-dir)
=C2=A0 = =C2=A0 nil ".trashinfo"))
- =C2=A0 =C2=A0(setq files-base = (file-name-nondirectory info-fn))
+ =C2=A0 =C2=A0(setq files-base (sub= string (file-name-nondirectory info-fn)
+ 0 (- (length ".trash= info"))))
=C2=A0 =C2=A0 =C2=A0(write-region nil nil info-fn nil &= #39;quiet info-fn)))
=C2=A0 ;; Finally, try to move the file to the tr= ashcan.
=C2=A0 (let ((delete-by-moving-to-trash nil)

---
Shi= ngo Tanaka
--000000000000ae78d50595bc8f90--