diff -uNr a/v.pl b/v.pl --- a/v.pl 2018-01-03 03:03:56.806515090 +0000 +++ b/v.pl 2018-01-11 07:14:32.394753755 +0000 @@ -1,6 +1,6 @@ #!/usr/bin/perl -# (C) 2014 - 2017 The Bitcoin Foundation. You do not have, nor can you ever +# (C) 2014 - 2018 The Bitcoin Foundation. You do not have, nor can you ever # acquire the right to use, copy or distribute this software ; Should you use # this software for any purpose, or copy and distribute it to anyone or in any # manner, you are breaking the laws of whatever soi-disant jurisdiction, and @@ -10,24 +10,38 @@ use strict; -my $version = "99994 K "; +my $version = "99993 K "; -my $tdir = get_homedir() . "/.gnupgtmp"; +my $tdir = ""; my $graph; my %wot = (); my %map = (); my %tmp_map = (); my %banners = (); +my %ante_map = (); my %desc_map = (); my %vp_map = (); my ($pdir, $sdir, $wdir) = ""; my (@pfiles, @sfiles, @wfiles) = (); -sub get_homedir { - my $home = `echo \$HOME`; chomp($home); - return $home; +my @dep_bins = ("cat", "echo", "gpg", "ls", "mkdir", "patch", "pwd", "rm", + "sha512sum", "sort", "wget", "which", "mktemp"); + +sub check_required { + foreach my $bin (@dep_bins) { + death("Dependent program not found! : $bin\n") if validator($bin) != 1; + } +} + +sub validator { + my ($bin) = @_; + + my $valid = 0; + my $r = `which $bin 2>&1`; chomp($r); + $valid = 1 if $r !~ /^which: no $bin/; + return $valid; } sub get_pwd { @@ -271,7 +285,28 @@ } @flow = toposort(%desc_map); %map = scrub_map(@flow); - return @flow; + return reverse @flow; +} + +sub calc_press_path { + my ($head) = @_; + traverse_press_path($head); + return toposort(%ante_map); +} + +sub traverse_press_path { + my ($vp) = @_; + + my %ante = antecedents($vp); + + if(%ante) { + $ante_map{$vp} = [ keys %ante ]; + foreach my $a (keys %ante) { + traverse_press_path($a); + } + } else { + $ante_map{$vp} = []; + } } sub scrub_map { @@ -387,7 +422,7 @@ death("Cyclic Graph!\n"); } } - return reverse @flow; + return @flow; } sub press_vpatches { @@ -395,9 +430,10 @@ my @press = @{$p}; my $v = 1 and shift @press if $press[0] =~ /^v$|^verbose$/i; death("HEAD: $press[1] not found in flow\n") if !grep /^$press[1]$/, @flow; - `rm -rf $press[0]` if -d $press[0]; + my @pp = calc_press_path($press[1]); + death("Directory $press[0] already exists! Halting press.\n") if -d $press[0]; `mkdir -p $press[0]`; - foreach my $vp (@flow) { + foreach my $vp (@pp) { if($v) { my @out = `patch -F 0 -E --dir $press[0] -p1 < $pdir/$vp 2>&1`; print "$vp\n"; @@ -553,8 +589,9 @@ } sub make_tmpdir { - my ($dir) = @_; - `mkdir -p $dir && chmod 0700 $dir` if !-d $dir or die "$dir exists! $!"; + if(-d "/tmp") { $tdir = `mktemp -d`; } else { $tdir = `mktemp -d -p .`; } + chomp($tdir); + death("Failed to create tempdir!\n") if $tdir eq ""; } sub death { @@ -694,6 +731,12 @@ foreach(@flow) { print "$_ " . get_signatories($_) . "\n"; } } +sub print_press_path { + my ($head) = @_; + my @pp = calc_press_path($head); + foreach(@pp) { print "$_ " . get_signatories($_) . "\n"; } +} + sub get_version { my $version_text = << "END_VERSION_TEXT"; ################################################################################ @@ -729,6 +772,7 @@ # (l | leafs) # # (f | flow) # # (p | press) ( ) # +# (pp | press-path) () # # (ss | sync-seals) ( ) # # (sv | sync-vpatches) ( ... ) # # (sa | sync-all-vpatches) ( ) # @@ -738,7 +782,7 @@ # (o | origin) () # # (g | graph) ( []) # # (v | version) # -# (h | ? | help) # +# (h | help) # # # END_SHORT_HELP my $l = "########################################" . @@ -753,8 +797,9 @@ # Commands: # # m, mirrors () # # Will attempt to retrieve, cryptographically verify and print entries # -# in this list for usage in other commands. Mirrors command my only be # -# invoked by itself. [See: sync-seals, sync-vpatches, sync-everything] # +# in this list for usage in other commands. Mirrors command may only # +# be invoked by itself. [See: sync-seals, sync-vpatches, # +# sync-everything] # # # # i, init () [( )] # # init should be run as the first command executed with V. init only # @@ -803,6 +848,10 @@ # is supplied immediately after ( p | press ) option. # # See: ( f | flow ) to view the topological ordering. # # # +# pp, press-path () # +# Print the actual path to be pressed, given a found in the # +# flow. # +# # # ss, sync-seals ( ) # # Given required options of and output directory # # will pull all of the available seal files from the given mirror into # @@ -845,7 +894,7 @@ # v, version # # Prints the version message. # # # -# h, ?, help # +# h, help # # Prints this full help message. # # # ################################################################################ @@ -854,11 +903,12 @@ } sub main { + check_required(); + my $cmd; if(@ARGV > 0) { $cmd = shift @ARGV; } else { print "Unknown or missing option!\n"; print short_help("t"); return; } - my $home = get_homedir(); my $pwd = get_pwd(); $wdir = "$pwd/.wot"; $pdir = "$pwd/patches"; @@ -900,7 +950,7 @@ @wfiles = set_files($wdir); build_wot(); - if($cmd =~ /^h$|^help$|^\?$/) { print long_help(); return; } + if($cmd =~ /^h$|^help$/) { print long_help(); return; } if($cmd =~ /^i$|^init$/) { if(@ARGV == 1) { init(@ARGV, $pdir, $sdir); return; @@ -927,6 +977,7 @@ if ($cmd =~ /^r$|^roots$/) { print_roots(); } elsif($cmd =~ /^l$|^leafs$/) { print_leafs(); } elsif($cmd =~ /^f$|^flow$/) { print_flow(@flow); } + elsif($cmd =~ /^pp$|^press-path$/) { print_press_path(@ARGV); } elsif($cmd =~ /^p$|^press$/) { if(@ARGV < 2) { print "$cmd requires two arguments: ( )\n\n"; @@ -964,6 +1015,6 @@ else { print "Unknown option: \"$cmd\"\n"; print short_help("t"); } } -make_tmpdir($tdir); +make_tmpdir(); main(); remove_tmpdir($tdir);