1 #!/usr/bin/perl
2 # httpup-repgen2 - generate a repo for httpup
3 # --
4 # Optimized for low CPU load
5 #
6 # Copyright 2003 (c) Johannes Winkelmann, jw@tks6.net
7
8 use strict;
9
10 my $base = @ARGV[0];
11
12 if (! -d $base) {
13 die "No such directory '$base': $!";
14 }
15
16 $_ = $base;
17 s/(.*)\/$/\1/;
18 $base = $_;
19
20
21 ### Parsing old REPO file
22 my %repoPorts = ();
23
24 if (-f "$base/REPO") {
25 # print "Parsing REPO \n";
26 open(IN, "$base/REPO") || die "Can't open repo file: $!";
27 while (<IN>) {
28 s/\n//;
29 my ($t, $md5, $name) = split(/:/);
30 if ($t eq "f") {
31 $repoPorts{$name} = $md5;
32 # print "$name:$repoPorts{$name}\n";
33 }
34 }
35 close(IN);
36 }
37
38 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
39 $atime,$mtime,$ctime,$blksize,$blocks) = stat("$base/REPO");
40 my %resultPorts = ();
41 my $md5count = 0;
42 getFiles($base, "", $mtime);
43
44 open(OUT, ">$base/REPO") || die "Can't open repo file: $!";
45
46 foreach my $key (sort keys %resultPorts) {
47 if ("$resultPorts{$key}" eq "0") {
48 print OUT "d:$key\n";
49 } else {
50 print OUT "f:$resultPorts{$key}:$key\n";
51 }
52 }
53 close(OUT);
54
55 # print ".: Made $md5count md5sum calls :.\n";
56
57
58 sub getFiles() {
59 # TODO: check double slashes
60
61 my $base = $_[0];
62 my $offset = $_[1];
63 my $repoMtime = $_[2];
64 my $dir = "$base/$offset";
65 opendir(DIR, $dir);
66 my @entries = readdir(DIR);
67 foreach my $d (@entries) {
68 next if ($d eq "." || $d eq "..");
69 next if ($d =~ "REPO.*");
70 if (-f "$dir/$d") {
71 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
72 $atime,$mtime,$ctime,$blksize,$blocks) = stat("$dir/$d");
73 # print "$offset$d (".$repoPorts{"xgalaga/.footprint"}.")\n";
74 if (!$repoPorts{"$offset$d"} || $repoMtime < $mtime) {
75
76 my $md5sum = `md5sum $dir/$d|awk '{print \$1}'`;
77 $md5sum =~ s/\n//;
78 $resultPorts{"$offset$d"} = $md5sum;
79 ++$md5count;
80 close(FILE);
81 } else {
82 $resultPorts{"$offset$d"} = $repoPorts{"$offset$d"};
83 }
84 } else {
85 &getFiles($base, "$offset$d/", $repoMtime);
86 $resultPorts{"$offset$d"} = 0;
87 }
88 }
89 closedir(DIR);
90 }
|