Skip to content

Instantly share code, notes, and snippets.

@soh335
Created April 8, 2011 04:15
Show Gist options
  • Save soh335/909271 to your computer and use it in GitHub Desktop.
Save soh335/909271 to your computer and use it in GitHub Desktop.
#!/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