Ampelofilosofies

homeaboutrss
The mind is like a parachute. If it doesn't open, you're meat.

(Un)locking files in Mac OS X

04 Jun 2007

I stumbled on a feature of Mac OS that probably dates from the days of OS 9 and that has caused me a few problems: file locking. File locking is nothing more than a flag (uchg) set on the file.

Flags are like the MSDOS/Windows attributes. According to man, the following flags are possible:

  • arch set the archived flag (super-user only)
  • opaque set the opaque flag (owner or super-user only)
  • nodump set the nodump flag (owner or super-user only)
  • sappnd set the system append-only flag (super-user only)
  • schg set the system immutable flag (super-user only)
  • sunlnk set the system undeletable flag (super-user only)
  • uappnd set the user append-only flag (owner or super-user only)
  • uchg set the user immutable flag (owner or super-user only)
  • uunlnk set the user undeletable flag (owner or super-user only)

File locking prevents you from doing anything with the file - can’t move it, rename it, change it’s permissions. Nothing whatsoever.

Now that wouldn’t be a big deal if Mac OS X would give you a decent error message but whenever you try to do anything you get a “operation not permitted” error, which for someone used to Unix leads to thinking that the permissions are not correctly set. Well, to be honest, drag and dropping the file to the trash can will produce the correct message (which is how I found out about file locking), but the terminal won’t give you a clue.

Now, why am I bothered about this?

Well, as I described in Using virtualization in software development projects I rely heavily on the use of VMs at work. The Parallels Vm allows me to share my project directories so that I can synchronize my repositories from Windows and from Mac OS X. The problem was that whenever subversion accessed the repository from a Windows VM, Mac OS X would lock the file as the operation happens over a network connection. Trying to update, commit etc. from Mac OS X afterwards leads to subversion failing with the misleading “operation not permitted” error. A real pain in the backside.

The solution is ofcourse to unlock the file. You do it by calling up the Info tab (cmd-I) of the file and uncheking the ‘Locked’ checkbox. A completely impractical and time wasting method when you have a couple hundred files. Back to the terminal then. It would be absurd if there was no way to do it on the command line and over many files - even attrib.exe had a recursive option. As always though, the command line does things faster:

To see any flags set

ls -lo 

To recursively unlock files

chflags -R nouchg [files]