about summary refs log tree commit diff
path: root/perl/lib/Nix/Utils.pm
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-10-17T20·45-0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-10-17T20·58-0400
commit167e36a5c3127da63d120d9fdaf5e046b829f287 (patch)
treed396fefa5dd8e3d1d35b82722bce385dd734766c /perl/lib/Nix/Utils.pm
parentac238d619c2469ea89b8707ae340d3f19c77eadf (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/Utils.pm')
-rw-r--r--perl/lib/Nix/Utils.pm19
1 files changed, 19 insertions, 0 deletions
diff --git a/perl/lib/Nix/Utils.pm b/perl/lib/Nix/Utils.pm
index 1e7e0b5afb2f..bc180e2a55b9 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;
+}