From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mike Kupfer Newsgroups: gmane.emacs.bugs Subject: bug#58721: 28.2; dired with delete-by-moving-to-trash can't trash directory twice Date: Sun, 30 Oct 2022 10:40:24 -0700 Message-ID: <17965.1667151624@alto> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10825"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 58721@debbugs.gnu.org, gusbrs.2016@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 30 18:41:27 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1opCJL-0002hs-Ka for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 30 Oct 2022 18:41:27 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opCJ6-0003O0-7a; Sun, 30 Oct 2022 13:41:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1opCIw-0003Nc-UO for bug-gnu-emacs@gnu.org; Sun, 30 Oct 2022 13:41:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1opCIw-0004ad-N1 for bug-gnu-emacs@gnu.org; Sun, 30 Oct 2022 13:41:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1opCIw-00036M-7w for bug-gnu-emacs@gnu.org; Sun, 30 Oct 2022 13:41:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mike Kupfer Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 30 Oct 2022 17:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58721 X-GNU-PR-Package: emacs Original-Received: via spool by 58721-submit@debbugs.gnu.org id=B58721.166715163411879 (code B ref 58721); Sun, 30 Oct 2022 17:41:02 +0000 Original-Received: (at 58721) by debbugs.gnu.org; 30 Oct 2022 17:40:34 +0000 Original-Received: from localhost ([127.0.0.1]:38989 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opCIT-00035W-M5 for submit@debbugs.gnu.org; Sun, 30 Oct 2022 13:40:33 -0400 Original-Received: from shell1.rawbw.com ([198.144.192.42]:63298 ident=root) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opCIR-00035M-WA for 58721@debbugs.gnu.org; Sun, 30 Oct 2022 13:40:33 -0400 Original-Received: from alto (135-180-174-133.dsl.dynamic.sonic.net [135.180.174.133] (may be forged)) (authenticated bits=0) by shell1.rawbw.com (8.15.1/8.15.1) with ESMTPSA id 29UHeOo9014772 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 30 Oct 2022 10:40:30 -0700 (PDT) (envelope-from mkupfer@alum.berkeley.edu) X-Authentication-Warning: shell1.rawbw.com: Host 135-180-174-133.dsl.dynamic.sonic.net [135.180.174.133] (may be forged) claimed to be alto In-Reply-To: Your message of "Sun, 30 Oct 2022 08:41:00 +0200." <8335b5hkzn.fsf@gnu.org> X-Mailer: MH-E 8.6+git; nmh 1.7.1; Emacs 29.0.50 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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: , Original-Sender: "bug-gnu-emacs" Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:246640 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii wrote: > I just thought you'd be able to call copy-directory, similarly (but > differently) to what rename-file does, instead of using your > lambda-function. Ah, of course. Thanks, yes, that's cleaner. How does the attached patch look? mike --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Fix-cross-filesystem-directory-trashing-Bug-58721.patch Content-Description: proposed patch >From e8fdbeb44dbea9ebf5679c23bf3ad5c5a61141ec Mon Sep 17 00:00:00 2001 From: Mike Kupfer Date: Sun, 30 Oct 2022 10:31:11 -0700 Subject: [PATCH] Fix cross-filesystem directory trashing (Bug#58721) * lisp/files.el (move-file-to-trash): When trashing a directory, copy it into the trash folder and then delete it, rather than using rename-file. --- lisp/files.el | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index 1e1ec6127d..b347815314 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -8565,10 +8565,20 @@ move-file-to-trash (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. + ;; Finally, try to move the item to the trashcan. If + ;; it's a file, just move it. If it's a directory, + ;; rename-file will not work across filesystems, so + ;; copy the directory tree and then delete it. (let ((delete-by-moving-to-trash nil) (new-fn (file-name-concat trash-files-dir files-base))) - (rename-file fn new-fn overwrite))))))))) + (if (not (file-directory-p fn)) + (rename-file fn new-fn overwrite) + (make-directory new-fn) + (copy-directory fn + (file-name-as-directory new-fn) + t nil t) + (delete-directory fn t)))))))))) + (defsubst file-attribute-type (attributes) -- 2.30.2 --=-=-=--