@@ -191,26 +191,29 @@ object ZipOpTests extends TestSuite {
191191 def prepare (
192192 wd : os.Path ,
193193 zipStream : Boolean = false ,
194- unzipStream : Boolean = false
194+ unzipStream : Boolean = false ,
195+ preserveLinks : Boolean = false
195196 ) = {
196197 val zipFileName = " zipped.zip"
197198 val source = wd / " folder2"
199+ val link = os.rel / " nestedA" / " link.txt"
198200 if (! scala.util.Properties .isWin) {
199201 os.perms.set(source / " nestedA" / " a.txt" , os.PermSet .fromString(" rw-rw-rw-" ))
200- os.symlink(source / " nestedA " / " link.txt " , os.rel / " a.txt" )
202+ os.symlink(source / link, os.rel / " a.txt" )
201203 }
202204
203205 val zipped =
204206 if (zipStream) {
205207 os.write(
206208 wd / zipFileName,
207- os.zip.stream(sources = List (source))
209+ os.zip.stream(sources = List (source), preserveLinks = preserveLinks )
208210 )
209211 wd / zipFileName
210212 } else {
211213 os.zip(
212214 dest = wd / zipFileName,
213- sources = List (source)
215+ sources = List (source),
216+ preserveLinks = preserveLinks
214217 )
215218 }
216219
@@ -228,56 +231,92 @@ object ZipOpTests extends TestSuite {
228231 )
229232 }
230233
231- (source, unzipped)
234+ (source, unzipped, link )
232235 }
233236
234237 def walkRel (p : os.Path ) = os.walk(p).map(_.relativeTo(p))
235238
236239 test(" zip" ) - prep { wd =>
237240 if (! scala.util.Properties .isWin) {
238- val (source, unzipped) = prepare(wd)
241+ val (source, unzipped, link ) = prepare(wd, preserveLinks = false )
239242
240243 assert(walkRel(source).toSet == walkRel(unzipped).toSet)
241244 assert(os.walk.stream(source)
242245 .filter(! os.isLink(_))
243246 .forall(p => os.perms(p) == os.perms(unzipped / p.relativeTo(source))))
244- assert(
245- os.walk.stream(source)
246- .filter(os.isLink(_))
247- .forall { p =>
248- val unzippedLink = unzipped / p.relativeTo(source)
249- os.isLink(unzippedLink) &&
250- os.readLink(p) == os.readLink(unzippedLink)
251- }
252- )
247+
248+ val unzippedLink = unzipped / link
249+ assert(os.isFile(unzippedLink))
250+ assert(os.read(os.readLink.absolute(source / link)) == os.read(unzippedLink))
251+ }
252+ }
253+
254+ test(" zipPreserveLinks" ) - prep { wd =>
255+ if (! scala.util.Properties .isWin) {
256+ val (source, unzipped, link) = prepare(wd, preserveLinks = true )
257+
258+ assert(walkRel(source).toSet == walkRel(unzipped).toSet)
259+ assert(os.walk.stream(source)
260+ .filter(! os.isLink(_))
261+ .forall(p => os.perms(p) == os.perms(unzipped / p.relativeTo(source))))
262+
263+ val unzippedLink = unzipped / link
264+ assert(os.isLink(unzippedLink))
265+ assert(os.readLink(source / link) == os.readLink(unzippedLink))
253266 }
254267 }
255268
256269 test(" zipStream" ) - prep { wd =>
257270 if (! scala.util.Properties .isWin) {
258- val (source, unzipped) = prepare(wd, zipStream = true )
271+ val (source, unzipped, link) = prepare(wd, zipStream = true , preserveLinks = false )
272+
273+ assert(walkRel(source).toSet == walkRel(unzipped).toSet)
274+ assert(os.walk.stream(source)
275+ .filter(! os.isLink(_))
276+ .forall(p => os.perms(p) == os.perms(unzipped / p.relativeTo(source))))
277+
278+ val unzippedLink = unzipped / link
279+ assert(os.isFile(unzippedLink))
280+ assert(os.read(os.readLink.absolute(source / link)) == os.read(unzippedLink))
281+ }
282+ }
283+
284+ test(" zipStreamPreserveLinks" ) - prep { wd =>
285+ if (! scala.util.Properties .isWin) {
286+ val (source, unzipped, link) = prepare(wd, zipStream = true , preserveLinks = true )
259287
260288 assert(walkRel(source).toSet == walkRel(unzipped).toSet)
261289 assert(os.walk.stream(source)
262290 .filter(! os.isLink(_))
263291 .forall(p => os.perms(p) == os.perms(unzipped / p.relativeTo(source))))
264- assert(
265- os.walk.stream(source)
266- .filter(os.isLink(_))
267- .forall { p =>
268- val unzippedLink = unzipped / p.relativeTo(source)
269- os.isLink(unzippedLink) &&
270- os.readLink(p) == os.readLink(unzippedLink)
271- }
272- )
292+
293+ val unzippedLink = unzipped / link
294+ assert(os.isLink(unzippedLink))
295+ assert(os.readLink(source / link) == os.readLink(unzippedLink))
296+ }
297+ }
298+
299+ test(" unzipStreamWithLinks" ) - prep { wd =>
300+ if (! scala.util.Properties .isWin) {
301+ val (source, unzipped, link) = prepare(wd, unzipStream = true , preserveLinks = true )
302+
303+ assert(walkRel(source).toSet == walkRel(unzipped).toSet)
304+
305+ val unzippedLink = unzipped / link
306+ assert(os.isFile(unzippedLink))
307+ assert(os.readLink(source / link).toString == os.read(unzippedLink))
273308 }
274309 }
275310
276311 test(" unzipStream" ) - prep { wd =>
277312 if (! scala.util.Properties .isWin) {
278- val (source, unzipped) = prepare(wd, unzipStream = true )
313+ val (source, unzipped, link ) = prepare(wd, unzipStream = true , preserveLinks = false )
279314
280315 assert(walkRel(source).toSet == walkRel(unzipped).toSet)
316+
317+ val unzippedLink = unzipped / link
318+ assert(os.isFile(unzippedLink))
319+ assert(os.read(os.readLink.absolute(source / link)) == os.read(unzippedLink))
281320 }
282321 }
283322 }
0 commit comments