So I am using a code VERY similar to the following (pulled from http://fahdshariff.blogspot.com/2011/08/java-7-working-with-zip-files.html):
/**
* Creates/updates a zip file.
* @param zipFilename the name of the zip to create
* @param filenames list of filename to add to the zip
* @throws IOException
*/
public static void create(String zipFilename, String... filenames)
throws IOException {
try (FileSystem zipFileSystem = createZipFileSystem(zipFilename, true)) {
final Path root = zipFileSystem.getPath("/");
//iterate over the files we need to add
for (String filename : filenames) {
final Path src = Paths.get(filename);
//add a file to the zip file system
if(!Files.isDirectory(src)){
final Path dest = zipFileSystem.getPath(root.toString(),
src.toString());
final Path parent = dest.getParent();
if(Files.notExists(parent)){
System.out.printf("Creating directory %s\n", parent);
Files.createDirectories(parent);
}
Files.copy(src, dest, StandardCopyOption.REPLACE_EXISTING);
}
else{
//for directories, walk the file tree
Files.walkFileTree(src, new SimpleFileVisitor<Path>(){
@Override
public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) throws IOException {
final Path dest = zipFileSystem.getPath(root.toString(),
file.toString());
Files.copy(file, dest, StandardCopyOption.REPLACE_EXISTING);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult preVisitDirectory(Path dir,
BasicFileAttributes attrs) throws IOException {
final Path dirToCreate = zipFileSystem.getPath(root.toString(),
dir.toString());
if(Files.notExists(dirToCreate)){
System.out.printf("Creating directory %s\n", dirToCreate);
Files.createDirectories(dirToCreate);
}
return FileVisitResult.CONTINUE;
}
});
}
}
}
}
When I call the Files.copy() in the visitFile() method, the src has 'rwxr-xr-x' file permissions, and the dest is successfully created. When I unzip the result, the corresponding file has only 'rw-r--r--' permissions. I tried using
Files.copy(src, dest, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING)
but the file still has 'rw-r--r--' permissions... Doing a Files.create() with 'rwxr-xr-x' permissions set has the same result... Any ideas?
EDIT: I tried the following, but i just get an UnsupportedOperationException:
Set<PosixFilePermission> permissions = PosixFilePermissions.fromString("rwxr-xr-x");
Files.setPosixFilePermissions(dest, permissions);