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
4 changes: 3 additions & 1 deletion Sources/ZIPFoundation/FileManager+ZIP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ extension FileManager {

try self.setSymlinkModificationDate(modificationDate, ofItemAtURL: url)
#else
// Bionic and Windows lack a fully equivalent symlink-targeted
// Some platforms lack a fully equivalent symlink-targeted
// `lutimes`; leave this codepath as a no-op there.
return
#endif
Expand All @@ -223,7 +223,9 @@ extension FileManager {
throw POSIXError(errno, path: url.path)
}
}
#endif

#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS) || os(Linux)
func setSymlinkModificationDate(_ modificationDate: Date, ofItemAtURL url: URL) throws {
let fileSystemRepresentation = self.fileSystemRepresentation(withPath: url.path)
var fileStat = stat()
Expand Down
49 changes: 30 additions & 19 deletions Tests/ZIPFoundationTests/ZIPFoundationFileAttributeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,38 @@ extension ZIPFoundationTests {
throws: Entry.EntryError.missingPermissionsAttributeError)
let permissions = NSNumber(value: Int16(0o753))
let tempPath = NSTemporaryDirectory()
var nonExistantURL = URL(fileURLWithPath: tempPath)
nonExistantURL.appendPathComponent("invalid.path")
var nonExistentURL = URL(fileURLWithPath: tempPath)
nonExistentURL.appendPathComponent("invalid.path")
XCTAssertPOSIXError(try fileManager.setAttributes([.posixPermissions: permissions],
ofItemAtURL: nonExistantURL, traverseLink: false),
ofItemAtURL: nonExistentURL, traverseLink: false),
throwsErrorWithCode: .ENOENT)
XCTAssertSwiftError(try fileManager.setAttributes([.posixPermissions: permissions],
ofItemAtURL: assetURL, traverseLink: false),
throws: Entry.EntryError.missingModificationDateAttributeError)
XCTAssertPOSIXError( try fileManager.setAttributes([.posixPermissions: permissions, .modificationDate: Date()],
ofItemAtURL: nonExistantURL, traverseLink: false),
throwsErrorWithCode: .ENOENT)
}

func testSymlinkModificationDateTransferErrorConditions() {
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS) || os(Linux)
let fileManager = FileManager()
var assetURL = self.resourceURL(for: #function, pathExtension: "png")
let tempPath = NSTemporaryDirectory()
var nonExistantURL = URL(fileURLWithPath: tempPath)
nonExistantURL.appendPathComponent("invalid.path")
XCTAssertPOSIXError(try fileManager.setSymlinkModificationDate(Date(), ofItemAtURL: nonExistantURL),
var nonExistentURL = URL(fileURLWithPath: tempPath)
nonExistentURL.appendPathComponent("invalid.path")
let providedPermissions = NSNumber(value: Int16(0o753))
XCTAssertSwiftError(try fileManager.setAttributes([.posixPermissions: providedPermissions],
ofItemAtURL: assetURL, traverseLink: false),
throws: Entry.EntryError.missingModificationDateAttributeError)
XCTAssertPOSIXError(try fileManager.setSymlinkModificationDate(Date(), ofItemAtURL: nonExistentURL),
throwsErrorWithCode: .ENOENT)
XCTAssertPOSIXError(
try fileManager.setAttributes(
[
.posixPermissions: providedPermissions,
.modificationDate: Date()
],
ofItemAtURL: nonExistentURL,
traverseLink: false
),
throwsErrorWithCode: .ENOENT
)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
var resourceValues = URLResourceValues()
resourceValues.isUserImmutable = true
try? assetURL.setResourceValues(resourceValues)
Expand All @@ -85,6 +95,7 @@ extension ZIPFoundationTests {
}
XCTAssertPOSIXError(try fileManager.setSymlinkModificationDate(Date(), ofItemAtURL: assetURL),
throwsErrorWithCode: .EPERM)
#endif
#endif
}

Expand All @@ -104,8 +115,8 @@ extension ZIPFoundationTests {

XCTAssertCocoaError(try FileManager.fileModificationDateTimeForItem(at: nonFileURL),
throwsErrorWithCode: CocoaError.fileReadNoSuchFile)
let nonExistantURL = URL(fileURLWithPath: "/nonexistant")
XCTAssertCocoaError(try FileManager.fileModificationDateTimeForItem(at: nonExistantURL),
let nonExistentURL = URL(fileURLWithPath: "/nonexistant")
XCTAssertCocoaError(try FileManager.fileModificationDateTimeForItem(at: nonExistentURL),
throwsErrorWithCode: CocoaError.fileReadNoSuchFile)
let msDOSDate = Date(timeIntervalSince1970: TimeInterval(Int.min)).fileModificationDate
XCTAssert(msDOSDate == 0)
Expand All @@ -118,14 +129,14 @@ extension ZIPFoundationTests {
}

func testFileSizeHelperMethods() {
let nonExistantURL = URL(fileURLWithPath: "/nonexistant")
XCTAssertCocoaError(try FileManager.fileSizeForItem(at: nonExistantURL),
let nonExistentURL = URL(fileURLWithPath: "/nonexistant")
XCTAssertCocoaError(try FileManager.fileSizeForItem(at: nonExistentURL),
throwsErrorWithCode: CocoaError.fileReadNoSuchFile)
}

func testFileTypeHelperMethods() {
let nonExistantURL = URL(fileURLWithPath: "/nonexistant")
XCTAssertCocoaError(try FileManager.typeForItem(at: nonExistantURL),
let nonExistentURL = URL(fileURLWithPath: "/nonexistant")
XCTAssertCocoaError(try FileManager.typeForItem(at: nonExistentURL),
throwsErrorWithCode: CocoaError.fileReadNoSuchFile)
guard let nonFileURL = URL(string: "https://www.peakstep.com") else {
XCTFail("Failed to create test URL."); return
Expand Down
14 changes: 11 additions & 3 deletions Tests/ZIPFoundationTests/ZIPFoundationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ extension ZIPFoundationTests {
("testFileModificationDate", testFileModificationDate),
("testFileModificationDateHelperMethods", testFileModificationDateHelperMethods),
("testInvalidSymlinkCompressionMethodErrorConditions", testInvalidSymlinkCompressionMethodErrorConditions)
] + zip64Tests + darwinOnlyTests + swift5OnlyTests
] + zip64Tests + darwinOnlyTests + posixOnlyTests + swift5OnlyTests
}

static var zip64Tests: [(String, (ZIPFoundationTests) -> () throws -> Void)] {
Expand Down Expand Up @@ -318,8 +318,16 @@ extension ZIPFoundationTests {
// Fails for Swift < 4.2 on Linux. We can re-enable that when we drop Swift 4.x support
("testZipItemErrorConditions", testZipItemErrorConditions),
// Applying permissions on symlinks is only relevant on Darwin platforms
("testSymlinkPermissionsTransferErrorConditions", testSymlinkPermissionsTransferErrorConditions),
// Applying file modification dates is currently unsupported in corelibs Foundation
("testSymlinkPermissionsTransferErrorConditions", testSymlinkPermissionsTransferErrorConditions)
]
#else
return []
#endif
}

static var posixOnlyTests: [(String, (ZIPFoundationTests) -> () throws -> Void)] {
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS) || os(Linux)
return [
("testSymlinkModificationDateTransferErrorConditions", testSymlinkModificationDateTransferErrorConditions)
]
#else
Expand Down
Loading