Created
April 8, 2011 04:15
-
-
Save soh335/909271 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use File::Temp qw/tempdir/; | |
use File::Copy; | |
use File::Basename; | |
my $svn_path = shift @ARGV or die "need svn path"; | |
my $output_path = shift @ARGV or die "need output filename"; | |
my ( $output_filename, $output_directory, $extension ) = fileparse( $output_path, qw/.zip .tar/); | |
die "output_filename's extension should be zip or tar" unless $extension; | |
die "not exists directory($output_directory)" unless -d $output_directory; | |
my %args = $ENV{TMPDIR} ? ( DIR => $ENV{TMPDIR} ) : (); | |
my $tmp_dir = tempdir( %args, CLEANUP => 1 ); | |
my $tmp_archive_path = "$tmp_dir/$output_filename$extension"; | |
my $svn_export_path = "$tmp_dir/$output_filename"; | |
system("svn export $svn_path $svn_export_path") == 0 or die $!; | |
if ( $extension eq '.zip' ) { | |
system("zip -r $tmp_archive_path $svn_export_path") == 0 or die $!; | |
} | |
elsif ( $extension eq '.tar' ) { | |
system("tar -cvf $tmp_archive_path $svn_export_path") == 0 or die $!; | |
} | |
move( $tmp_archive_path, $output_path) or die $!; | |
print "create $output_path\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment