How to Screw Up a Source Tree; Fix Ownership Recursively with for and chown

Language butchery by Mr Rich on  17.5.10 @ 14:57

It's actually pretty easy to screw up your source tree:


  1. Update your source tree.
    $ svn up

  2. Notice that the permissions are set to use your user — and set them to use the Apache user
    $ sudo chown -R [apache user] .

  3. Wait a few weeks, and attempt to update your source tree.
    $ svn up
    foo/.svn/lock': Permission denied


Fortunately, I had a job interview a few months ago where I was asked how to fix a whole fsckload of files. I answered, "...write a script," but the answer they wanted was "use a Bash for loop." So rarely do you learn something useful from a job interview.


The next challenge came in how to fix the myriad of directories — but only those associated with subversion. I started off by attempting svn up and fixing the directories. That got old really fast.


So I started searching. After a few false starts, I came up with the following:


  1. Get a list of subversion directories, write to a file:
    $ find . -path '*/.svn' -type d > files

  2. As superuser, execute a for loop on each file listed in files
    $ for file in `cat files`;do chown -R [proper user] $file; done

  3. As normal user, test: attempt to update source tree
    $ svn up


...And that was all.


(bloody hell!)

Labels: , , ,


 0 comments links to this post

This page is powered by Blogger. Isn't yours?