Skip to content

Fix setting permission in PbxCP on open #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2025
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
7 changes: 5 additions & 2 deletions Sources/SWBUtil/PbxCp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ fileprivate func copyRegular(_ srcPath: Path, _ srcParentPath: Path, _ dstPath:

func _copyFile(_ srcPath: Path, _ dstPath: Path) throws {
do {
let dstFd = try FileDescriptor.open(FilePath(dstPath.str), .writeOnly, options: [.create, .truncate], permissions: [.ownerReadWrite, .groupRead, .otherRead])
var permissions: FilePermissions = [.ownerRead, .ownerWrite, .groupRead, .groupWrite, .otherRead, .otherWrite]
if try localFS.isExecutable(srcPath) {
permissions.insert([.ownerExecute, .groupExecute, .otherExecute])
}
let dstFd = try FileDescriptor.open(FilePath(dstPath.str), .writeOnly, options: [.create, .truncate], permissions: permissions)
try dstFd.closeAfter {
let srcFd = try FileDescriptor.open(FilePath(srcPath.str), .readOnly)
try srcFd.closeAfter {
Expand All @@ -316,7 +320,6 @@ func _copyFile(_ srcPath: Path, _ dstPath: Path) throws {
} while (bread > bwritten)
}
}
try localFS.setFilePermissions(dstPath, permissions: localFS.getFilePermissions(srcPath))
}
} catch let error as Errno {
throw POSIXError(error.rawValue, context: "copy", srcPath.str, dstPath.str)
Expand Down
6 changes: 3 additions & 3 deletions Tests/SWBTaskExecutionTests/PBXCpTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ fileprivate struct PBXCpTests: CoreBasedTests {
))
let srcPerm = try fs.getFilePermissions(srcfile)
let dstPerm = try fs.getFilePermissions(dst.join(fwkName).join(fName))
#expect(srcPerm == dstPerm)
#expect(dstPerm == 0o755) // files are created with u+rw, g+wr, o+rw (and +x if src is executable) permissions and umask will adjust
}
}
}
Expand All @@ -452,7 +452,7 @@ fileprivate struct PBXCpTests: CoreBasedTests {
size += try fd.writeAll(buffer1)
}
}
try fs.setFilePermissions(sName, permissions: 0o777)
try fs.setFilePermissions(sName, permissions: 0o600)

do {
let result = await pbxcp(["builtin-copy", "-V", src.str + Path.pathSeparatorString, dst.str], cwd: Path("/"))
Expand All @@ -463,7 +463,7 @@ fileprivate struct PBXCpTests: CoreBasedTests {
// Check permssions
let srcPerm = try fs.getFilePermissions(sName)
let dstPerm = try fs.getFilePermissions(dName)
#expect(srcPerm == dstPerm)
#expect(dstPerm == 0o644) // files are created with u+rw, g+wr, o+rw (and +x if src is executable) permissions and umask will adjust
#expect(FileManager.default.contentsEqual(atPath: sName.str, andPath: dName.str))
}
}
Expand Down