I’m trying to p4 sync, but I got a “Can’t clobber writable file” error. So, I removed the writable permission, but now I get this error:
$ ls -l file.txt
-r--r--r-- 1 myusername admin 1.0K Jan 1 00:00 file.txt
$ p4 sync file.txt
//the/depot/directory/file.txt#5 - deleted as /my/local/workspace/directory/file.txt
unlink: /my/local/workspace/directory/file.txt: Permission denied
I am logged in as myusername. Why am I getting permission denied?
Because you just took away your own write permission. That means you no longer have permission to write to the file. Which means p4, acting on your behalf, no longer has permission to write to the file. Which means that when p4, acting on your behalf, asks for permission to write to the file, it’s denied. Which means p4 says “Permission denied”.
What else did you expect to happen?
The reason
p4 syncis complaining is that you appear to have a file that you’ve checked out (and therefore possibly made changes to) and it doesn’t know about it, so it refuses to just overwrite your hard work. You should manually revert the file, if that’s what you want to do.Perforce keeps track of what state it expects your files to be in. If it left a file with non-writable access, and expects it to still be in that state, it will attempt to chmod it before overwriting it. But if it thinks the file should be writable, it will just open it and try to write it. The fact that a chmod would succeed is irrelevant if p4 never calls it.
At any rate, the solution is to explicitly revert the file, delete it and re-pull it, etc.