Error when trying to set access permissions of file owned by user

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?

The Finder Info panel of the source directory shows the following permissions

As I mentioned on your other thread, it’s best to test this stuff with BSD-level APIs. It’s hard to say how the Finder permissions you’ve described translate to BSD permissions. What does ls -l show for each of these directories?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Error when trying to set access permissions of file owned by user
 
 
Q