SVN Working Copy xxx locked and cleanup failed

less than 1 minute read

This thing drives me insane every time . It almost always happens in the middle of a mega-update, and usually the only solution is to delete everything and re-checkout. When it’s 4G , it gets *really* annoying.

Apparently , the main reason for this is that some”lock” files are left inside the”.svn” folders , and the svn client refuses to clean them up (what’s the point of the”cleanup” function , anyway , if it won’t clean unnecessary locks?!)

So I wrote this little Perl script to delete all the”lock” files from all the subdirectories in the project. It’s quick , it’s dirty as hell , and it will kill anything on its way - a perfect reflection of my mood!

You might also find the StackOverflow question about it useful (I sure did)

use strict;
use warnings;
use Cwd;

use File::Find;

my ($dir) = @ARGV;

find( \&wanted, $dir );

sub wanted {
    return unless -f;  
    return unless /^lock$/;
    printf cwd()."/$_\n" ;    
    unlink $_ or warn "deleting".cwd()."/'$_ failed: $!\n";
    return;
}