copy - Java ZipFileSystem attributes -
so using code similar following (pulled http://fahdshariff.blogspot.com/2011/08/java-7-working-with-zip-files.html):
/** * creates/updates zip file. * @param zipfilename name of zip create * @param filenames list of filename add 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 on files need add (string filename : filenames) { final path src = paths.get(filename); //add file 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 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 call files.copy() in visitfile() method, src has 'rwxr-xr-x' file permissions, , dest created. when unzip result, corresponding file has 'rw-r--r--' permissions. tried using
files.copy(src, dest, standardcopyoption.copy_attributes, standardcopyoption.replace_existing) but file still has 'rw-r--r--' permissions... doing files.create() 'rwxr-xr-x' permissions set has same result... ideas?
edit: tried following, unsupportedoperationexception:
set<posixfilepermission> permissions = posixfilepermissions.fromstring("rwxr-xr-x"); files.setposixfilepermissions(dest, permissions);
the zip file format default not support unix filesystem features. , zip filesystem provider @ least not support store unix file permissions.
// zip created teh java zipfs zipinfo foobar.zip file system or operating system of origin: ms-dos, os/2 or nt fat version of encoding software: 2.0 ... non-msdos external file attributes: 000000 hex ms-dos file attributes (00 hex): none if create zip file linux version of info-zip implementation.
file system or operating system of origin: unix version of encoding software: 3.0 ... apparent file type: text unix file attributes (100755 octal): -rwxr-xr-x ms-dos file attributes (00 hex): none for more information might have source of zipfilesystem.java original source or current included in jdk 8 demos , samples
edit you try truevfs instead of zipfs. after quick check seems not support unix file permissions.
you use apache commons compress. following javadoc supports unix permissions.
from ziparchiveentry.setunixmode
sets unix permissions in way understood info-zip's unzip command.
Comments
Post a Comment