Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to preserve file permissions when using FileUtils.copyDirectory?

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.

like image 843
Noel Yap Avatar asked Jul 27 '11 00:07

Noel Yap


1 Answers

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.

like image 93
Dilum Ranatunga Avatar answered Oct 07 '22 19:10

Dilum Ranatunga