From 61c0c9e5f21f231bca1c5594c2b6616e419b86fc Mon Sep 17 00:00:00 2001 From: Stephane Raux Date: Wed, 27 Sep 2017 19:43:05 -0700 Subject: 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 --- src/libstd/sys/windows/fs.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/libstd/sys') 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 { pub fn copy(from: &Path, to: &Path) -> io::Result { 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)?; -- cgit 1.4.1-3-g733a5