Skip to content

Commit

Permalink
Try removing permission on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Sep 10, 2024
1 parent 9113f27 commit dee3cec
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 24 deletions.
26 changes: 3 additions & 23 deletions Sources/Zip/Zip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

import Foundation
@_implementationOnly import CMinizip
#if os(Windows)
import WinSDK
#endif

/// Main class that handles zipping and unzipping of files.
public class Zip {
Expand Down Expand Up @@ -165,28 +162,11 @@ public class Zip {
throw ZipError.unzipFail
}

// TODO: Set permissions properly on Windows
#if !os(Windows)
// Set file permissions from current `fileInfo`
if fileInfo.external_fa != 0 {
let permissions = (fileInfo.external_fa >> 16) & 0x1FF
// TODO: Set permissions properly on Windows
#if os(Windows)
// Convert POSIX permissions to Windows attributes
var attributes: UInt32 = 0
if permissions & 0o400 != 0 { // Owner read
attributes |= UInt32(FILE_ATTRIBUTE_READONLY)
}
if permissions & 0o200 != 0 { // Owner write
attributes &= ~UInt32(FILE_ATTRIBUTE_READONLY)
}
if permissions & 0o100 != 0 { // Owner execute
// Windows does not have a direct equivalent for execute permissions
// You might need to handle this separately if required
}
// Set the file attributes on Windows
if !SetFileAttributesW(fullPath.utf16.map { WCHAR($0) } + [0], attributes) {
print("Failed to set permissions to file \(fullPath), error: \(GetLastError())")
}
#else
// We will define a valid permission range between Owner read only to full access
if permissions >= 0o400 && permissions <= 0o777 {
do {
Expand All @@ -195,8 +175,8 @@ public class Zip {
print("Failed to set permissions to file \(fullPath), error: \(error)")
}
}
#endif
}
#endif

ret = unzGoToNextFile(zip)

Expand Down
1 change: 0 additions & 1 deletion Tests/ZipTests/ZipTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ final class ZipTests: XCTestCase {
}

// Tests if https://github.com/vapor-community/Zip/issues/4 does not occur anymore.
// TODO: Fix on Windows
func testRoundTripping() throws {
// "prod-apple-swift-metrics-main-e6a00d36.zip" is the original zip file from the issue.
let zipFilePath = url(forResource: "prod-apple-swift-metrics-main-e6a00d36", withExtension: "zip")!
Expand Down

0 comments on commit dee3cec

Please sign in to comment.