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


--- Comment #0 from lotrpy <lotrpy gmail.com> 2010-10-09 22:30:48 PDT ---
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



--- Comment #1 from Andrei Alexandrescu <andrei erdani.com> 2013-03-10 18:58:36
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


--- Comment #2 from Vladimir Panteleev <thecybershadow gmail.com> 2013-03-11
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


--- Comment #3 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-03-10
19:14:02 PDT ---
(In reply to comment #2)
 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



--- Comment #4 from Andrei Alexandrescu <andrei erdani.com> 2013-03-10 19:43:21
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



--- Comment #5 from Vladimir Panteleev <thecybershadow gmail.com> 2013-03-11
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



--- Comment #6 from Andrei Alexandrescu <andrei erdani.com> 2013-03-10 19:58:51
PDT ---
(In reply to comment #5)
 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



--- Comment #7 from Andrei Alexandrescu <andrei erdani.com> 2013-03-10 19:59:12
PDT ---
(In reply to comment #6)
 (In reply to comment #5)
 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


--- Comment #8 from Vladimir Panteleev <thecybershadow gmail.com> 2013-03-11
05:16:13 EET ---
(In reply to comment #6)
 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



--- Comment #9 from github-bugzilla puremagic.com 2013-03-11 22:03:51 PDT ---
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
Merge pull request #1198 from CyberShadow/fix5032

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