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: