Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 87 lines (66 sloc) 2.93 KB
#!/usr/local/bin/perl -w
######################################################################
# Copyright (c) 2012, Yahoo! Inc. All rights reserved.
#
# This program is free software. You may copy or redistribute it under
# the same terms as Perl itself. Please see the LICENSE.Artistic file
# included with this project for the terms of the Artistic License
# under which this project is licensed.
######################################################################
use warnings;
use strict;
use Getopt::Long;
use Chisel::Manifest;
use File::Basename qw();
# take a manifest and build a zsync for every file
our %opt = (
'h|help' => 'Print this message',
'i|in=s' => 'input directory, default .',
'd|directory=s' => 'output directory, default azsync.data (will be inside --in)',
'wipe' => 'forcefully rm -rf the old azsync.data -d arg',
'zsyncmake=s' => 'path to zsyncmake command',
'emit_keys=s@' => 'specific tags to include, '.
'default: $Chisel::Manifest::defaults{emit_keys}',
);
die "RTFS, bad usage" unless GetOptions(\our %o, keys %opt);
$o{i} ||= ".";
$o{d} ||= "azsync.data";
die "-d can't have slashes/nested dir" if $o{d} =~ m!/!;
$o{emit_keys} = $Chisel::Manifest::defaults{emit_keys}
unless $o{emit_keys};
# chdir into --in, everything is relative to it
chdir($o{i}) or die "chdir $o{i}: $!\n";
if( $o{wipe} ) {
system "rm", "-rf", $o{d};
die "can't wipe $o{d}\n" if($?);
system "rm", "-f", "azsync.manifest.json";
die "can't wipe azsync.manifest.json\n" if($?);
}
my $manifest = Chisel::Manifest->new({ emit_keys => $o{emit_keys} });
my $output = $manifest->add_dir(".")->compute_manifest->to_json_lines();
{
open my $fh, ">", "azsync.manifest.json" or die "can't write azsync.manifest.json: $!";
print $fh $output;
close $fh;
}
my $zsyncmake = $o{zsyncmake};
$zsyncmake ||= "/bin/zsyncmake";
mkdir $o{d} or die "can't mkdir $o{d}: $!";
# only generate a .zsync for the first name listed in any set of links
#
for my $mf (@{$manifest->{computed_manifest}}) {
my $first_name = $mf->first_name;
my $relative_path_to_file = $first_name;
$relative_path_to_file = File::Basename::dirname($relative_path_to_file);
$relative_path_to_file = "" if $relative_path_to_file eq ".";
$relative_path_to_file =~ s![^/]+!..!g;
$relative_path_to_file .= "/" if $relative_path_to_file ne "";
$relative_path_to_file = "../" . $relative_path_to_file ; # azsync.data dir
$relative_path_to_file .= "$first_name";
system "mkdir", "-p", File::Basename::dirname("$o{d}/$first_name");
next unless -f $first_name;
unlink "$o{d}/$first_name";
system $zsyncmake, $first_name, "-o", "$o{d}/$first_name", "-u", $relative_path_to_file;
die "can't $zsyncmake $first_name\n" if($?);
die "didn't $zsyncmake $first_name\n" if ! -f "$o{d}/$first_name";
}
Something went wrong with that request. Please try again.