How to save file permissions when using FileUtils.copyDirectory?

When I use FileUtils.copyDirectory() , the execution bits are disabled for executable files.
Do I have to enable them manually?

FWIW, my umask is set to 0027, but it looks like FileUtils.copyDirectory() not using this parameter, since "other" permissions are saved except for the execution bit.

+7
source share
2 answers

New additions to the file system in Java 7 will help. Take a look at the JSR-203. If you are using Linux, you can use backport with Java 6.

The new API you want: Files.copy(Path, Path, CopyOptions) . Note that CopyOptions has COPY_ATTRIBUTES , which will do what you want.

+5
source

I do not think this is possible due to JVM limitations. IO api and behavior are shameful for the most popular language / platform in the world.

If you look at the source code of FileUtils, during copying it creates a new file like this

 File copiedFile = new File(destDir, srcFile.getName()); 

file permissions are not saved. And during the actual copy, the bytes are copied to the batch (buffered) and written to a new file.

but you can wait a couple of days or use the preview release of JDK7, which has apis to make this possible.

+3
source

All Articles