From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David De La Harpe Golden Newsgroups: gmane.emacs.bugs Subject: bug#964: trash - runaway recursion for cross-device delete-file ops Date: Fri, 12 Sep 2008 03:07:31 +0100 Message-ID: <48C9CEE3.90006@harpegolden.net> Reply-To: David De La Harpe Golden , 964@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040105050802060801010406" X-Trace: ger.gmane.org 1221186472 14378 80.91.229.12 (12 Sep 2008 02:27:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 12 Sep 2008 02:27:52 +0000 (UTC) To: submit@emacsbugs.donarmstrong.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Sep 12 04:28:47 2008 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KdyOs-0003a4-9A for geb-bug-gnu-emacs@m.gmane.org; Fri, 12 Sep 2008 04:28:46 +0200 Original-Received: from localhost ([127.0.0.1]:51477 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KdyNr-0004PT-Nn for geb-bug-gnu-emacs@m.gmane.org; Thu, 11 Sep 2008 22:27:43 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KdyNo-0004OQ-7N for bug-gnu-emacs@gnu.org; Thu, 11 Sep 2008 22:27:40 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KdyNm-0004O6-Ld for bug-gnu-emacs@gnu.org; Thu, 11 Sep 2008 22:27:39 -0400 Original-Received: from [199.232.76.173] (port=54362 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KdyNm-0004O0-Ck for bug-gnu-emacs@gnu.org; Thu, 11 Sep 2008 22:27:38 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:47429) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KdyNl-0004eh-D1 for bug-gnu-emacs@gnu.org; Thu, 11 Sep 2008 22:27:38 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m8C2RXTx000695; Thu, 11 Sep 2008 19:27:33 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id m8C2F4S8028447; Thu, 11 Sep 2008 19:15:04 -0700 X-Loop: don@donarmstrong.com Resent-From: David De La Harpe Golden Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Fri, 12 Sep 2008 02:15:03 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 964 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Original-Received: via spool by submit@emacsbugs.donarmstrong.com id=B.122118526926249 (code B ref -1); Fri, 12 Sep 2008 02:15:03 +0000 Original-Received: (at submit) by emacsbugs.donarmstrong.com; 12 Sep 2008 02:07:49 +0000 Original-Received: from harpegolden.net (harpegolden.net [65.99.215.13]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m8C27j7Z026243 for ; Thu, 11 Sep 2008 19:07:46 -0700 Original-Received: from golden1.harpegolden.net (unknown [86.45.15.116]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "David De La Harpe Golden", Issuer "David De La Harpe Golden Personal CA rev 3" (verified OK)) by harpegolden.net (Postfix) with ESMTP id 310CF81AD for ; Fri, 12 Sep 2008 03:07:44 +0100 (IST) User-Agent: Mozilla-Thunderbird 2.0.0.16 (X11/20080724) X-Enigmail-Version: 0.95.0 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Resent-Date: Thu, 11 Sep 2008 22:27:39 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list 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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:20496 Archived-At: This is a multi-part message in MIME format. --------------040105050802060801010406 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Package: emacs Version: 23.0.60 Severity: normal Tags: patch Steps to reproduce: Turn on delete-by-moving-to-trash on gnu+linux. Make a file on a different filesystem to your home dir. Try to delete-file the file in emacs once. Look inside ~/.Trash, full of hundreds of redundant copies of the file. Reason: When delete-by-moving-to-trash is on, delete-file calls move-file-to-trash. move-file-to-trash, when using its fallback emacs trashcan implementation* (i.e. when there's no system-move-file-to-trash) picks a name for the trashed file, and calls rename-file. rename-file tries a C rename(), but that doesn't work cross-device on gnu+linux (and several other OSes), so rename-file falls back to copying the file to the new name, and then calls delete-file to get rid of the old one (~line 2247 of fileio.c) move-file-to-trash decides the existing filename under .Trash is taken, seeing as a file exists with that name, picks a new name, and calls rename-file again... ... Lather, rinse, repeat, until emacs gets bored with a "Variable binding depth exceeds max-specpdl-size" Fix?: (i) Well, binding delete-by-moving-to-trash to nil around the rename-file in move-file-to-trash might be adequate, fixes immediate issue? trivial patch attached. Though another strikes me: (ii) As it stands, won't an actual rename-file will sometimes move a copy of "renamed" files to trash (i.e. when they're on a different device) if delete-by-moving-to-trash is on? Not sure that's very nice - maybe should bind delete-by-moving-to-trash to nil around its call to delete-file, or maybe just use C unlink()? * which really isn't suitable for gnu+linux/freedesktop.org desktops, it seems to be something very like (if not identical to) the macosx convention, but that's a matter for a different bug. --------------040105050802060801010406 Content-Type: text/x-patch; name="trash_xdevice_fix_r1.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="trash_xdevice_fix_r1.diff" Index: lisp/files.el =================================================================== RCS file: /sources/emacs/emacs/lisp/files.el,v retrieving revision 1.995 diff -U 8 -r1.995 files.el --- lisp/files.el 2 Sep 2008 16:10:44 -0000 1.995 +++ lisp/files.el 12 Sep 2008 01:43:51 -0000 @@ -5820,17 +5820,18 @@ ;; make new-fn unique. ;; example: "~/.Trash/abc.txt" -> "~/.Trash/abc.txt.~1~" (let ((version-control t)) (setq new-fn (car (find-backup-file-name new-fn))))) ;; stop processing if fn is same or parent directory of trash-dir. (and (string-match fn trash-dir) (error "Filename `%s' is same or parent directory of trash-directory" filename)) - (rename-file fn new-fn))))) + (let ((delete-by-moving-to-trash nil)) + (rename-file fn new-fn)))))) (define-key ctl-x-map "\C-f" 'find-file) (define-key ctl-x-map "\C-r" 'find-file-read-only) (define-key ctl-x-map "\C-v" 'find-alternate-file) (define-key ctl-x-map "\C-s" 'save-buffer) (define-key ctl-x-map "s" 'save-some-buffers) (define-key ctl-x-map "\C-w" 'write-file) --------------040105050802060801010406 Content-Type: text/plain; name="ChangeLog.trash_xdevice_fix_r1" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ChangeLog.trash_xdevice_fix_r1" 2008-09-11 David De La Harpe Golden files.el: in move-file-to-trash, bind delete-by-moving-to-trash to nil around rename-file to avoid recursive trashing if rename-file calls delete-file. --------------040105050802060801010406--