Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions os/src/ZipOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object zip {
excludePatterns,
includePatterns,
(path, sub) => {
os.copy.over(path, opened / sub, createFolders = true)
os.copy(path, opened / sub, createFolders = true)
if (!preserveMtimes) {
os.mtime.set(opened / sub, 0)
// This is the only way we can properly zero out filesystem metadata within the
Expand Down Expand Up @@ -98,12 +98,10 @@ object zip {
sources.foreach { source =>
if (os.isDir(source.src)) {
for (path <- os.walk(source.src)) {
if (shouldInclude(path.toString, excludePatterns, includePatterns)) {
val target = source.dest.getOrElse(os.sub) / path.subRelativeTo(source.src / os.up)
makeZipEntry0(path, target)
if (os.isFile(path) && shouldInclude(path.toString, excludePatterns, includePatterns)) {
makeZipEntry0(path, source.dest.getOrElse(os.sub) / path.subRelativeTo(source.src))
}
}
makeZipEntry0(source.src, source.dest.getOrElse(os.sub / source.src.last))
} else if (shouldInclude(source.src.last, excludePatterns, includePatterns)) {
makeZipEntry0(source.src, source.dest.getOrElse(os.sub / source.src.last))
}
Expand Down Expand Up @@ -155,7 +153,6 @@ object zip {
val mtimeOpt = if (preserveMtimes) Some(os.mtime(file)) else None

val fis = if (os.isFile(file)) Some(os.read.inputStream(file)) else None

try makeZipEntry0(sub, fis, mtimeOpt, zipOut)
finally fis.foreach(_.close())
}
Expand All @@ -166,14 +163,7 @@ object zip {
preserveMtimes: Option[Long],
zipOut: ZipOutputStream
) = {
val path = is match {
// for folder
case None => sub.toString + "/"
// for file
case Some(_) => sub.toString
}

val zipEntry = new ZipEntry(path)
val zipEntry = new ZipEntry(sub.toString)

preserveMtimes match {
case Some(mtime) => zipEntry.setTime(mtime)
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions os/test/src-jvm/SpawningSubprocessesNewTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ object SpawningSubprocessesNewTests extends TestSuite {
stdout =
os.ProcessOutput((buf, len) => lineCount += buf.slice(0, len).count(_ == '\n'))
)
lineCount ==> 24
lineCount ==> 22
}
}
test - prep { wd =>
Expand All @@ -97,7 +97,7 @@ object SpawningSubprocessesNewTests extends TestSuite {
cwd = wd,
stdout = os.ProcessOutput.Readlines(line => lineCount += 1)
)
lineCount ==> 24
lineCount ==> 22
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions os/test/src-jvm/SpawningSubprocessesTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ object SpawningSubprocessesTests extends TestSuite {
stdout =
os.ProcessOutput((buf, len) => lineCount += buf.slice(0, len).count(_ == '\n'))
)
lineCount ==> 24
lineCount ==> 22
}
}
test - prep { wd =>
Expand All @@ -92,7 +92,7 @@ object SpawningSubprocessesTests extends TestSuite {
cwd = wd,
stdout = os.ProcessOutput.Readlines(line => lineCount += 1)
)
lineCount ==> 24
lineCount ==> 22
}
}
}
Expand Down
20 changes: 9 additions & 11 deletions os/test/src-jvm/ZipOpJvmTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,19 @@ object ZipOpJvmTests extends TestSuite {
dest = wd / "unzipped folder"
)

val paths = os.walk(unzippedFolder).toList.sorted
val expected = List(
val paths = os.walk(unzippedFolder)
val expected = Seq(
// Files get included in the zip root using their name
wd / "unzipped folder/File.txt",
wd / "unzipped folder/Multi Line.txt",
// Folder contents get included relative to the source root
wd / "unzipped folder/folder1",
wd / "unzipped folder/folder1/one.txt",
wd / "unzipped folder/folder2",
wd / "unzipped folder/folder2/nestedA",
wd / "unzipped folder/folder2/nestedA/a.txt",
wd / "unzipped folder/folder2/nestedB",
wd / "unzipped folder/folder2/nestedB/b.txt"
).sorted
assert(paths == expected)
wd / "unzipped folder/nestedA",
wd / "unzipped folder/nestedB",
wd / "unzipped folder/one.txt",
wd / "unzipped folder/nestedA/a.txt",
wd / "unzipped folder/nestedB/b.txt"
)
assert(paths.sorted == expected)
}

test("zipAndUnzipPreserveMtimes") - prep { wd =>
Expand Down
7 changes: 3 additions & 4 deletions os/test/src/CheckerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,8 @@ object CheckerTests extends TestSuite {
val unzipDir = os.unzip(zipFile, wd / "unzipped")
os.walk(unzipDir).sorted ==> Seq(
unzipDir / "File.txt",
unzipDir / "folder1/one.txt",
unzipDir / "folder1"
).sorted
unzipDir / "one.txt"
)
}
test("unzip") - prepChecker { wd =>
val zipFileName = "zipped.zip"
Expand All @@ -479,7 +478,7 @@ object CheckerTests extends TestSuite {
source = zipFile,
dest = wd / "unzipped"
)
os.walk(unzipDir).length ==> 3
os.walk(unzipDir).length ==> 2
}
}
}
3 changes: 1 addition & 2 deletions os/test/src/OpTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ object OpTests extends TestSuite {
res / "misc",
res / "os",
res / "File.txt",
res / "Multi Line.txt",
res / "emptyFolder"
res / "Multi Line.txt"
),
os.list(res / "folder2").toSet == Set(
res / "folder2/nestedA",
Expand Down
49 changes: 14 additions & 35 deletions os/test/src/ZipOpTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ object ZipOpTests extends TestSuite {
val expected = Seq(
wd / "unzipped folder/renamed-file.txt",
wd / "unzipped folder/renamed-folder",
wd / "unzipped folder/renamed-folder/folder1",
wd / "unzipped folder/renamed-folder/folder1/one.txt"
wd / "unzipped folder/renamed-folder/one.txt"
)
assert(paths.sorted == expected.sorted)
assert(paths.sorted == expected)
}

test("excludePatterns") - prep { wd =>
Expand All @@ -81,9 +80,8 @@ object ZipOpTests extends TestSuite {
zipFile1,
dest = wd / "zipByExcludingCertainFiles"
)
val paths = os.walk(outputZipFilePath).toList.sorted
val expected =
Seq(wd / "zipByExcludingCertainFiles/File.amx").toList.sorted
val paths = os.walk(outputZipFilePath).sorted
val expected = Seq(wd / "zipByExcludingCertainFiles/File.amx")
assert(paths == expected)
}

Expand All @@ -106,8 +104,8 @@ object ZipOpTests extends TestSuite {
// Unzip file to check for contents
val outputZipFilePath =
os.unzip(zipFile1, dest = wd / "zipByIncludingCertainFiles")
val paths = os.walk(outputZipFilePath).toSeq.sorted
val expected = List(wd / "zipByIncludingCertainFiles" / amxFile).sorted
val paths = os.walk(outputZipFilePath)
val expected = Seq(wd / "zipByIncludingCertainFiles" / amxFile)
assert(paths == expected)
}

Expand All @@ -126,8 +124,8 @@ object ZipOpTests extends TestSuite {
dest = wd / "zipStreamFunction"
)

val paths = os.walk(unzippedFolder).toSeq
assert(paths.sorted == Seq(unzippedFolder / "File.txt").sorted)
val paths = os.walk(unzippedFolder)
assert(paths == Seq(unzippedFolder / "File.txt"))
}

test("list") - prep { wd =>
Expand All @@ -142,10 +140,9 @@ object ZipOpTests extends TestSuite {
)

// Unzip file to a destination folder
val listedContents = os.unzip.list(source = wd / zipFileName).toList.sorted
val listedContents = os.unzip.list(source = wd / zipFileName).toSeq

val expected =
List(os.sub / "File.txt", os.sub / "folder1/one.txt", os.sub / "folder1").sorted
val expected = Seq(os.sub / "File.txt", os.sub / "one.txt")
assert(listedContents == expected)
}

Expand All @@ -170,12 +167,11 @@ object ZipOpTests extends TestSuite {
excludePatterns = Seq(amxFile.r)
)

val paths = os.walk(unzippedFolder).toList.sorted
val expected = List(
val paths = os.walk(unzippedFolder)
val expected = Seq(
wd / "unzipAllExceptExcludingCertainFiles/File.txt",
wd / "unzipAllExceptExcludingCertainFiles/folder1/one.txt",
wd / "unzipAllExceptExcludingCertainFiles/folder1"
).sorted
wd / "unzipAllExceptExcludingCertainFiles/one.txt"
)

assert(paths == expected)
}
Expand Down Expand Up @@ -226,22 +222,5 @@ object ZipOpTests extends TestSuite {
assert(file2Content == "Content of file2")
}

test("emptyFolder") - prep { wd =>
val zipFileName = "zipCheckEmptyDirectory.zip"
val zipFile = os.zip(
dest = wd / zipFileName,
sources = Seq(
wd / "emptyFolder",
wd / "File.txt"
)
)

val unzippedFolder = os.unzip(
source = wd / zipFileName,
dest = wd / "unzipped-empty-directory"
)

assert(os.exists(unzippedFolder / "emptyFolder"))
}
}
}
Loading