File: convert.pl

package info (click to toggle)
fnord 1.10-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 324 kB
  • ctags: 167
  • sloc: ansic: 1,894; makefile: 96; sh: 59; perl: 36
file content (40 lines) | stat: -rw-r--r-- 1,035 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl

use Compress::Zlib;

$PWD=`pwd`;
chomp $PWD;
push @dirs,$PWD;

while ($#dirs>=0) {
  my $x=shift @dirs;
  opendir DIR,$x || die "can't chdir to $x\n";
  foreach $i (readdir DIR) {
    next if (substr($i,0,1) eq ".");
    if (-d "$x/$i") {
      push @dirs,"$x/$i";
    } elsif (-f "$x/$i") {
      next if ($i =~ m/\.gz$/);
      my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("$x/$i");
      my $gzmtime=(stat("$x/$i.gz"))[9];
      if (not defined $gzmtime or $gzmtime<$mtime) {
	print "gzipping $x/$i...\n";
	if ($#ARGV<0) {
	  open FILE,"$x/$i" || die "can't open $x/$i\n";
	  my $gz = gzopen("$x/$i.gz","wb")
	    or die "can't open $x/$i.gz: $gzerrno\n";
	  while (<FILE>) {
	    $gz->gzwrite($_)
	      or die "error writing: $gzerrno\n";
	  }
	  $gz->gzclose;
	  close FILE;
	  utime $atime, $mtime, "$x/$i.gz" or die "can't utime $x/$i.gz\n";
	  my $gzsize=(stat("$x/$i.gz"))[7];
	  unlink "$x/$i.gz" if ($gzsize>=$size);
	}
      }
    }
  }
  closedir DIR;
}