Mercurial > hg > foxridge-archiver
comparison metacheck.pl @ 18:fdf4ceb36db1
fixed problem with dir names in metacheck
new version of metacheck defaults to not change index file
new version of archiver uses new version of metacheck
author | casties |
---|---|
date | Tue, 20 Sep 2005 19:24:57 +0200 |
parents | b7259a1c85aa |
children | 1dd183b95c61 |
comparison
equal
deleted
inserted
replaced
17:6c5c7743acb1 | 18:fdf4ceb36db1 |
---|---|
12 ####################################################### | 12 ####################################################### |
13 # internal parameters | 13 # internal parameters |
14 # | 14 # |
15 | 15 |
16 # program version | 16 # program version |
17 my $version = "0.5.3 (8.7.2004)"; | 17 my $version = "0.6.0 (20.9.2005)"; |
18 my $help = | |
19 "use: metacheck [options] docdir | |
20 options: | |
21 -debug show debugging info | |
22 -dry-run simulate, dont'do anything | |
23 -checkonly leave existing index file untouched | |
24 -add-files add file tags for missing files | |
25 -replace rewrite index file to match current files | |
26 "; | |
27 logger("INFO", "metacheck $version"); | |
18 | 28 |
19 # read command line parameters | 29 # read command line parameters |
20 my $args = MPIWGStor::parseargs; | 30 my $args = MPIWGStor::parseargs; |
31 if (! scalar(%$args)) { | |
32 print $help, "\n"; | |
33 exit 1; | |
34 } | |
21 | 35 |
22 # debug level | 36 # debug level |
23 $debug = (exists $$args{'debug'}) ? $$args{'debug'} : 0; | 37 $debug = (exists $$args{'debug'}) ? $$args{'debug'} : 0; |
24 | 38 |
39 # simulate action only | |
40 my $dry_run = (exists $$args{'dry-run'}) ? $$args{'dry-run'} : 0; | |
41 logger('DEBUG', "dry-run: $dry_run"); | |
42 | |
25 # check only or fix index file also | 43 # check only or fix index file also |
26 my $check_only = (exists $$args{'checkonly'}) ? $$args{'checkonly'} : 0; | 44 my $check_only = (exists $$args{'checkonly'}) ? $$args{'checkonly'} : 1; |
45 | |
27 # add file tags for missing files | 46 # add file tags for missing files |
28 my $fix_files = ! $check_only; | 47 my $fix_files = ! $check_only; |
29 # add tags for file size and date | 48 # add tags for file size and date |
30 my $fix_fs_meta = 1; | 49 my $fix_fs_meta = 1; |
31 # add dir tags for missing directories | 50 # add dir tags for missing directories |
32 my $fix_dirs = ! $check_only; | 51 my $fix_dirs = ! $check_only; |
33 # rewrite XML file (necessary for fix_files and fix_dirs) | 52 # rewrite XML file (necessary for fix_files and fix_dirs) |
34 my $fix_xml = ! $check_only; | 53 my $fix_xml = ! $check_only; |
54 # rewrite complete index file | |
55 my $do_rewrite = 0; | |
56 | |
57 # add file tags for missing files | |
58 if (exists $$args{'add-files'}) { | |
59 $check_only = 0; | |
60 $fix_files = 1; | |
61 $fix_dirs = 1; | |
62 $fix_xml = 1; | |
63 $do_rewrite = 0; | |
64 logger('DEBUG', "add-files: true"); | |
65 } | |
66 | |
67 # completely rewrite index file | |
68 if (exists $$args{'replace'}) { | |
69 $check_only = 0; | |
70 $fix_files = 1; | |
71 $fix_dirs = 1; | |
72 $fix_xml = 1; | |
73 $do_rewrite = 1; | |
74 logger('DEBUG', "replace: true"); | |
75 } | |
76 logger('DEBUG', "checkonly: $check_only"); | |
77 | |
78 | |
35 my $xml_changed = 0; | 79 my $xml_changed = 0; |
36 # XML namespace (not really implemented!) | 80 # XML namespace (not really implemented!) |
37 my $namespace = ""; | 81 my $namespace = ""; |
38 | 82 |
39 | 83 |
148 logger("WARNING", "description for directory $dirname (in $dirpath/) missing!"); | 192 logger("WARNING", "description for directory $dirname (in $dirpath/) missing!"); |
149 $warncnt++; | 193 $warncnt++; |
150 } | 194 } |
151 # check with dirs on filesystem | 195 # check with dirs on filesystem |
152 my $fn; | 196 my $fn; |
153 if ($dirpath) { | 197 if ($dirpath && ($dirpath ne '.')) { |
154 $fn = "$dirpath/$dirname"; | 198 $fn = "$dirpath/$dirname"; |
155 } else { | 199 } else { |
156 $fn = "$dirname"; | 200 $fn = "$dirname"; |
157 } | 201 } |
158 #logger("dir: \"$dirname\", \"$dirpath\""); | 202 #logger('DEBUG', "dir: \"$dirname\", \"$dirpath\", fn: \"$fn\""); |
159 if ($$fsdirs{$fn}) { | 203 if ($$fsdirs{$fn}) { |
160 #logger(" OK ($$fsdirs{$fn})"); | 204 #logger(" OK ($$fsdirs{$fn})"); |
161 $okdirs{$fn} = $dirname; | 205 $okdirs{$fn} = $dirname; |
162 } else { | 206 } else { |
163 logger("ERROR", "directory $dirname (in $dirpath/) missing on disk!"); | 207 if ($do_rewrite) { |
164 $errcnt++; | 208 # remove dir tag |
209 logger("WARNING", "directory $dirname (in $dirpath/) no longer on disk!"); | |
210 $dirnode->unbindNode(); | |
211 $warncnt++; | |
212 } else { | |
213 logger("ERROR", "directory $dirname (in $dirpath/) missing on disk!"); | |
214 $errcnt++; | |
215 } | |
165 } | 216 } |
166 } | 217 } |
167 #logger("dirs: ", (scalar keys %$fsdirs), " vs ", (scalar keys %okdirs), ""); | 218 #logger("dirs: ", (scalar keys %$fsdirs), " vs ", (scalar keys %okdirs), ""); |
168 if ((scalar keys %$fsdirs) != (scalar keys %okdirs)) { | 219 if ((scalar keys %$fsdirs) != (scalar keys %okdirs)) { |
169 # number of dir tags and dirs don't match | 220 # number of dir tags and dirs don't match |
170 # iterate through all dirs | 221 # iterate through all dirs |
171 foreach my $f (sort keys %$fsdirs) { | 222 foreach my $f (sort keys %$fsdirs) { |
172 # was this dir missing? | 223 # was this dir missing? |
173 if (! $okdirs{$f}) { | 224 if (! $okdirs{$f}) { |
174 my ($name, $path) = split_file_path($f); | 225 my ($name, $path) = split_file_path($f, 1); |
175 # name must be valid | 226 # name must be valid |
176 if (! valid_dir_name($name)) { | 227 if (! valid_dir_name($name)) { |
177 $path = "." unless ($path); | 228 $path = "." unless ($path); |
178 logger("ERROR", "directory name $name (in $path/) invalid!"); | 229 logger("ERROR", "directory name $name (in $path/) invalid!"); |
179 $errcnt++; | 230 $errcnt++; |
260 $node = $filenode->addNewChild($namespace, "date"); | 311 $node = $filenode->addNewChild($namespace, "date"); |
261 $node->appendTextNode(stime($$fsfiles{$fn}->[2])); | 312 $node->appendTextNode(stime($$fsfiles{$fn}->[2])); |
262 $xml_changed++; | 313 $xml_changed++; |
263 } | 314 } |
264 } else { | 315 } else { |
265 logger("ERROR", "file $filename (in $filepath/) missing on disk!"); | 316 if ($do_rewrite) { |
266 $errcnt++; | 317 # remove file tag |
318 logger("WARNING", "file $filename (in $filepath/) no longer on disk!"); | |
319 $filenode->unbindNode(); | |
320 $warncnt++; | |
321 } else { | |
322 logger("ERROR", "file $filename (in $filepath/) missing on disk!"); | |
323 $errcnt++; | |
324 } | |
267 } | 325 } |
268 } | 326 } |
269 #logger("files: ", (scalar keys %$fsfiles), " vs ", (scalar keys %okfiles), ""); | 327 #logger("files: ", (scalar keys %$fsfiles), " vs ", (scalar keys %okfiles), ""); |
270 if ((scalar keys %$fsfiles) != (scalar keys %okfiles)) { | 328 if ((scalar keys %$fsfiles) != (scalar keys %okfiles)) { |
271 # number of file tags and files don't match | 329 # number of file tags and files don't match |
272 # iterate through all files | 330 # iterate through all files |
273 foreach my $f (sort keys %$fsfiles) { | 331 foreach my $f (sort keys %$fsfiles) { |
274 my ($name, $path) = split_file_path($f); | 332 my ($name, $path) = split_file_path($f, 1); |
275 # was this file missing? | 333 # was this file missing? |
276 if (! $okfiles{$f}) { | 334 if (! $okfiles{$f}) { |
277 # is an ignoreable file? | 335 # is an ignoreable file? |
278 if ($index_files{$name}) { | 336 if ($index_files{$name}) { |
279 next; | 337 next; |
388 | 446 |
389 ####################################################### | 447 ####################################################### |
390 # main | 448 # main |
391 # | 449 # |
392 | 450 |
393 logger("INFO", "metacheck $version"); | |
394 | |
395 my ($document, $rootnode) = read_xml($metafile); | 451 my ($document, $rootnode) = read_xml($metafile); |
396 | 452 |
397 check_resource_meta($rootnode); | 453 check_resource_meta($rootnode); |
398 | 454 |
399 my $fnum = fs_read_files($docdir, "", \%files, \%dirs); | 455 my $fnum = fs_read_files($docdir, "", \%files, \%dirs); |
400 logger("INFO", "$fnum files on FS"); | 456 logger("INFO", "$fnum files on FS"); |
401 #foreach (keys %files) {logger(" file ($_): $files{$_}");} | 457 #foreach (keys %dirs) {logger('DEBUG', " dir ($_): $dirs{$_}");} |
402 | 458 |
403 check_files($rootnode, \%files); | 459 check_files($rootnode, \%files); |
404 check_dirs($rootnode, \%dirs); | 460 check_dirs($rootnode, \%dirs); |
405 | 461 |
406 logger("INFO", "$warncnt warnings"); | 462 logger("INFO", "$warncnt warnings"); |
407 logger("INFO", "$errcnt errors"); | 463 logger("INFO", "$errcnt errors"); |
408 if ($errcnt > 0) { | 464 if ($errcnt > 0) { |
409 logger("ABORT", "there were errors!"); | 465 logger("ABORT", "there were $errcnt errors!"); |
410 exit 1; | 466 exit 1; |
411 } else { | 467 } else { |
412 if ($fix_xml) { | 468 if ($fix_xml) { |
413 write_xml($document, $metafile); | 469 if ($dry_run) { |
470 logger('INFO', "would write $metafile"); | |
471 logger('DEBUG', $document->toString(1)); | |
472 } else { | |
473 write_xml($document, $metafile); | |
474 } | |
414 } | 475 } |
415 logger("DONE", "index file checked successfully!"); | 476 logger("DONE", "index file checked successfully!"); |
416 } | 477 } |