-
Notifications
You must be signed in to change notification settings - Fork 4
/
httpup-repgen2
executable file
·90 lines (75 loc) · 1.98 KB
/
httpup-repgen2
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/perl
# httpup-repgen2 - generate a repo for httpup
# --
# Optimized for low CPU load
#
# Copyright 2003 (c) Johannes Winkelmann, [email protected]
use strict;
my $base = @ARGV[0];
if (! -d $base) {
die "No such directory '$base': $!";
}
$_ = $base;
s/(.*)\/$/\1/;
$base = $_;
### Parsing old REPO file
my %repoPorts = ();
if (-f "$base/REPO") {
# print "Parsing REPO \n";
open(IN, "$base/REPO") || die "Can't open repo file: $!";
while (<IN>) {
s/\n//;
my ($t, $md5, $name) = split(/:/);
if ($t eq "f") {
$repoPorts{$name} = $md5;
# print "$name:$repoPorts{$name}\n";
}
}
close(IN);
}
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = stat("$base/REPO");
my %resultPorts = ();
my $md5count = 0;
getFiles($base, "", $mtime);
open(OUT, ">$base/REPO") || die "Can't open repo file: $!";
foreach my $key (sort keys %resultPorts) {
if ("$resultPorts{$key}" eq "0") {
print OUT "d:$key\n";
} else {
print OUT "f:$resultPorts{$key}:$key\n";
}
}
close(OUT);
# print ".: Made $md5count md5sum calls :.\n";
sub getFiles() {
# TODO: check double slashes
my $base = $_[0];
my $offset = $_[1];
my $repoMtime = $_[2];
my $dir = "$base/$offset";
opendir(DIR, $dir);
my @entries = readdir(DIR);
foreach my $d (@entries) {
next if ($d eq "." || $d eq "..");
next if ($d =~ "REPO.*");
if (-f "$dir/$d") {
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = stat("$dir/$d");
# print "$offset$d (".$repoPorts{"xgalaga/.footprint"}.")\n";
if (!$repoPorts{"$offset$d"} || $repoMtime < $mtime) {
my $md5sum = `md5sum $dir/$d|awk '{print \$1}'`;
$md5sum =~ s/\n//;
$resultPorts{"$offset$d"} = $md5sum;
++$md5count;
close(FILE);
} else {
$resultPorts{"$offset$d"} = $repoPorts{"$offset$d"};
}
} else {
&getFiles($base, "$offset$d/", $repoMtime);
$resultPorts{"$offset$d"} = 0;
}
}
closedir(DIR);
}