copyTo() without any copy option copies the alternate data streams to the target file(win)
Alan Bateman
Alan.Bateman at Sun.COM
Wed Jun 11 02:39:19 PDT 2008
Rajendra Gutupalli wrote:
> Hi Alan,
>
> 1)
> Spec for Path.copyTo() says "File attributes are not required to be
> copied to the target file".
> I observed in Windows vista it copies the alternate data stream (named
> attribute) associated with file.
> Could you please tell me whether the observed behavior is expected in
> Windows. If it is expected
> then how can I copy the file discarding the associated data streams to
> another volume using copyTo method.
A good question! For the first part, "yes", this is expected. This is no
different to copying a file via the copy command or using the file
explorer when the source and target volumes are NTFS.
Stepping back for a moment, the copyTo method, when invoked without any
options, is simply required to copy the file (the unamed stream in this
case) and doesn't set any expectations on meta-data (or the named
streams in this case). It is essentially a simple "cp" or equivalent.
When invoked with the COPY_ATTRIBUTES option then it attempts to copy
the file attributes and is essentially a "cp -p" or equivalent. Aside
from minimal guarantees it does not (and cannot) specify which file
attributes are copied. On Solaris/Linux you'll see that it works just
like "cp -p" so the permissions, owner, timestamps, extended attributes,
etc. are copied when supported by the target file system. On Windows it
copies all the NTFS attributes, named streams, etc. if supported by
target volume.
We have not included copy options to allow for fine control on the
attributes that are copied or not-copied. It's hard to say if many
non-specialized applications would need this but the copy options are
extensible so we could add this later if really needed (at the risk of a
bit of complexity). So far nobody has threatened bodily harm over this :-)
>
>
> 2) Could you please tell me is there any restrictions for naming a
> alternate data streams. I am able to name nul, LP1 and all other
> characters that are forbidden for naming a file which are mentioned in
> the msdn site:
> http://msdn.microsoft.com/en-us/library/aa365247.aspx
>
These are stream names rather than file names. I believe they are stored
as UTF-16/UCS-2 without any Unicode normalization or other special
treatment. I'm not aware of any restrictions on characters.
-Alan.
More information about the nio-dev
mailing list