bin/raddepend.pl
changeset 8 9ed02f081b72
equal deleted inserted replaced
7:f0aa5e41ede2 8:9ed02f081b72
       
     1 #!/usr/bin/perl
       
     2 #
       
     3 # Find scene dependencies in this directory
       
     4 #
       
     5 # This a re-write of Greg's raddepend.csh.
       
     6 # Scene dependencies are now parsed recursively with the fs tree.
       
     7 #
       
     8 # This (like the old CSH script) relies on the file's atime and
       
     9 # will not work if the partition is mounted with the noatime option,
       
    10 # or if the file system does not store the files' access time.
       
    11 #
       
    12 # not-a-bug: https://bugs.launchpad.net/ubuntu/+bug/490500
       
    13 # LINUX file systems are now defaulting to relative atime (relatime) which
       
    14 # updates the atime only if the previous atime update is older than
       
    15 # the mtime or ctime update.
       
    16 # This effectively renders this script (as well as the old raddepend.csh)
       
    17 # useless on a LINUX system, unless the fs is mounted with strictatime:
       
    18 # $ sudo mount -o remount,strictatime /home
       
    19 #
       
    20 # Axel, Oct 2010
       
    21 
       
    22 use strict;
       
    23 use warnings;
       
    24 
       
    25 use File::Find qw/ find /;
       
    26 use File::Basename;
       
    27 
       
    28 # Use path from the first scene file.
       
    29 #TODO: Use all args, not just first one.
       
    30 die("$0: Need at least one scene file.\n") unless ($#ARGV >= 0);
       
    31 my (undef, $dir, undef) = fileparse($ARGV[0]);
       
    32 
       
    33 #TODO: Make this a new -t option
       
    34 #system("touch -m `find . -type f`");
       
    35 #sleep (2);
       
    36 
       
    37 # Get atimes of all files in this dir and all subdirs.
       
    38 system("sync");
       
    39 my %atimes0;   # atimes before genbbox command
       
    40 my %atimes1;   # atimes after genbbox command
       
    41 find(sub {$atimes0{$File::Find::name} = (stat())[8] if -f;}, $dir);
       
    42 
       
    43 my $cmd = 'getbbox -w ' . join(' ', @ARGV) . ' >/dev/null';
       
    44 my $exstat = system("$cmd");
       
    45 
       
    46 # Use exit status of genbbox command
       
    47 exit $exstat unless ($exstat == 0);
       
    48 
       
    49 system("sync");
       
    50 sleep(1);   # atime resolution is 1 second.
       
    51 
       
    52 # Compare the atimes before and after genbbox was run
       
    53 find(sub {$atimes1{$File::Find::name} = (stat())[8] if -f;}, $dir);
       
    54 my @touched = ();
       
    55 while(my ($key, $value) = each(%atimes0)) {
       
    56 	push(@touched, $key) if ($value < $atimes1{$key});
       
    57 }
       
    58 
       
    59 # @touched should contain at least the file(s) we were called with.
       
    60 # Exit with error if @touched is empty.
       
    61 die("$0: Could not determine scene dependencies.\n") unless ($#touched > 0);
       
    62 #TODO: Print hint with strictatime mount option
       
    63 
       
    64 foreach my $file (@touched) {
       
    65 	# Remove all ARGV files from @touched list to ensure output is
       
    66 	# identical to that of the old raddepend.csh script
       
    67 	print "$file\n" unless grep($_ eq $file, @ARGV);
       
    68 }
       
    69 
       
    70 #EOF