File: apt-cacher-format-transition.pl

package info (click to toggle)
apt-cacher 0.9.4sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 268 kB
  • ctags: 224
  • sloc: perl: 1,862; makefile: 495; sh: 37
file content (36 lines) | stat: -rwxr-xr-x 943 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl
die "Please specify the cache directory!\n" if !$ARGV[0];

chdir $ARGV[0] || die "Could not enter the cache directory!";

@info = stat("private");

mkdir "packages";
mkdir "headers";
chown $info[4], $info[5], "packages", "headers";

for $fname (<*.deb>, <*pgp>, <*gz>, <*bz2>, <*Release>) {
   my $data=0;
   my $size=0;
   open(in, $fname);
   open(daten, ">packages/$fname");
   open(header, ">headers/$fname");
   while(<in>) {
      if($data) { print daten $_; next; };
      print header $_;
      $size=$1 if /^Content-Length: (\d+)/;
      $data=1 if /^$/;
   }
   close(daten);
   close(header);
   @statinfo = stat("packages/$fname");
   if($size == $statinfo[7]) {
      chown $info[4], $info[5], "packages/$fname", "headers/$fname";
      utime $statinfo[9], $statinfo[9], "packages/$fname", "headers/$fname";
      unlink $fname;
   }
   else {
      unlink "packages/$fname";
      unlink "headers/$fname";
   }
}