aboutsummaryrefslogtreecommitdiff
path: root/scripts/update-manifest.pl
blob: ac0ce749d9abde6efe102cf129a6c30270fec2e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/perl -w -I.

use strict;
use readmanifest;

die unless scalar @ARGV == 2;

my $cache = $ARGV[0];
my $manifest = $ARGV[1];
my %narFiles;
my %localPaths;
my %patches;

readManifest $manifest, \%narFiles, \%localPaths, \%patches;

foreach my $storePath (keys %narFiles) {
    my $narFileList = $narFiles{$storePath};

    foreach my $narFile (@{$narFileList}) {
        if (!defined $narFile->{size} or
            !defined $narFile->{narHash})
        {
            $narFile->{url} =~ /\/([^\/]+)$/;
            die unless defined $1;
            my $fn = "$cache/$1";
            
            my @info = stat $fn or die;
            $narFile->{size} = $info[7];

            my $narHash;
            my $hashFile = "$fn.NARHASH";
            if (-e $hashFile) {
                open HASH, "<$hashFile" or die;
                $narHash = <HASH>;
                close HASH;
            } else {
                print "$fn\n";
                $narHash = `bunzip2 < '$fn' | nix-hash --flat /dev/stdin` or die;
                open HASH, ">$hashFile" or die;
                print HASH $narHash;
                close HASH;
            }
            chomp $narHash;
            $narFile->{narHash} = $narHash;
        }
    }
}

if (! -e "$manifest.backup") {
    system "mv --reply=no '$manifest' '$manifest.backup'";
}

writeManifest $manifest, \%narFiles, \%patches;