I'm trying to copy the access permissions of a source directory to a destination directory. The Finder Info panel of the source directory shows the following permissions:
- Source directory:
- I: Read & write
- Everyone: No access
- Destination directory:
- I: Read & write
- Staff: Read only
- Everyone: Read only
The following code succeeds in creating a file in the destination directory, but then fails when setting the URL.fileSecurityKey
resource:
let openPanel = NSOpenPanel()
openPanel.canChooseDirectories = true
openPanel.canChooseFiles = false
openPanel.runModal()
let source = openPanel.urls[0]
openPanel.runModal()
var destination = openPanel.urls[0]
do {
try Data().write(to: destination.appendingPathComponent("asd"))
try destination.setResourceValues(source.resourceValues(forKeys: [.fileSecurityKey]))
} catch {
fatalError(error.localizedDescription)
}
The error message is:
You don’t have permission to save the file “destination” in the folder “parent”
I thought that an app run by a user has the same permissions as the user itself, and since I have read & write access to both the source and destination directories, the app should be able to copy the access permissions without issues. What is the problem?