Thursday, January 29, 2009

You can check-out any time you like, but you can never leave (or check-in)

With apologies to The Eagles.

So I was trying to check-in my work to my svn repository when it kept running into files it didn't have permissions for. This frustrated me for quite sometime because apparently there are several such files (and all seem to have a size of 0 bytes / blocksize) and changing each one of those with "chmod 644" got tiresome really quickly. And svn is deceptive that way too because it would just croak and die on that file and not move any forward.

I had run in to this issue earlier, but didn't have the time to look in to what was exactly causing the problem. Finally figured out that because the files were of size zero, apparently tar dropped them there with no permissions what so ever. I kid you not, ls -la on the offending file showed permissions as "-------------"!

so, I whipped up the following perl script to automatically chmod the offending file to correct permissions without disturbing any other files / permissions.


#!/bin/perl
#author: hypothetical25
#created: 2009-01-29
# this is a file to add a given directory to svn without being stuck by permission issues.
# i frequently found that svn add * was getting stuck because it would run in to files that didn't have the correct permissions set on them. Typically these files were extracted from some tar ball
#Copyright: all rights reserved.
#if you want to use this, drop me a line (or leave a comment on this blog)

# run svn
# if output matchs svn: Can't open file '\(.*\)': Permission denied
# chmod 744 $1
use strict;
use warnings;

open FH, "svn add --force * 2>&1 |" or die "can't open svn";
my $error_pattern;
$error_pattern = "svn.*open file \'(.*)\': Permission denied";
while()
{
chomp;
# print "$_\n";
if(/$error_pattern/)
{
print "found an error with file [$1]\n";
system "chmod", "744", $1;
close FH;
open FH, "svn add --force * 2>&1 |" or die "can't open svn";

}
print "read [$_]\n";
}

No comments: