Change
Currently Directory.rename() has two undesirable properties on Windows:
- if the target path is an existing directory then it is deleted
- if the target path matches the current path, then the directory is deleted
I propose that we remove both of those behaviors i.e. it is an no-op if the src and target paths are identical and it is an error if the target path is an existing directory.
See https://dart-review.googlesource.com/c/sdk/+/219501
Rationale
This change will bring the semantics of Directory.rename() on Windows inline with the semantics on every other platform - except that it will be an error to rename to a existing empty directory, which is allowed on POSIX systems.
This is inline with the behavior offered in other programming languages:
https://en.cppreference.com/w/cpp/filesystem/rename
https://docs.python.org/3/library/os.html#os.rename
https://docs.oracle.com/javase/7/docs/api/java/io/File.html#renameTo(java.io.File)
https://doc.rust-lang.org/std/fs/fn.rename.html
Impact
It is possible (but not likely IMO) that some dart Windows-only programs rely on this behavior but it is more likely that existing programs have a large unintended footgun and this will remove it.
Mitigation
Users can first remove the target directory before rename i.e.
Directory(target).deleteSync()
Directory(src).renameSync(target)
Change
Currently
Directory.rename()has two undesirable properties on Windows:I propose that we remove both of those behaviors i.e. it is an no-op if the src and target paths are identical and it is an error if the target path is an existing directory.
See https://dart-review.googlesource.com/c/sdk/+/219501
Rationale
This change will bring the semantics of
Directory.rename()on Windows inline with the semantics on every other platform - except that it will be an error torenameto a existing empty directory, which is allowed on POSIX systems.This is inline with the behavior offered in other programming languages:
https://en.cppreference.com/w/cpp/filesystem/rename
https://docs.python.org/3/library/os.html#os.rename
https://docs.oracle.com/javase/7/docs/api/java/io/File.html#renameTo(java.io.File)
https://doc.rust-lang.org/std/fs/fn.rename.html
Impact
It is possible (but not likely IMO) that some dart Windows-only programs rely on this behavior but it is more likely that existing programs have a large unintended footgun and this will remove it.
Mitigation
Users can first remove the target directory before
renamei.e.