Random bad permissions on OSX
I occasionally run into weird permission problems after a restore of files and folders on my machine, I think it has to do with OSX trying to protect me from myself.
Today I needed to fire up my coding environment on my Mac Mini, so I jumped into the folder for the code that I wanted to update using SourceTree, and did (what I thought was going to be) a quick pull, only to get a weird error message.
I figured it was probably something goofy, so I went to the command line, only to get another weird error:
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
Well, I’ve seen that before, and knew that message was probably because I’ve updated the OS a few times since I last coded. Basically it means the XCode command line tools are missing. Fixing that is easy: just run:
xcode-select --install
This fires up the Xcode installer, which will ask you if you want to install Xcode, or just the command line tools. In this case I don’t need Xcode, so I chose the latter.
That took a pretty long time (it was on “about a minute left” for at least 10 minutes), which was a bit worrisome, but not all that unusual.
Going back to the command line, I tried to do my “git pull” only to get another error:
fatal: Unable to write new index file
OK, weird – why can’t it write that. Found a few things online that suggested running “git gc” might fix it, so I tried that, but that just gave me this error:
fatal: failed to write ref-pack file error: failed to run pack-refs
More curious Googling, and finding the suggestion to look at the extended file permissions, so I tried that:
robweaver$ ls -le .git total 264 -rwxrwxrwx+ 1 robweaver staff 50 Sep 19 2015 COMMIT_EDITMSG 0: group:everyone deny delete 1: 4C6F60A2-E302-49BF-A4C9-5EE480973499 allow read,readattr,readextattr,readsecurity 2: user:_spotlight allow read,write,append,readattr,writeattr,readextattr,writeextattr,readsecurity -rwxrwxrwx+ 1 robweaver staff 802 Apr 29 08:38 FETCH_HEAD 0: group:everyone deny delete 1: 4C6F60A2-E302-49BF-A4C9-5EE480973499 allow read,readattr,readextattr,readsecurity 2: user:_spotlight allow read,write,append,readattr,writeattr,readextattr,writeextattr,readsecurity -rwxrwxrwx+ 1 robweaver staff 41 Sep 19 2015 HEAD 0: group:everyone deny delete 1: 4C6F60A2-E302-49BF-A4C9-5EE480973499 allow read,readattr,readextattr,readsecurity 2: user:_spotlight allow read,write,append,readattr,writeattr,readextattr,writeextattr,readsecurity -rwxrwxrwx+ 1 robweaver staff 41 Sep 19 2015 ORIG_HEAD 0: group:everyone deny delete 1: 4C6F60A2-E302-49BF-A4C9-5EE480973499 allow read,readattr,readextattr,readsecurity 2: user:_spotlight allow read,write,append,readattr,writeattr,readextattr,writeextattr,readsecurity drwxrwxrwx+ 2 robweaver staff 68 Jan 14 2014 branches 0: group:everyone deny delete 1: 4C6F60A2-E302-49BF-A4C9-5EE480973499 allow list,search,readattr,readextattr,readsecurity 2: user:_spotlight allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity -rwxrwxrwx+ 1 robweaver staff 496 May 11 2015 config 0: group:everyone deny delete 1: 4C6F60A2-E302-49BF-A4C9-5EE480973499 allow read,readattr,readextattr,readsecurity 2: user:_spotlight allow read,write,append,readattr,writeattr,readextattr,writeextattr,readsecurity -rwxrwxrwx+ 1 robweaver staff 73 Jan 14 2014 description 0: group:everyone deny delete 1: 4C6F60A2-E302-49BF-A4C9-5EE480973499 allow read,readattr,readextattr,readsecurity 2: user:_spotlight allow read,write,append,readattr,writeattr,readextattr,writeextattr,readsecurity drwxrwxrwx+ 4 robweaver staff 136 May 3 2015 hawser 0: group:everyone deny delete 1: 4C6F60A2-E302-49BF-A4C9-5EE480973499 allow list,search,readattr,readextattr,readsecurity 2: user:_spotlight allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity drwxrwxrwx+ 11 robweaver staff 374 Jan 14 2014 hooks 0: group:everyone deny delete 1: 4C6F60A2-E302-49BF-A4C9-5EE480973499 allow list,search,readattr,readextattr,readsecurity 2: user:_spotlight allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity -rwxrwxrwx+ 1 robweaver staff 99575 Sep 25 2015 index 0: group:everyone deny delete 1: 4C6F60A2-E302-49BF-A4C9-5EE480973499 allow read,readattr,readextattr,readsecurity 2: user:_spotlight allow read,write,append,readattr,writeattr,readextattr,writeextattr,readsecurity drwxrwxrwx+ 3 robweaver staff 102 Jan 14 2014 info 0: group:everyone deny delete 1: 4C6F60A2-E302-49BF-A4C9-5EE480973499 allow list,search,readattr,readextattr,readsecurity 2: user:_spotlight allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity drwxrwxrwx+ 4 robweaver staff 136 Jan 14 2014 logs 0: group:everyone deny delete 1: 4C6F60A2-E302-49BF-A4C9-5EE480973499 allow list,search,readattr,readextattr,readsecurity 2: user:_spotlight allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity drwxrwxrwx+ 260 robweaver staff 8840 May 11 2015 objects 0: group:everyone deny delete 1: 4C6F60A2-E302-49BF-A4C9-5EE480973499 allow list,search,readattr,readextattr,readsecurity 2: user:_spotlight allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity -rwxrwxrwx+ 1 robweaver staff 176 Jan 14 2014 packed-refs 0: group:everyone deny delete 1: 4C6F60A2-E302-49BF-A4C9-5EE480973499 allow read,readattr,readextattr,readsecurity 2: user:_spotlight allow read,write,append,readattr,writeattr,readextattr,writeextattr,readsecurity drwxrwxrwx+ 6 robweaver staff 204 May 11 2015 refs 0: group:everyone deny delete 1: 4C6F60A2-E302-49BF-A4C9-5EE480973499 allow list,search,readattr,readextattr,readsecurity 2: user:_spotlight allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity -rwxrwxrwx@ 1 robweaver staff 156 Nov 1 2015 sourcetreeconfig 0: group:everyone deny delete 1: 4C6F60A2-E302-49BF-A4C9-5EE480973499 allow read,readattr,readextattr,readsecurity 2: user:_spotlight allow read,write,append,readattr,writeattr,readextattr,writeextattr,readsecurity
Wait, what’s this “group:everyone deny delete” ? Well, no wonder I can’t run stuff that updates these folders. More Googling and I find the right switch for chmod to clear out the extended permissions:
sudo chmod -R -N .git
Note that I had the two flags reversed the first time and the command told me it couldn’t find a file named “-R”. After running the above, the folder permissions looked more normal:
robweaver$ ls -le .git total 264 -rwxrwxrwx 1 robweaver staff 50 Sep 19 2015 COMMIT_EDITMSG -rwxrwxrwx 1 robweaver staff 802 Apr 29 08:38 FETCH_HEAD -rwxrwxrwx 1 robweaver staff 41 Sep 19 2015 HEAD -rwxrwxrwx 1 robweaver staff 41 Sep 19 2015 ORIG_HEAD drwxrwxrwx 2 robweaver staff 68 Jan 14 2014 branches -rwxrwxrwx 1 robweaver staff 496 May 11 2015 config -rwxrwxrwx 1 robweaver staff 73 Jan 14 2014 description drwxrwxrwx 4 robweaver staff 136 May 3 2015 hawser drwxrwxrwx 11 robweaver staff 374 Jan 14 2014 hooks -rwxrwxrwx 1 robweaver staff 99575 Sep 25 2015 index drwxrwxrwx 3 robweaver staff 102 Jan 14 2014 info drwxrwxrwx 4 robweaver staff 136 Jan 14 2014 logs drwxrwxrwx 260 robweaver staff 8840 May 11 2015 objects -rwxrwxrwx 1 robweaver staff 176 Jan 14 2014 packed-refs drwxrwxrwx 6 robweaver staff 204 May 11 2015 refs -rwxrwxrwx@ 1 robweaver staff 156 Nov 1 2015 sourcetreeconfig
And my commands worked as expected.