Files.copy() under Linux at least will remove the existing destination even if the source cannot be read...

Alan Bateman Alan.Bateman at oracle.com
Wed Feb 11 21:35:46 UTC 2015


On 11/02/2015 20:57, Francis Galiegue wrote:
> Not sure if this is wanted, but...
>
> $ touch a b
> $ ls -l ?
> -rw-rw-r-- 1 fge fge 0 Feb 11 21:55 a
> -rw-rw-r-- 1 fge fge 0 Feb 11 21:55 b
> $ chmod 0 a
> $ cp a b
> cp: cannot open ‘a’ for reading: Permission denied
> $ ls -l ?
> ---------- 1 fge fge 0 Feb 11 21:55 a
> -rw-rw-r-- 1 fge fge 0 Feb 11 21:55 b
> $
>
> BUT...
>
> If I have Paths to a and b and do:
>
> Files.copy(a, b, StandardCopyOption.REPLACE_EXISTING);
>
> then b is deleted even though you cannot even copy the contents from a
> in the first place!
The implementation does test the the source file before removing the 
target but it should really have it open to avoid this scenario. Can you 
submit a bug on this?

-Alan


More information about the nio-dev mailing list