简体   繁体   中英

Maintain file permissions while unzipping in clojure

I want to unzip files from a zip package which can have text, executable files in it. I have figured out way using Java interop to unzip the contents of the file at given location.

However, after everthing's unzipped at given locations, I am not able to run the executable files, because the permissions are not set as executable on the files.

I am using ZipInputStream and BufferedOutputStream from Java APIs, to read and write respectively. I don't think there's anything wrong with my code, because I can see the side effect and the files are unzipped as expected. Also, I checked the permissions on files and none of the executables have x permission on it.

Sure, I can run the unzip command instead and that should take care of everything, but I am not sure which platform the program would run on. So, I thought I'd programmatically unzip everything.

Can I really use, unzip command? Or is there any other recommended way?

Thanks.

If your program is crating the files on the disk then it's that program's responsibility to set the permissions. It sounds like every file is getting the default file permissions, which would not include setting the executable bit.

If the library you are using gives you access to the permissions that where stored for a given file within the archive, then it would be fairly straightforward to reset the permissions on the file after you finish writing it.

Do keep security in the back of your mind if you are unpacking files provided by someone else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM