unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: David De La Harpe Golden <david@harpegolden.net>
To: submit@emacsbugs.donarmstrong.com
Subject: bug#3353: rename-file being called on directories for cross-device rename, mostly during trashing...
Date: Sat, 23 May 2009 00:10:48 +0100	[thread overview]
Message-ID: <4A1730F8.7060708@harpegolden.net> (raw)

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)











                 reply	other threads:[~2009-05-22 23:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A1730F8.7060708@harpegolden.net \
    --to=david@harpegolden.net \
    --cc=3353@emacsbugs.donarmstrong.com \
    --cc=submit@emacsbugs.donarmstrong.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).