From 85c8a2e01e27ac3beeb123f4f0061a95e99a7f4a Mon Sep 17 00:00:00 2001 From: Sam Hanley Date: Sat, 25 Jan 2025 20:22:45 -0500 Subject: [PATCH 1/2] Fix: preserve symlinks in ziparchive --- Sources/Basics/Archiver/ZipArchiver.swift | 2 +- Tests/BasicsTests/Archiver/ZipArchiverTests.swift | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/Basics/Archiver/ZipArchiver.swift b/Sources/Basics/Archiver/ZipArchiver.swift index ed82f14ae10..f43aa7274be 100644 --- a/Sources/Basics/Archiver/ZipArchiver.swift +++ b/Sources/Basics/Archiver/ZipArchiver.swift @@ -120,7 +120,7 @@ public struct ZipArchiver: Archiver, Cancellable { arguments: [ "/bin/sh", "-c", - "cd \(directory.parentDirectory.underlying.pathString) && zip -r \(destinationPath.pathString) \(directory.basename)", + "cd \(directory.parentDirectory.underlying.pathString) && zip -ry \(destinationPath.pathString) \(directory.basename)", ] ) #endif diff --git a/Tests/BasicsTests/Archiver/ZipArchiverTests.swift b/Tests/BasicsTests/Archiver/ZipArchiverTests.swift index c8a5e113f0b..1c330b18c73 100644 --- a/Tests/BasicsTests/Archiver/ZipArchiverTests.swift +++ b/Tests/BasicsTests/Archiver/ZipArchiverTests.swift @@ -119,6 +119,8 @@ final class ZipArchiverTests: XCTestCase { try localFileSystem.writeFileContents(dir2.appending("file3.txt"), string: "Hello World 3!") try localFileSystem.writeFileContents(dir2.appending("file4.txt"), string: "Hello World 4!") + try localFileSystem.createSymbolicLink(rootDir.appending("file2.txt"), pointingAt: dir1.appending("file2.txt"), relative: true) + let archivePath = tmpdir.appending(component: UUID().uuidString + ".zip") try await archiver.compress(directory: rootDir, to: archivePath) XCTAssertFileExists(archivePath) @@ -154,6 +156,12 @@ final class ZipArchiverTests: XCTestCase { try? localFileSystem.readFileContents(extractedDir2.appending("file4.txt")), "Hello World 4!" ) + + XCTAssertTrue(localFileSystem.isSymlink(extractRootDir.appending("file2.txt"))) + XCTAssertEqual( + try? localFileSystem.readFileContents(extractRootDir.appending("file2.txt")), + try? localFileSystem.readFileContents(extractedDir1.appending("file2.txt")) + ) } } } From 0b6507cafd0b72ce5bf37c0404af400b394a0718 Mon Sep 17 00:00:00 2001 From: Sam Hanley Date: Tue, 28 Jan 2025 16:58:12 -0500 Subject: [PATCH 2/2] Move symlink to subdirectories --- Tests/BasicsTests/Archiver/ZipArchiverTests.swift | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Tests/BasicsTests/Archiver/ZipArchiverTests.swift b/Tests/BasicsTests/Archiver/ZipArchiverTests.swift index 1c330b18c73..340935dbade 100644 --- a/Tests/BasicsTests/Archiver/ZipArchiverTests.swift +++ b/Tests/BasicsTests/Archiver/ZipArchiverTests.swift @@ -118,8 +118,7 @@ final class ZipArchiverTests: XCTestCase { try localFileSystem.createDirectory(dir2) try localFileSystem.writeFileContents(dir2.appending("file3.txt"), string: "Hello World 3!") try localFileSystem.writeFileContents(dir2.appending("file4.txt"), string: "Hello World 4!") - - try localFileSystem.createSymbolicLink(rootDir.appending("file2.txt"), pointingAt: dir1.appending("file2.txt"), relative: true) + try localFileSystem.createSymbolicLink(dir2.appending("file5.txt"), pointingAt: dir1.appending("file2.txt"), relative: true) let archivePath = tmpdir.appending(component: UUID().uuidString + ".zip") try await archiver.compress(directory: rootDir, to: archivePath) @@ -157,11 +156,11 @@ final class ZipArchiverTests: XCTestCase { "Hello World 4!" ) - XCTAssertTrue(localFileSystem.isSymlink(extractRootDir.appending("file2.txt"))) - XCTAssertEqual( - try? localFileSystem.readFileContents(extractRootDir.appending("file2.txt")), + XCTAssertTrue(localFileSystem.isSymlink(extractedDir2.appending("file5.txt"))) + XCTAssertEqual( + try? localFileSystem.readFileContents(extractedDir2.appending("file5.txt")), try? localFileSystem.readFileContents(extractedDir1.appending("file2.txt")) ) } } -} +} \ No newline at end of file