@@ -8,6 +8,7 @@ import java.nio.file.attribute.{
88 BasicFileAttributes ,
99 BasicFileAttributeView ,
1010 FileTime ,
11+ PosixFilePermission ,
1112 PosixFilePermissions
1213}
1314import java .util .zip .{ZipEntry , ZipFile , ZipInputStream , ZipOutputStream }
@@ -188,6 +189,15 @@ object zip {
188189 else apache.PermissionUtils .FileType .OTHER
189190 }
190191
192+ // In zip, symlink info and posix permissions are stored together thus to store symlinks as
193+ // symlinks on Windows some permissions need to be set as well. Use 644/"rw-r--r--" as the default.
194+ private lazy val defaultPermissions = Set (
195+ PosixFilePermission .OWNER_READ ,
196+ PosixFilePermission .OWNER_WRITE ,
197+ PosixFilePermission .GROUP_READ ,
198+ PosixFilePermission .OTHERS_READ
199+ ).asJava
200+
191201 private def makeZipEntry (
192202 file : os.Path ,
193203 sub : os.SubPath ,
@@ -203,16 +213,20 @@ object zip {
203213 val mtime = if (preserveMtimes) os.mtime(file) else 0
204214 zipEntry.setTime(mtime)
205215
206- if (! isWin) {
216+ val symlink = ! followLinks && os.isLink(file)
217+
218+ if (! isWin || symlink) {
219+ val perms =
220+ if (isWin) defaultPermissions else os.perms(file, followLinks = followLinks).toSet()
207221 val mode = apache.PermissionUtils .modeFromPermissions(
208- os. perms(file, followLinks = followLinks).toSet() ,
222+ perms,
209223 toFileType(file, followLinks = followLinks)
210224 )
211225 zipEntry.setUnixMode(mode)
212226 }
213227
214228 val fis =
215- if (! followLinks && ! isWin && os.isLink(file) )
229+ if (symlink )
216230 Some (new java.io.ByteArrayInputStream (os.readLink(file).toString().getBytes()))
217231 else if (os.isFile(file)) Some (os.read.inputStream(file))
218232 else None
0 commit comments