From 7a440fb095d578c94ada33a6fef4e19145f422cf Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Mon, 20 Jun 2016 09:06:17 +0200 Subject: [PATCH] pdist: style: fix whitespace issues --- pdist/pdist | 98 +++++++++++++++++++---------------------------------- 1 file changed, 34 insertions(+), 64 deletions(-) diff --git a/pdist/pdist b/pdist/pdist index d39104d..9b9fade 100755 --- a/pdist/pdist +++ b/pdist/pdist @@ -15,7 +15,7 @@ our @EXPORT=qw(fn_escape fn_unescape); # # My::FileInfo helper class. -# +# # sub fn_escape { @@ -57,7 +57,6 @@ use Fcntl ':mode'; # P path perm uid gid - - hardlink # S path perm uid gid - - hardlink - sub name_escaped { my ($self)=shift; @@ -82,7 +81,7 @@ sub export_index $self->uid, $self->gid, ( - $type eq 'F' ? $self->size : + $type eq 'F' ? $self->size : $type eq 'L' ? fn_escape($self->target) : $type eq 'B' || $type eq 'C' ? $self->rdev : '-' @@ -107,7 +106,7 @@ sub import_index ($type eq 'F' ? $F[5] : 0 ), # size ($type eq 'F'||$type eq 'D' ? $F[6] : 0 ), # mtime ($type eq 'L' ? fn_unescape($F[5]) : ''), # target - + ], $class; } @@ -188,7 +187,6 @@ use constant DISTFILE => '/root/Distfile', # read FILES,HOSTS,EXCEPTS here }; - our $PID=$$; our $TMPDIR='/tmp/pdist.'.$$; our $TMPUPDDIR='/tmp/pdist.'.$$.'/upd'; @@ -251,7 +249,7 @@ sub cache_local_fs my ($fs,$path,$type)=($1,$2,$3); next unless $type && $type =~ /^advfs|ufs|ext\d+|reiserfs|xfs|fuseblk|vfat|efs$/; my @F = lstat($path) or die "$path: $!\n"; - $LOCAL_DEV{$F[0]}=$path; + $LOCAL_DEV{$F[0]}=$path; } } @@ -263,13 +261,12 @@ sub read_distfile open IN,"<$filename" or die "$filename: $!\n"; my $distfile=(join '',); $distfile=~s/#.*//g; - + while ($distfile =~ /(\S+) ?= ?\(([^)]*)\)/g) { $DIST{$1} = [split (' ',$2)]; } - # for (keys %DIST) { print "$_ : ",join(' ',@{$DIST{$_}}),"\n"; } # sanity check; @@ -329,7 +326,7 @@ chomp($machine=`uname -m`); if ($machine eq 'i686') { $SYS_lchown=198; # __NR_lchown32 in /usr/include/asm/unistd.h - $SYS_mknod=14; # __NR_mknod + $SYS_mknod=14; # __NR_mknod } elsif ($machine eq 'x86_64') { @@ -448,7 +445,6 @@ sub fileop_mv rename($from,$to) or die "$from: $!\n"; } - sub fileop_rm { my ($path)=@_; @@ -465,7 +461,6 @@ sub fileop_rmdir_recurse system 'rm','-rf',$path and exit 1; } - sub fileop_symlink { my ($from,$to)=@_; @@ -501,7 +496,7 @@ sub index_wanted } my $st=My::FileInfo->lstat($_) or die "$_ : $!\n"; - + if ( !exists $LOCAL_DEV{$st->dev} && !($st->dev == -1 && $st->type eq 'P')) # osf bug: pipes show -1 as dev { warn "$_ : remote filesystem\n"; @@ -509,7 +504,6 @@ sub index_wanted return; } - my $save_fn=fn_escape($_); my $hardlink='-'; @@ -528,13 +522,12 @@ sub index_wanted print $st->export_index,$hardlink; } - sub prog_index { cache_local_fs(); # start index with list of excepts - + local($, , $\)=(' ',"\n"); for (@EXCEPTS) @@ -542,7 +535,6 @@ sub prog_index print '!',fn_escape($_); } - @files and @FILES=@files; # override via --files find @@ -558,8 +550,6 @@ sub prog_index print '%','complete'; # end tag, because truncated indices can be quite destructive } - - sub prog_pack { my $errors=0; @@ -574,7 +564,7 @@ sub prog_pack while () { my ($tag,$save_fn,$size,$mtime)=split; - $tag eq '+' or die "$0 invalid input record $_\n"; + $tag eq '+' or die "$0 invalid input record $_\n"; my $fn=fn_unescape($save_fn); my @S; @@ -586,13 +576,13 @@ sub prog_pack unless (S_ISREG($S[2]) && $S[7]==$size && $S[9]==$mtime) { warn "$fn: requested files has changed\n"; - } + } $fn=~s"^/+""; print TAR $fn,"\n"; } unless (close TAR) { - $! and die "$0: $!\n"; + $! and die "$0: $!\n"; exit 1; # child exit status. diagnostics should already be out. }; } @@ -651,7 +641,7 @@ sub out_of_the_way my ($st)=@_; $st->type eq '-' and return; - + if ($st->type eq 'D') { my $path=$st->name; @@ -673,13 +663,10 @@ use constant F_UPDATE=>2, }; - sub prog_update { my ($function,$index1,$tarfile)=@_; - - # # (F_REQUEST,index-filename) # (F_UPDATE, index-filename,undef) @@ -708,7 +695,6 @@ sub prog_update system 'tar','--extract',,'--directory',$TMPUPDDIR,'--file',$tarfile and exit 1; } - open INDEX,"<$index1" or die "$index1: $!\n"; while () { @@ -763,7 +749,7 @@ sub prog_update my $hardlink=fn_unescape($F[7]); my $tmp_filename=$TMPUPDDIR.$filename; - + if ($hardlink ne '-') { my $st_src=My::FileInfo->lstat($hardlink); @@ -855,14 +841,14 @@ sub prog_update { check_perm($st_is,$st_want); } - } + } else { die "type ".$st_want->type." not yet implemented\n"; } - } + } } - defined $_ or die "$index1 : truncated\n"; # emergency exit + defined $_ or die "$index1 : truncated\n"; # emergency exit if ($function==F_UPDATE) { @@ -895,7 +881,6 @@ sub prog_update } } - for (my $i=0;$i<@DIR_MTIME_QUEUE;$i+=2) { my ($fn,$mtime)=($DIR_MTIME_QUEUE[$i],$DIR_MTIME_QUEUE[$i+1]); @@ -912,11 +897,10 @@ sub prog_update else { warn "$fn: $!\n"; - } + } } } - if ($function==F_REQUEST) { $verbose and warn sprintf "requesting %d files %5.2f MB\n",$requested_files,$requested_bytes/1024/1024; @@ -928,7 +912,6 @@ sub prog_update } } - sub prog_client { my ($master,$port)=@_; @@ -949,12 +932,12 @@ sub prog_client $tmp_free=$F[3]; close P; } - + my $master_index=$TMPDIR."/snapshot.$master"; my $tmpfile="$master_index.tmp"; $verbose and warn "$hostname receiving index from $master\n"; - + open OUT,">$tmpfile" or die "$tmpfile: $!\n"; while () {print OUT} close OUT; @@ -977,7 +960,6 @@ sub prog_client die sprintf ("%s: insufficient disk space (%dk needed, %dk free)\n",$TMPDIR,$req_bytes/1024*1.2,$tmp_free); } - if ($req_files) { my $s; @@ -994,7 +976,7 @@ sub prog_client } $verbose and warn "$hostname: connected to $master\n"; - defined (my $copy_pid=fork) or die "$0: $!\n"; + defined (my $copy_pid=fork) or die "$0: $!\n"; unless ($copy_pid) { $0="pdist [receiving tar from $master]"; @@ -1013,7 +995,7 @@ sub prog_client open STDIN,'<&',$s or die "$!"; $verbose and warn "$hostname: about to exec tar --extract\n"; exec 'tar','--extract','--directory',$TMPUPDDIR,'--file','-'; - die "tar: $!\n"; + die "tar: $!\n"; } $verbose and warn "$hostname sending request to $master\n"; open IN,"<$requestfile" or die "$requestfile: $!\n"; @@ -1037,11 +1019,10 @@ sub prog_client } $verbose and warn "$hostname installation done. cleaning up\n"; - + unlink ($master_index); unlink ($requestfile); - if ($post_command) { $verbose and warn "$hostname: executing $post_command\n"; @@ -1051,15 +1032,13 @@ sub prog_client } #-------------------------------------------- - - sub set_prefix { my ($client)=@_; $SIG{__WARN__} = sub { warn sprintf "%-30s: %s",$client,$_[0] }; $SIG{__DIE__} = sub { die sprintf "%-30s: %s",$client,$_[0] }; } - + sub fork_pack_daemon { my ($client)=@_; # client name @@ -1079,7 +1058,7 @@ sub fork_pack_daemon $s_listen=new IO::Socket::INET (Listen=>1) or die "$0: $!\n"; } $server_port=$s_listen->sockport; - + defined ($server_pid=fork) or die "$0: $!\n"; unless ($server_pid) { @@ -1104,7 +1083,7 @@ sub fork_pack_daemon # open STDOUT,'>','/dev/null' or die "$!\n"; # $0="pdist [listening for $client]"; } - exit # notreached + exit # notreached } return ($server_port); } @@ -1122,7 +1101,7 @@ sub push_single unless ($pid) { my @remote_opts; - + $verbose and push @remote_opts,'--verbose'; $quiet and push @remote_opts,'--quiet'; $fileop_noop and push @remote_opts,'--noop'; @@ -1133,7 +1112,6 @@ sub push_single $parallel && $parallel>1 and push @remote_opts,'--msg-prefix',$client; - my @l= ( 'ssh','-l','root', @@ -1164,7 +1142,7 @@ sub push_single defined $timeout and alarm($timeout); unless (close OUT) { - $! and die "$0: $!\n"; + $! and die "$0: $!\n"; exit 1; # child exit status. diagnostics should already be out. }; alarm(0); @@ -1175,13 +1153,12 @@ sub push_single sub client_expand { my (@spec)=@_; # host host @group host @group - - our (%NG,$ng_init); + our (%NG,$ng_init); my @ret; my %did; - + while (my $spec=shift @spec) { next if $did{$spec}; @@ -1243,7 +1220,6 @@ sub prog_push select($old); close SNAPSHOT; - if (@_==1 && @client_list==1) { push_single($client_list[0],$tmpfile); @@ -1302,13 +1278,10 @@ sub prog_push #-------------------------------------------- - - use constant USAGE => <<"__EOF__"; usage: $0 cmd [options] - # low level index # create file index on stdout @@ -1317,7 +1290,6 @@ usage: $0 cmd [options] update want-indexfile [tarfile] # update to want-indexfile using tar client master-name port [--msg-prefix] xxx # client server - # high level push [options] client ... # update client with our snapshot @@ -1325,7 +1297,6 @@ usage: $0 cmd [options] # client : hostname \@netgroup or ALL # ALL expands to HOSTS from Distfile (plus /root/Distfile.hostconfig if it exists) - # [common-options] --noop # do not execute file operations @@ -1365,11 +1336,11 @@ __EOF__ use constant OPTIONS => ( 'noop' => \$fileop_noop, - 'quiet' => \$quiet, - 'timeout=i' => \$timeout, + 'quiet' => \$quiet, + 'timeout=i' => \$timeout, 'fileop_noop' => sub { warn "warning: --fileop_noop deprecated. using --noop\n"; $fileop_noop=1;}, - + 'fileop_debug' => \$fileop_debug, 'delete!' => \$delete, @@ -1383,13 +1354,12 @@ use constant OPTIONS => 'post-command=s' => \$post_command, 'parallel=i' => \$parallel, 'prompt' => \$prompt, - + 'msg-prefix=s' => \$msg_prefix, ); GetOptions(OPTIONS) or die USAGE; - my $cmd=shift; defined $cmd or die USAGE; @@ -1428,7 +1398,7 @@ elsif ($cmd eq 'push') } elsif ($cmd eq 'devel') { - @ARGV==2 or die USAGE; + @ARGV==2 or die USAGE; fileop_cp(@ARGV); } else