diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-10-17 16:45:04 -0400 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-10-17 16:58:05 -0400 |
commit | 167e36a5c3127da63d120d9fdaf5e046b829f287 (patch) | |
tree | d396fefa5dd8e3d1d35b82722bce385dd734766c /perl/lib/Nix | |
parent | ac238d619c2469ea89b8707ae340d3f19c77eadf (diff) |
nix-push: Only generate and copy a NAR if it doesn't already exist
This prevents unnecessary and slow rebuilds of NARs that already exist
in the binary cache.
Diffstat (limited to 'perl/lib/Nix')
-rw-r--r-- | perl/lib/Nix/Manifest.pm | 40 | ||||
-rw-r--r-- | perl/lib/Nix/Utils.pm | 19 |
2 files changed, 58 insertions, 1 deletions
diff --git a/perl/lib/Nix/Manifest.pm b/perl/lib/Nix/Manifest.pm index 50f7777e4..ed43900b5 100644 --- a/perl/lib/Nix/Manifest.pm +++ b/perl/lib/Nix/Manifest.pm @@ -9,7 +9,7 @@ use Fcntl ':flock'; use Nix::Config; our @ISA = qw(Exporter); -our @EXPORT = qw(readManifest writeManifest updateManifestDB addPatch deleteOldManifests); +our @EXPORT = qw(readManifest writeManifest updateManifestDB addPatch deleteOldManifests parseNARInfo); sub addNAR { @@ -388,4 +388,42 @@ sub deleteOldManifests { } +# Parse a NAR info file. +sub parseNARInfo { + my ($storePath, $content) = @_; + + my ($storePath2, $url, $fileHash, $fileSize, $narHash, $narSize, $deriver, $system); + my $compression = "bzip2"; + my @refs; + + foreach my $line (split "\n", $content) { + return undef unless $line =~ /^(.*): (.*)$/; + if ($1 eq "StorePath") { $storePath2 = $2; } + elsif ($1 eq "URL") { $url = $2; } + elsif ($1 eq "Compression") { $compression = $2; } + elsif ($1 eq "FileHash") { $fileHash = $2; } + elsif ($1 eq "FileSize") { $fileSize = int($2); } + elsif ($1 eq "NarHash") { $narHash = $2; } + elsif ($1 eq "NarSize") { $narSize = int($2); } + elsif ($1 eq "References") { @refs = split / /, $2; } + elsif ($1 eq "Deriver") { $deriver = $2; } + elsif ($1 eq "System") { $system = $2; } + } + + return undef if $storePath ne $storePath2 || !defined $url || !defined $narHash; + + return + { url => $url + , compression => $compression + , fileHash => $fileHash + , fileSize => $fileSize + , narHash => $narHash + , narSize => $narSize + , refs => [ @refs ] + , deriver => $deriver + , system => $system + }; +} + + return 1; diff --git a/perl/lib/Nix/Utils.pm b/perl/lib/Nix/Utils.pm index 1e7e0b5af..bc180e2a5 100644 --- a/perl/lib/Nix/Utils.pm +++ b/perl/lib/Nix/Utils.pm @@ -1,5 +1,8 @@ package Nix::Utils; +our @ISA = qw(Exporter); +our @EXPORT = qw(checkURL uniq writeFile readFile); + $urlRE = "(?: [a-zA-Z][a-zA-Z0-9\+\-\.]*\:[a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~\*]+ )"; sub checkURL { @@ -17,3 +20,19 @@ sub uniq { } return @res; } + +sub writeFile { + my ($fn, $s) = @_; + open TMP, ">$fn" or die; + print TMP "$s" or die; + close TMP or die; +} + +sub readFile { + local $/ = undef; + my ($fn) = @_; + open TMP, "<$fn" or die; + my $s = <TMP>; + close TMP or die; + return $s; +} |