copyTo/moveTo overwrite

Salter, Thomas A Thomas.Salter at unisys.com
Thu Jan 14 12:19:37 PST 2010


I found it through testing.  We're porting to a system with where the file system is essentially two independent file systems (one Windows, one legacy).  Copying within a file system works with the platform's CopyFile/MoveFile functions.  Copying between the file systems is equivalent to copying between providers, so I borrowed the methods in AbstractPath.  This would be much easier, by the way, if copyToForeignTarget and convertMoveToCopyOptions were protected rather than private in AbstractPath.


-----Original Message-----
From: Alan.Bateman at Sun.COM [mailto:Alan.Bateman at Sun.COM]
Sent: Thursday, January 14, 2010 3:00 PM
To: Salter, Thomas A
Cc: nio-dev at openjdk.java.net
Subject: Re: copyTo/moveTo overwrite

Salter, Thomas A wrote:
> When doing a copyTo or moveTo with different providers, it looks like
> AbstractPath.copyToForeignTarget will overwrite the target file even
> if REPLACE_EXISTING is not set.  It correctly deletes the target only
> if REPLACE_EXISTING is set but then later in
> copyRegularFileToForeignTarget calls newByteChannel with CREATE, so
> any existing file is overwritten.  It should have used CREATE_NEW
> instead of CREATE.
>
You are right! When copying or moving a file to a location that is
associated with some other provider then it shouldn't replace an
existing file unless the REPLACE_EXISTING option is present. Thanks for
finding this. Our of curiosity, did you find this by inspection or were
you testing with your own provider? Our existing tests doesn't exercise
this scenario (not yet anyway).

-Alan.


More information about the nio-dev mailing list