www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5032] New: std.file.rename acts differently on Windows and Linux when the target file already exists.

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5032

           Summary: std.file.rename acts differently on Windows and Linux
                    when the target file already exists.
           Product: D
           Version: D2
          Platform: x86
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: lotrpy gmail.com



rename, on windows, if the file exists will throw a FileException. However, on
Linux, it succeeds.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 09 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5032


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5032




PDT ---
Could somebody with access to a Windows machine change std.file.rename to
overwrite the target? I see in
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85).aspx
that MoveFileEx offers such a flag.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5032


Vladimir Panteleev <thecybershadow gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow gmail.com



04:03:41 EET ---
Is that the right thing to do, though? I'd expect the function to throw if the
target exists. Doesn't help that the docs for either "copy" and "rename" do not
specify what it does in that situation.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5032


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



19:14:02 PDT ---

 Is that the right thing to do, though? I'd expect the function to throw if the
 target exists. Doesn't help that the docs for either "copy" and "rename" do not
 specify what it does in that situation.
Yeah I agree. If anything make the forced renaming an option, not a default behavior. That's how most tools work on win32 anyway, dunno about Posix though. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5032




PDT ---
No, rename must clobber. It's the only way things can be done atomically on
Unix as far as I can tell. If we have code such as "if (!exists(target))
rename(source, target)" we have a race condition.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5032




04:53:21 EET ---
I think a clobber option with the default set to "no" would be better.
Atomicity is a valid concern, but I don't think the default behavior should
imply the risk of accidentally overwriting files.

It's too late to change the behavior of "copy", and atomicity does not apply to
it anyway.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5032




PDT ---

 I think a clobber option with the default set to "no" would be better.
 Atomicity is a valid concern, but I don't think the default behavior should
 imply the risk of accidentally overwriting files.
Atomicity is not a concern as much as a gating factor. How to implement the clobber option "no" on Unix?
 It's too late to change the behavior of "copy", and atomicity does not apply to
 it anyway.
This is remove. It must clobber the target on both Windows and Unix. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5032




PDT ---


 I think a clobber option with the default set to "no" would be better.
 Atomicity is a valid concern, but I don't think the default behavior should
 imply the risk of accidentally overwriting files.
Atomicity is not a concern as much as a gating factor. How to implement the clobber option "no" on Unix?
 It's too late to change the behavior of "copy", and atomicity does not apply to
 it anyway.
This is remove. It must clobber the target on both Windows and Unix.
I mean "This is rename." :o) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5032


Vladimir Panteleev <thecybershadow gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull



05:16:13 EET ---

 Atomicity is not a concern as much as a gating factor. How to implement the
 clobber option "no" on Unix?
Good point.
 This is rename. It must clobber the target on both Windows and Unix.
Yep, I mentioned copy earlier as they're related. https://github.com/D-Programming-Language/phobos/pull/1198 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5032




Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/7d35ad4953d6dd24857bb978219183abce266f4a
std.file: Make rename clobber on Windows, adjust docs (Issue 5032)

https://github.com/D-Programming-Language/phobos/commit/bba5dbe1c6ab5bb32432d6e7d8fd960713b04163


std.file: Fix/document/test clobber behavior for copy and rename (Issue 5032)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 11 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5032


Alex Rønne Petersen <alex lycus.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
                 CC|                            |alex lycus.org
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 11 2013