5
# This script simply traverses a directory structure and
6
# creates a file named .growfsdir that lists all the files
7
# in the directory structure recursively.
8
# The Parrot growfs module uses this information in order to
9
# make a web server look like a filesystem.
12
# make_growfs /home/fred/www
14
# cd /growfs/my.web.server/~fred
30
$GROW_EPOCH = 1199163600;
43
($type,$name,$mode,$size,$mtime,$checksum) = split;
45
load_cache("$dirpath/$name");
46
} elsif($type eq "E") {
49
$mtime_cache{"$dirpath/$name"} = "$mtime";
50
$size_cache{"$dirpath/$name"} = "$size";
51
$checksum_cache{"$dirpath/$name"} = "$checksum";
53
return if(!defined DIRFILE);
60
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = @_;
61
return ($mode,$size,$mtime-$GROW_EPOCH);
71
opendir $dir, $dirname or die "make_growfs: couldn't open $dirname\n";
73
while( $d = readdir($dir) ) {
75
if( $d =~ ".growfs.*") {
79
if( $d eq "." || $d eq ".." ) {
83
$subdirname = "$dirname/$d";
85
print "$subdirname\n" if($verbose_mode);
87
if($follow_mode eq "y") {
88
# if we are following symbolic links, then
89
# stat the item the link points to.
90
@info = stat $subdirname;
92
# but if that fails, it could be a broken link,
93
# so try to get that instead.
95
@info = lstat $subdirname;
97
print STDERR "make_growfs: broken symbolic link $subdirname\n";
101
# if we are not following symbolic links,
102
# then look at the link itself and report that
103
@info = lstat $subdirname;
109
print STDERR "make_growfs: couldn't access $subdirname\n";
113
@info = reorder_stat @info;
115
if( S_ISLNK($info[0]) ) {
116
$linkname = readlink "$subdirname";
117
if(substr($linkname,0,1) eq "/") {
118
$toplength = length $topdir;
119
if(substr($linkname,0,$toplength) eq $topdir) {
120
$linkname = substr($linkname,$toplength);
121
if(substr($linkname,0,1) ne "/") {
122
$linkname = "/" . $linkname;
125
if( $follow_mode eq "a" ) {
126
print STDERR "make_growfs: following link $subdirname to $linkname\n";
127
@info = stat $subdirname;
130
print STDERR "make_growfs: symbolic link $subdirname points to $linkname outside the root $topdir\n";
134
print DIRFILE "L $d\t@info 0 $linkname\n";
136
} elsif( S_ISDIR($info[0]) ) {
137
print DIRFILE "D $d\t@info 0\n";
138
listdir($subdirname);
143
$mtime = $mtime_cache{$subdirname};
144
$size = $size_cache{$subdirname};
145
if(defined $mtime && $mtime==$info[2] && defined $size && $size==$info[1]) {
146
$checksum = $checksum_cache{$subdirname};
148
($checksum,$name) = split " ", `sha1sum \"$subdirname\"`;
150
print "$subdirname changed: $checksum\n" if($verbose_mode || $verbose_changes);
155
print DIRFILE "F $d\t@info $checksum\n";
164
print "Use: $0 [options] <directory>
166
-v Give verbose messages.
167
-K Create checksums for files. (default)
168
-k Disable checksums for files.
169
-f Follow all symbolic links.
170
-F Do not follow any symbolic links.
171
-a Only follow links that fall outside the root. (default)
172
-h Show this help file.
176
while( defined $ARGV[0] ) {
180
} elsif( $arg eq "-F" ) {
182
} elsif( $arg eq "-a" ) {
184
} elsif( $arg eq "-v" ) {
186
} elsif( $arg eq "-c" ) {
187
$verbose_changes = 1;
188
} elsif( $arg eq "-k" ) {
190
} elsif( $arg eq "-K" ) {
192
} elsif( $arg eq "-h" ) {
195
} elsif( $arg =~ "-.*" ) {
196
print "make_growfs: unknown argion: $arg (-h for help)\n";
204
if(!defined $topdir) {
205
print "make_growfs: please give me a directory name (-h for help)\n";
209
$dirfile = "$topdir/.growfsdir";
211
print "make_growfs: loading existing directory from $dirfile\n";
213
if(open DIRFILE, "$topdir/.growfsdir") {
218
print "make_growfs: no directory exists, this might be quite slow...\n";
221
print "make_growfs: scanning directory tree for changes...\n";
223
open DIRFILE, ">$topdir/.growfsdirtmp" or die "make_growfs: cannot write to directory file $topdir/.growfsdirtmp\n";
224
@info = reorder_stat stat $topdir;
225
print DIRFILE "D root\t@info 0\n";
232
rename "$topdir/.growfsdirtmp", "$topdir/.growfsdir";
233
system "sha1sum < $topdir/.growfsdir > $topdir/.growfschecksum";
235
printf "make_growfs: $total_files files, $total_links links, $total_dirs dirs, $total_checksums checksums computed\n";