Post

Replies

Boosts

Views

Activity

Reply to FileManager.removeItem(atPath:) fails with "You don't have permission to access the file" error when trying to remove non-empty directory on NAS
Thanks for your insights. how long is the deepest file path? Not long. In the video they showed how the removed directory is only 2 levels deep and every filename is 10-20 characters long. Are you able to remove the sub-directory they added? Like I mentioned, with FileManager.removeItem(atPath:) I wasn't able to, but with my custom function below that recursively removes files before the containing folder and I sent to them in a test app today, it worked (and no error alerts were shown). (Note: before macOS 10.15, the code will leave empty sub-directories and try to remove the top-level directory at the end.) func removeFileRecursively(atPath path: String) -> Bool { if case let url = URL(fileURLWithPath: path, isDirectory: false), (try? url.resourceValues(forKeys: [.isDirectoryKey]).isDirectory) == true { var options: FileManager.DirectoryEnumerationOptions = [] if #available(macOS 10.15, *) { options.insert(.includesDirectoriesPostOrder) } guard let enumerator = FileManager.default.enumerator(at: url, includingPropertiesForKeys: [.isDirectoryKey, .isUserImmutableKey], options: options, errorHandler: { url, error in NSAlert(error: error).runModal() return true }) else { return false } while let url = enumerator.nextObject() as? URL { let isDirectory = (try? url.resourceValues(forKeys: [.isDirectoryKey]).isDirectory) == true let shouldRemove = if #available(macOS 10.15, *) { !isDirectory || enumerator.isEnumeratingDirectoryPostOrder } else { !isDirectory } if shouldRemove { do { if try url.resourceValues(forKeys: [.isUserImmutableKey]).isUserImmutable == true { try (url as NSURL).setResourceValues([.isUserImmutableKey: false]) } if #available(macOS 10.15, *) { let result = if isDirectory { rmdir(url.path) } else { unlink(url.path) } if result < 0 { throw NSError(domain: NSPOSIXErrorDomain, code: Int(errno)) } } else { try FileManager.default.removeItem(at: url) } } catch { NSAlert(error: error).runModal() return false } } } } do { try FileManager.default.removeItem(atPath: path) } catch { NSAlert(error: error).runModal() return false } return true }
Topic: App & System Services SubTopic: Core OS Tags:
Jul ’25
Reply to FileManager.removeItem(atPath:) fails with "You don't have permission to access the file" error when trying to remove non-empty directory on NAS
The user sent me a video showing how removing regular files and empty directories works, but removing non-empty directories doesn't work. They even created a new directory, put a file in there and tried to remove the directory: it didn't work, and after moving the contained file away, it worked.
Topic: App & System Services SubTopic: Core OS Tags:
Jul ’25
Reply to FileManager.removeItem(atPath:) fails with "You don't have permission to access the file" error when trying to remove non-empty directory on NAS
Actually, what prompted me to write this post and I forgot to mention is that the user told me that they can remove the folders without errors in the Finder. So I was also wondering if the Finder is using its own recursive folder delete function, and if I should be doing so as well to be safe?
Topic: App & System Services SubTopic: Core OS Tags:
Jul ’25
Reply to How to create file system snapshots with fs_snapshot_create?
You don't want to end up unnecessarily copying to the system volume when you could have cloned by staying "inside" the correct file system. I don't understand. Doesn't URLResourceKey.volumeSupportsFileCloningKey allow me to detect if cloning is supported? on the smb side, I don't think there's currently any way to preserve file clones across the smb copy, even when both sides support cloning I thought you were saying that with the deprecated Carbon API one can clone files, but then I don't understand why file clones are not preserved. Do you mean when copying a folder that contains file clones, those files are copied and not cloned?
Topic: App & System Services SubTopic: Core OS Tags:
Jul ’25
Reply to How to create file system snapshots with fs_snapshot_create?
Thanks. Sure, I just meant that it seems a little "unclean" to have a temporary file on a volume that is not controlled by the OS and could potentially be lying there forever if the volume is disconnected in the middle of the operation. I'm going to be using URLResourceKey.volumeSupportsFileCloningKey to determine if cloning is available and use clonefile in that case, and otherwise use filecopy to copy the file to the system temporary directory and then copy it from there to the actual destination volume. The latter may be a problem if it's a big file for which the system volume has not enough free space, but in that case the user should just disable checksum calculation in my app.
Topic: App & System Services SubTopic: Core OS Tags:
Jun ’25
Reply to Detect and wait until a file has been unzipped to avoid permission errors
I didn't receive some notifications for recent replies to my posts. Were notifications disabled during the WWDC25 week? I'm not sure I understand the difference between "temporary" and "working (with in progress files)". Wouldn't the temporary one be for in progress files too? And do you mean that I shouldn't use the temporary folder in a production app?
Topic: App & System Services SubTopic: Core OS Tags:
Jun ’25
Reply to NSTableView is unresponsive when inside a modal window shown in DispatchQueue.main.async
Thanks for the explanation. So is using perform(_:with:afterDelay:) or Timer.scheduledTimer(withTimeInterval:repeats:block:) the correct way in this case? I thought using DispatchQueue.main.async was the most elegant way, as it's succinct and allows me to call a native Swift method with a native Swift argument, but because of the modal table view unresponsiveness it's out of the question. Timer.scheduledTimer(withTimeInterval:repeats:block:) is less intuitive and a little longer, but works in this case, so it's my best option for now. perform(_:with:afterDelay:) requires the first argument to be a @objc method, which in turn requires its own argument to be representable in Objective C (which I did by inheriting from NSObject, quite an overhead).
Topic: UI Frameworks SubTopic: AppKit Tags:
Jun ’25