Source

packaging / rpmbuild / SOURCES / dl-generic-0.1.0 / maketree.pl

#!/usr/bin/perl -w
use strict;

my $chkouts;
my $clean = 0;
my @filelist = ( );

$clean = 1 if ( defined($ARGV[0]) && $ARGV[0] eq 'clean' );

unless ( $clean ) {
	if ( defined($ENV{CHECKOUTS}) ) {
		$chkouts = $ENV{CHECKOUTS};
	} else {
		print STDERR 'Warning: CHECKOUTS environment is not set, defaulting to ' . $ENV{HOME} . '/checkouts' . "\n";
		$chkouts = $ENV{HOME} . '/checkouts';
	}

	unless ( length($chkouts) ) {
		printf STDERR "checkouts directory not specified.\n";
		exit 1;
	}
}


foreach my $l ( <STDIN> ) {
	chomp $l;
	push @filelist, $l;
}
@filelist = reverse(@filelist) if ( $clean );

foreach my $l ( @filelist ) {
	my ( $source, $dest ) = split(m/\s+/, $l);
	next if ( index($l, '#') == 0 );

	if ( defined($source) && defined($dest) ) {
		if ( $clean ) {
			unlink($dest);
		} else {
			system('rsync', '--exclude=.svn', '-r', '-a', '-v', '-p', $chkouts . '/' . $source, $dest . '/' . $source);
		}
	} elsif ( $l =~ m/\/$/ ) {
		if ( $clean ) {
			rmdir $l;
		} else {
			mkdir $l;
		}
	} else {
		printf("Ignoring line: %s\n", $l);
	}
}

exit 0;