objview: Working and tested under LINUX and Vista.
#!/usr/bin/perl
#
# Find scene dependencies in this directory
#
# This a re-write of Greg's raddepend.csh.
# Scene dependencies are now parsed recursively with the fs tree.
#
# This (like the old CSH script) relies on the file's atime and
# will not work if the partition is mounted with the noatime option,
# or if the file system does not store the files' access time.
#
# not-a-bug: https://bugs.launchpad.net/ubuntu/+bug/490500
# LINUX file systems are now defaulting to relative atime (relatime) which
# updates the atime only if the previous atime update is older than
# the mtime or ctime update.
# This effectively renders this script (as well as the old raddepend.csh)
# useless on a LINUX system, unless the fs is mounted with strictatime:
# $ sudo mount -o remount,strictatime /home
#
# Axel, Oct 2010
use strict;
use warnings;
use File::Find qw/ find /;
use File::Basename;
# Use path from the first scene file.
#TODO: Use all args, not just first one.
die("$0: Need at least one scene file.\n") unless ($#ARGV >= 0);
my (undef, $dir, undef) = fileparse($ARGV[0]);
#TODO: Make this a new -t option
#system("touch -m `find . -type f`");
#sleep (2);
# Get atimes of all files in this dir and all subdirs.
system("sync");
my %atimes0; # atimes before genbbox command
my %atimes1; # atimes after genbbox command
find(sub {$atimes0{$File::Find::name} = (stat())[8] if -f;}, $dir);
my $cmd = 'getbbox -w ' . join(' ', @ARGV) . ' >/dev/null';
my $exstat = system("$cmd");
# Use exit status of genbbox command
exit $exstat unless ($exstat == 0);
system("sync");
sleep(1); # atime resolution is 1 second.
# Compare the atimes before and after genbbox was run
find(sub {$atimes1{$File::Find::name} = (stat())[8] if -f;}, $dir);
my @touched = ();
while(my ($key, $value) = each(%atimes0)) {
push(@touched, $key) if ($value < $atimes1{$key});
}
# @touched should contain at least the file(s) we were called with.
# Exit with error if @touched is empty.
die("$0: Could not determine scene dependencies.\n") unless ($#touched > 0);
#TODO: Print hint with strictatime mount option
foreach my $file (@touched) {
# Remove all ARGV files from @touched list to ensure output is
# identical to that of the old raddepend.csh script
print "$file\n" unless grep($_ eq $file, @ARGV);
}
#EOF