Reputation: 19798
When I use FileUtils.copyDirectory()
, the execute bits get turned off for executable files.
Do I have to turn them on manually?
FWIW, my umask is set to 0027 but it looks like FileUtils.copyDirectory()
is not using that setting since the 'other' permissions, aside from the execute bit, are preserved.
Upvotes: 12
Views: 8665
Reputation: 13374
The upcoming Filesystem additions in Java 7 will help. Look at JSR-203. If you are using Linux, you can use the backport with Java 6.
The new API that you want is: Files.copy(Path, Path, CopyOptions)
. Note that CopyOptions
has COPY_ATTRIBUTES
, which will do what you want.
Upvotes: 8
Reputation: 6423
I don't think its possible because of JVM limitations. The IO api and behavior is kinda shameful for the most popular language/platform in the world.
If you look at the FileUtils source code, during copy it creates the new file like this
File copiedFile = new File(destDir, srcFile.getName());
the file permissions are not preserved. And during actual copy the bytes are copied in batches ( buffered ) and written to the new file.
but, you could wait a couple of days or use the preview release of JDK7 which has apis to allow this to be possible.
Upvotes: 3