Skip to content

Commit

Permalink
Custom permissions on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Sep 8, 2024
1 parent 725fc95 commit 0ebf430
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Sources/Zip/Zip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public class Zip {
}

var isDirectory = false
let fileInfoSizeFileName = Int(fileInfo.size_filename-1)
let fileInfoSizeFileName = Int(fileInfo.size_filename - 1)
if (fileName[fileInfoSizeFileName] == "/".cString(using: String.Encoding.utf8)?.first || fileName[fileInfoSizeFileName] == "\\".cString(using: String.Encoding.utf8)?.first) {
isDirectory = true
}
Expand All @@ -121,7 +121,7 @@ public class Zip {

let creationDate = Date()
let directoryAttributes: [FileAttributeKey: Any]?
#if os(Linux) && swift(<6.0)
#if (os(Linux) || os(Windows)) && swift(<6.0)
// On Linux, setting attributes is not yet really implemented.
// In Swift 4.2, the only settable attribute is `.posixPermissions`.
// See https://github.com/apple/swift-corelibs-foundation/blob/swift-4.2-branch/Foundation/FileManager.swift#L182-L196
Expand Down Expand Up @@ -170,10 +170,15 @@ public class Zip {
// Set file permissions from current `fileInfo`
if fileInfo.external_fa != 0 {
let permissions = (fileInfo.external_fa >> 16) & 0x1FF
// We will devifne a valid permission range between Owner read only to full access
// We will define a valid permission range between Owner read only to full access
if permissions >= 0o400 && permissions <= 0o777 {
do {
// TODO: Set permissions properly on Windows
#if os(Windows)
try fileManager.setAttributes([.posixPermissions : 0o666], ofItemAtPath: fullPath)
#else
try fileManager.setAttributes([.posixPermissions : permissions], ofItemAtPath: fullPath)
#endif
} catch {
print("Failed to set permissions to file \(fullPath), error: \(error)")
}
Expand Down

0 comments on commit 0ebf430

Please sign in to comment.