I had a disk crash on my Mac and needed to copy an Xcode project from a Time Machine disk to a new Mac. When trying to open the project I get a popup stating
"MyProjectName Project" is locked for editing and you may not be able to save your changes. Do you want to unlock it?
I then tap the Unlock button. Immediately a new popup states that
The file “myusername.xcuserdatad” could not be unlocked. Unlocking failed for an unknown reason.
When trying several times, it has sometimes complained about the file “UserInterfaceState.xcuserstate”.
I have tried setting the read/write permissions as recommended here: https://stackoverflow.com/a/53720710
I have used a terminal window and checked ownership and permissions for the files.
I have tried deleting the project from Xcode's DerivedData directory.
I have tried deleting the directory "myusername.xcuserdatad", but then it complained that the “project.xcworkspace” could not be unlocked. I tried to remove that entire directory, but then various other error messages of the same kind appeared.
Now, I have run out of ideas.
I'm using Xcode 16.3 on macOS 15.3. (I can add that this is the first project I'm trying to open after installing Xcode on this new Mac, so it could possibly be any general issue with the setup of Xcode.)
Edit: This problem occurs when copying files and directories from a Time Machine disk using the Finder. It should not occur using Apple's Migration Assistant, but that was not an option for me since I, for various reasons, liked to setup my new Mac from scratch.
I found the solution to my own question:
It turned out that this problem was a general problem affecting all files copied from the Time Machine disk from the old Mac. It was impossible to write to any of these files.
Besides the usual unix file permissions system (POSIX) using three octal digits (e.g. chmod 755), I learned that there is also a more fine-grained system based on ACL (Access Control List).
The ACL for a file can be viewed by the -e
option to the ls
command, e.g.:
ls -lde filename
It turned out that all files copied from the Time Machine had the following ACL entry:
0: group:everyone deny write,delete,append,writeattr,writeextattr,chown
This meant that even if it looked like I had write properties for a file, writing was blocked by the ACL.
The solution I used was to delete all ACL entries recursively for all files and subdirectories in my Xcode project by writing the following command on the top directory of the project:
sudo chmod -RN directoryname