GNU bug report logs - #14628
mv: safeguard against renaming dir with open files

Previous Next

Package: coreutils;

Reported by: "S. Dara" <saif.dara <at> gmail.com>

Date: Sat, 15 Jun 2013 20:18:02 UTC

Severity: wishlist

Done: Assaf Gordon <assafgordon <at> gmail.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 14628 in the body.
You can then email your comments to 14628 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-coreutils <at> gnu.org:
bug#14628; Package coreutils. (Sat, 15 Jun 2013 20:18:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "S. Dara" <saif.dara <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Sat, 15 Jun 2013 20:18:02 GMT) Full text and rfc822 format available.

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

From: "S. Dara" <saif.dara <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: mv command (and suggesting a feature for it)
Date: Sat, 15 Jun 2013 22:02:22 +0200
Dear authors of the mv command,

With this email, I would like to suggest a feature for the mv command. I 
believe this command should contain a safeguard feature which will deny 
renaming a directory that contains files which are currently opened by 
the user.

For example, I have a directory named 'my directory'. In this directory, 
there is a .txt file which I had opened and was entering text in it. In 
the command prompt, I decided to change the name of 'my directory' to 
'mydirectory' using the command 'mv -ivT my\ directory mydirectory'. 
Although command succeeded, when I wanted to save the text file which I 
was working on I got an error from my text editor saying the directory 
does not exist. This is due to the name change of the parent directory 
of the .txt-file.

I hope the problem is clear by above example. If there already exists 
such safeguard by providing some specific option to the mv command, then 
please discard this email and my apologies.


With kind regards,


Saif Dara





Information forwarded to bug-coreutils <at> gnu.org:
bug#14628; Package coreutils. (Sat, 15 Jun 2013 23:37:02 GMT) Full text and rfc822 format available.

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

From: Pádraig Brady <P <at> draigBrady.com>
To: "S. Dara" <saif.dara <at> gmail.com>
Cc: 14628 <at> debbugs.gnu.org
Subject: Re: bug#14628: mv command (and suggesting a feature for it)
Date: Sun, 16 Jun 2013 00:35:48 +0100
tag 14628 wishlist
stop

On 06/15/2013 09:02 PM, S. Dara wrote:
> Dear authors of the mv command,
> 
> With this email, I would like to suggest a feature for the mv command. I believe this command should contain a safeguard feature which will deny renaming a directory that contains files which are currently opened by the user.
> 
> For example, I have a directory named 'my directory'. In this directory, there is a .txt file which I had opened and was entering text in it. In the command prompt, I decided to change the name of 'my directory' to 'mydirectory' using the command 'mv -ivT my\ directory mydirectory'. Although command succeeded, when I wanted to save the text file which I was working on I got an error from my text editor saying the directory does not exist. This is due to the name change of the parent directory of the .txt-file.
> 
> I hope the problem is clear by above example. If there already exists such safeguard by providing some specific option to the mv command, then please discard this email and my apologies.
> 
> 
> With kind regards,

While I see the issue, I think it's probably outside the remit
of mv to make such checks. Depending on how the open file
is being processed, it may be immune to renames.
I.E. if the file descriptor is just being manipulated,
then naming is irrelevant. Also if name operations are
done on relative paths and the rename is higher in the
directory hierarchy, again the rename is irrelevant.

I'm thinking that something external to mv could be used here, like:

safe_rename() { lsof +D "$1" >/dev/null 2>&1 || mv "$1" "$2"; }

Note however lsof as presented there at least doesn't support
this with the correct exit code, due to it requiring _all_ files
rather than _any_ files in the hierarchy under "$1" to be open.
This is also a very expensive operation as noted in the lsof man page.

cheers,
Pádraig.





Information forwarded to bug-coreutils <at> gnu.org:
bug#14628; Package coreutils. (Fri, 19 Oct 2018 16:54:02 GMT) Full text and rfc822 format available.

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

From: Assaf Gordon <assafgordon <at> gmail.com>
To: 14628 <at> debbugs.gnu.org
Subject: Re: bug#14628: mv command (and suggesting a feature for it)
Date: Fri, 19 Oct 2018 10:53:04 -0600
severity 14628 wishlist
retitle  14628 mv: safeguard against renaming dir with open files
close 14628
stop

(triaging old bugs)

On 15/06/13 05:35 PM, Pádraig Brady wrote:
> 
> On 06/15/2013 09:02 PM, S. Dara wrote:
>>
>> With this email, I would like to suggest a feature for the mv command. I believe this command should contain a safeguard feature which will deny renaming a directory that contains files which are currently opened by the user.
> 
> While I see the issue, I think it's probably outside the remit
> of mv to make such checks.


With no further comments in 5 years, I'm closing this item.

-assaf




Severity set to 'wishlist' from 'normal' Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 19 Oct 2018 16:54:02 GMT) Full text and rfc822 format available.

Changed bug title to 'mv: safeguard against renaming dir with open files' from 'mv command (and suggesting a feature for it)' Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 19 Oct 2018 16:54:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 14628 <at> debbugs.gnu.org and "S. Dara" <saif.dara <at> gmail.com> Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 19 Oct 2018 16:54:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 17 Nov 2018 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 215 days ago.

Previous Next


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