diff options
| author | bors <bors@rust-lang.org> | 2016-04-12 10:12:55 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-04-12 10:12:55 -0700 |
| commit | a4f781e47710d8c938130446bf4cd5e9be2231d2 (patch) | |
| tree | 14c792420a3b1405b59acf413a57b54eef1bf2f6 /src/libstd | |
| parent | 933000613b7774727dd7f1bfe766e2bee71c5747 (diff) | |
| parent | bcbc9e5346941011f36f71f66c808675b263a589 (diff) | |
| download | rust-a4f781e47710d8c938130446bf4cd5e9be2231d2.tar.gz rust-a4f781e47710d8c938130446bf4cd5e9be2231d2.zip | |
Auto merge of #31963 - barosl:rename-doc, r=alexcrichton
Describe more platform-specific behaviors of `std::fs::rename` I did some tests myself regarding the situation when both `from` and `to` exist, and the results were: On Linux: `from` | `to` | Result ---- | ---- | ---- Directory | Directory | Ok Directory | File | Error File | Directory | Error File | File | Ok On Windows: `from` | `to` | Result ---- | ---- | ---- Directory | Directory | Error Directory | File | Ok File | Directory | Error File | File | Ok This is a bit against the official MSDN documentation, which says "(`MOVEFILE_REPLACE_EXISTING`) cannot be used if `lpNewFileName` or `lpExistingFileName` names a directory." As evidenced above, `lpExistingFileName` *can* be a directory. I also mentioned the atomicity of the operation. Fixes #31301.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/fs.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index f5a51e97427..03ebaa59ca5 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -965,7 +965,8 @@ pub fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> { fs_imp::lstat(path.as_ref()).map(Metadata) } -/// Rename a file or directory to a new name. +/// Rename a file or directory to a new name, replacing the original file if +/// `to` already exists. /// /// This will not work if the new name is on a different mount point. /// @@ -973,6 +974,12 @@ pub fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> { /// /// This function currently corresponds to the `rename` function on Unix /// and the `MoveFileEx` function with the `MOVEFILE_REPLACE_EXISTING` flag on Windows. +/// +/// Because of this, the behavior when both `from` and `to` exist differs. On +/// Unix, if `from` is a directory, `to` must also be an (empty) directory. If +/// `from` is not a directory, `to` must also be not a directory. In contrast, +/// on Windows, `from` can be anything, but `to` must *not* be a directory. +/// /// Note that, this [may change in the future][changes]. /// [changes]: ../io/index.html#platform-specific-behavior /// |
