Post

Replies

Boosts

Views

Activity

Reply to FileManager.copyItem Permission Bug in iOS 18.1.1 with iCloud Shared Folders
You’re absolutely correct that write permissions on the parent directory are required to delete a file, and your example clearly demonstrates this. I’d like to add to the discussion with another perspective on folder permissions and their impact on file operations. If the directory where I’m copying a file has permissions set to 555, it wouldn’t be possible to copy the file into it because write permissions are not allowed. Here’s an example to illustrate: mkdir test chmod 555 test touch test/file.txt When you run this, you’ll encounter the error: touch: test/file.txt: Permission denied This behavior reinforces your point about needing proper permissions on the parent directory to modify or delete files within it. Similarly, copying or creating new files also requires write access. In my case, I’m working with the temporary directory provided by FileManager.default.temporaryDirectory, which has more permissive settings 755. This avoids the issues seen with 555 permissions. I’ll definitely take a closer look at the "On File System Permissions" post that you linked. Thank you for pointing it out and for your detailed explanation!
Topic: App & System Services SubTopic: Core OS Tags:
Dec ’24
Reply to FileManager.copyItem Permission Bug in iOS 18.1.1 with iCloud Shared Folders
After updating to iOS 18.2, the issue I’ve been experiencing remains unresolved. To ensure the issue wasn’t related to the temporary folder permissions, I took the following steps: Created a custom temporary folder inside the app’s existing temporary folder. Used the UIDocumentPickerViewController to import a file and copied it into the newly created custom temporary folder. Unfortunately, this approach did not resolve the problem. Even after successfully copying the file into the custom folder, I am still unable to delete it. You have to understand that when I import a file using the UIDocumentPickerController, I expect the provided API to enable me to successfully copy the returned file into the app sandbox in such a way that I am then able to delete it. This operation appears to work correctly. do { let securityScoped = sourceItemURL.startAccessingSecurityScopedResource() try FileManager.default.copyItem(at: sourceItemURL, to: temporaryItemURL) print("INFO: Source item copied to temporary directory successfully") currentItemURL = temporaryItemURL if securityScoped { sourceItemURL.stopAccessingSecurityScopedResource() } } catch { print("ERROR: Could not copy source item to temporary directory: \(error)") return } Naturally, as the owner of the newly copied file, I also expect to be able to delete it without any issues. However this is not happening, because when I do this: guard let currentItemURL = currentItemURL else { return } do { try FileManager.default.removeItem(at: currentItemURL) self.currentItemURL = nil } catch { errorDeletingItem(error: error as NSError, temporaryItemURL: currentItemURL) return } This is the error I get. ERROR: “IMG_6897.png” couldn’t be removed because you don’t have permission to access it. Error code: 513 Error domain: NSCocoaErrorDomain Error userInfo: ["NSUserStringVariant": <__NSSingleObjectArrayI 0x301efc3c0>( Remove ) , "NSUnderlyingError": Error Domain=NSPOSIXErrorDomain ?> Code=1 "Operation not permitted", "NSFilePath": /private/var/mobile/Containers/Data/Application/EB178B53-1BBA-47FF-9DFD-AA4F0419940C/tmp/MyTemporaryFolder/IMG_6897.png, "NSURL": file:///private/var/mobile/Containers/Data/Application/EB178B53-1BBA-47FF-9DFD-AA4F0419940C/tmp/MyTemporaryFolder/IMG_6897.png] Please show me the correct way to copy a file (which belongs to an iCloud readonly shared folder) opened with the document picker initialized as UIDocumentPickerViewController(forOpeningContentTypes: [.movie, .image], asCopy: false), so that I can subsequently delete it. Giovanni
Topic: App & System Services SubTopic: Core OS Tags:
Dec ’24
Reply to FileManager.copyItem Permission Bug in iOS 18.1.1 with iCloud Shared Folders
Applying this immediately after copying the file resolves the issue: var attributes = try FileManager.default.attributesOfItem(atPath: temporaryItemURL.path) attributes[FileAttributeKey.immutable] = false try FileManager.default.setAttributes(attributes, ofItemAtPath: temporaryItemURL.path) That said, it might be better to preserve the original attributes and only modify them right before deleting the file, as you demonstrated. This approach would also address the issue for files that were copied previously. Thank you for your help, Kevin!
Topic: App & System Services SubTopic: Core OS Tags:
Dec ’24