diff options
| author | bors <bors@rust-lang.org> | 2017-10-03 22:19:40 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-10-03 22:19:40 +0000 |
| commit | bd90aa6daa5b73c2be85f604129ee40a6734cb6b (patch) | |
| tree | 20f4643c039a026cf67841323ca42b18eae2dd3b /src/libstd/sys | |
| parent | 4502e2aa9c28d8caa610fc1815fd9c5b5a16e91c (diff) | |
| parent | 61c0c9e5f21f231bca1c5594c2b6616e419b86fc (diff) | |
| download | rust-bd90aa6daa5b73c2be85f604129ee40a6734cb6b.tar.gz rust-bd90aa6daa5b73c2be85f604129ee40a6734cb6b.zip | |
Auto merge of #44895 - stephaneyfx:master, r=dtolnay
Made `fs::copy` return the length of the main stream On Windows with the NTFS filesystem, `fs::copy` would return the sum of the lengths of all streams, which can be different from the length reported by `metadata` and thus confusing for users unaware of this NTFS peculiarity. This makes `fs::copy` return the same length `metadata` reports which is the value it used to return before PR #26751. Note that alternate streams are still copied; their length is just not included in the returned value. This change relies on the assumption that the stream with index 1 is always the main stream in the `CopyFileEx` callback. I could not find any official document confirming this but empirical testing has shown this to be true, regardless of whether the alternate stream is created before or after the main stream. Resolves #44532
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/windows/fs.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index f2487c1b0bd..ae9535139d9 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -722,16 +722,16 @@ pub fn canonicalize(p: &Path) -> io::Result<PathBuf> { pub fn copy(from: &Path, to: &Path) -> io::Result<u64> { unsafe extern "system" fn callback( _TotalFileSize: c::LARGE_INTEGER, - TotalBytesTransferred: c::LARGE_INTEGER, + _TotalBytesTransferred: c::LARGE_INTEGER, _StreamSize: c::LARGE_INTEGER, - _StreamBytesTransferred: c::LARGE_INTEGER, - _dwStreamNumber: c::DWORD, + StreamBytesTransferred: c::LARGE_INTEGER, + dwStreamNumber: c::DWORD, _dwCallbackReason: c::DWORD, _hSourceFile: c::HANDLE, _hDestinationFile: c::HANDLE, lpData: c::LPVOID, ) -> c::DWORD { - *(lpData as *mut i64) = TotalBytesTransferred; + if dwStreamNumber == 1 {*(lpData as *mut i64) = StreamBytesTransferred;} c::PROGRESS_CONTINUE } let pfrom = to_u16s(from)?; |
