From 56131a2709d76a1e52bada83a083bd2cfee2f716 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 24 Jul 2014 12:24:25 +0200 Subject: Refactor --- perl/lib/Nix/CopyClosure.pm | 8 +------- perl/lib/Nix/SSH.pm | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 8 deletions(-) (limited to 'perl') diff --git a/perl/lib/Nix/CopyClosure.pm b/perl/lib/Nix/CopyClosure.pm index f701a7c8a0d5..061a15c071cf 100644 --- a/perl/lib/Nix/CopyClosure.pm +++ b/perl/lib/Nix/CopyClosure.pm @@ -27,13 +27,7 @@ sub copyToOpen { # Get back the set of paths that are already valid on the remote host. my %present; - my $n = readInt($from); - while ($n--) { - my $len = readInt($from); - my $s = readN($len, $from); - $present{$s} = 1; - readN(8 - $len % 8, $from) if $len % 8; # skip padding - } + $present{$_} = 1 foreach readStrings($from); my @missing = grep { !$present{$_} } @closure; return if !@missing; diff --git a/perl/lib/Nix/SSH.pm b/perl/lib/Nix/SSH.pm index 3bcbabe981d6..dd3e5cefd8c7 100644 --- a/perl/lib/Nix/SSH.pm +++ b/perl/lib/Nix/SSH.pm @@ -7,7 +7,8 @@ use IPC::Open2; our @ISA = qw(Exporter); our @EXPORT = qw( sshOpts openSSHConnection closeSSHConnection - readN readInt writeInt writeString writeStrings + readN readInt readString readStrings + writeInt writeString writeStrings connectToRemoteNix ); @@ -83,6 +84,24 @@ sub readInt { } +sub readString { + my ($from) = @_; + my $len = readInt($from); + my $s = readN($len, $from); + readN(8 - $len % 8, $from) if $len % 8; # skip padding + return $s; +} + + +sub readStrings { + my ($from) = @_; + my $n = readInt($from); + my @res; + push @res, readString($from) while $n--; + return @res; +} + + sub writeInt { my ($n, $to) = @_; syswrite($to, pack("L