Description
NTFS files may contain alternate data streams besides the main one. Since PR #26751, std::fs::copy
returns the combined size of all streams, which is confusing and likely unexpected unless the user is aware of this Windows/NTFS peculiarity.
An example where Windows uses alternate data streams seems to be when storing whether a file was downloaded from the internet (e.g. to display a security section and an "Unblock" button in the file properties). Such alternate streams are more like metadata, and to be consistent with other file metadata (attributes, permissions, extended attributes, etc.), their size should not be reflected in the value returned by copy
.
In summary, I think std::fs::copy
should return the size of the main stream for the following reasons (alternate data streams are still copied, their size is just not reported, like other metadata):
- This is the least confusing result for non-NTFS experts and what most people expect (no "copying more bytes than the file contains").
- This is consistent with other file metadata whose size is not reported by
copy
. - Alternate streams are mostly invisible, unless you try to open them explicitly. Even the file properties don't show them and Windows reports only the size of the main stream in the dialog.
@retep998, what do you think?
Steps to reproduce
- On Windows, download an executable file to a NTFS partition and verify that the property dialog contains a security section with an "Unblock" button.
- Note the file size reported in the file properties.
- Copy the file to the same partition using
std::fs::copy
and note the number of bytes returned.
Expected result
The number of bytes copied reported by copy
is equal to the file size.
Actual result
copy
reports a number of bytes greater than the file size.