GNU bug report logs - #3353
rename-file being called on directories for cross-device rename, mostly during trashing...

Previous Next

Package: emacs;

Reported by: David De La Harpe Golden <david <at> harpegolden.net>

Date: Fri, 22 May 2009 23:20:04 UTC

Severity: normal

Done: Chong Yidong <cyd <at> stupidchicken.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 3353 in the body.
You can then email your comments to 3353 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#3353; Package emacs. (Fri, 22 May 2009 23:20:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to David De La Harpe Golden <david <at> harpegolden.net>:
New bug report received and forwarded. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Fri, 22 May 2009 23:20:05 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: David De La Harpe Golden <david <at> harpegolden.net>
To: submit <at> debbugs.gnu.org
Subject: rename-file being called on directories for cross-device rename,
 mostly during trashing...
Date: Sat, 23 May 2009 00:10:48 +0100
Sorry about timing, first time I had to investigate - not sure this is 
release-critical - haven't proved it can really cause data loss,  but 
it's at least surprising.  I don't really use trashing myself, but 
noticed something was acting funny a while back:

On a gnu+linux or other unix-like system:
To replicate, you'll need two distinct mounted filesystems - I'll assume 
/home and /tmp  as they're often separate filesystems

Set delete-by-moving-to-trash non-nil
Now both delete-file and delete-directory will call move-file-to-trash 
to do their deletion.

Point your trash-directory to a subdir on one filesystem - the default 
~/.Trash/  may well be fine.

Make a directory on another filesystem, say
mkdir /tmp/uhoh/

Now try to
M-x delete-directory /tmp/uhoh/

Get an error:
Non-regular file: is a directory, /tmp/uhoh

... But of course you know it's a directory, and you are now puzzled
as to why it didn't delete.

Do the same with delete-by-moving-to-trash turned off, and the directory
will be deleted as one would expect.

This is happening because move-file-to-trash is calling rename-file
with the directory name, and then rename-file is blindly trying to 
copy-file the directory if the C-level rename() fails with EXDEV (around 
line 2269 in fileio.c) as it tries to emulate a rename for the regular
file case.

Some possible paths to addressing this issue (non-exhaustive...):

1. have move-file-to-trash check if the file is a directory before
trying to rename-file it.  The issue here is rename-file actually works
fine on directories as-is so long as you don't try to rename
them across filesystems.

2. make rename-file not blindly copy-file directories but throw
an error about renaming directories cross-device not being supported
on the platform. That might be "good enough" as a placeholder for the 
23.1 release, would at least be less confusing than the "Non-regular 
file: is a directory" error.

3. make rename-file not blindly copy-file directories but work
more like shell "mv".  Right now it acts a bit like mv for
regular files (emulates move with the problematic copy and delete), but 
like C-level rename() for directories (bombs out...)
(3a. Or make a separate rename-directory that move-file-to-trash can 
call for directories...)

4. make copy-file do something for directories other than simply 
noticing it's a directory and giving up, like shell "cp -r".
(4a. Or make a separate copy-directory that rename-file (or 3a's 
rename-directory) could call underneath)









Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#3353; Package emacs. (Wed, 27 Jan 2010 04:11:02 GMT) Full text and rfc822 format available.

Message #8 received at 3353 <at> debbugs.gnu.org (full text, mbox):

From: Chong Yidong <cyd <at> stupidchicken.com>
To: David De La Harpe Golden <david <at> harpegolden.net>
Cc: Tassilo Horn <tassilo <at> member.fsf.org>, 3353 <at> debbugs.gnu.org,
	5436 <at> debbugs.gnu.org
Subject: Re: bug#5436: 23.1.91;
	Deleting directories causes unusable file layout in freedesktop
	trashcan
Date: Tue, 26 Jan 2010 23:10:52 -0500
David De La Harpe Golden <david <at> harpegolden.net> writes:

> Chong Yidong wrote:
>
>> I understand what you are saying.  How about conditioning the
>> delete-directory change on delete-by-moving-to-trash?
>
> Unless I'm misunderstanding you (or did you mean the rename-file
> change?*):

Sorry, I meant the rename-file change.

However, after looking carefully at the change, I think it is OK.  I've
commited it to the respository.

Thank you for your work on this.




bug closed, send any further explanations to David De La Harpe Golden <david <at> harpegolden.net> Request was from Chong Yidong <cyd <at> stupidchicken.com> to control <at> debbugs.gnu.org. (Wed, 27 Jan 2010 04:13:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <bug-gnu-emacs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 24 Feb 2010 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 15 years and 169 days ago.

Previous Next


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