1: #!/usr/bin/perl -w
2:
3: =pod
4:
5: =head1 savetime / loadtime
6:
7: This pair of simple scripts that are useful for making sure that
8: file times remain correct even after small updates.
9:
10: I use it to make sure that the photos from my digital camera have
11: the original times, even after some retouching or evil FTP clients
12: which do not set the right times...
13:
14: To install: Copy the file to somewhere within the path and make a
15: (symbolic) link to it, so that it appears in two names: loadtime and
16: savetime.
17:
18: =head2 savetime
19:
20: Creates the file '.filetimes' in the current directory and stores
21: access and modification time for all of the files in the current
22: directory.
23:
24: =head2 loadtime
25:
26: Resets the file times for all the files that have different time
27: than what is written in '.filetimes'.
28:
29: It will print one line for each file that is updated, containing the
30: number of seconds that have been changed.
31:
32: =cut
33:
34: if($0=~/savetime/)
35: { my @f=<*>;
36:
37: open(F, ">.filetimes") or die "open .filetimes: $!\n";
38: for (@f) {
39: my ($atime, $mtime)=(stat($_))[8,9];
40: print F "$_ $atime $mtime\n";
41: }
42: }
43:
44: if($0=~/loadtime/) {
45: die unless -f ".filetimes";
46:
47: open(F, "<.filetimes") or die "open .filetimes: $!\n";
48: while(<F>) {
49: my ($n,$a,$m) = split;
50: $atime{$n} = $a;
51: $mtime{$n} = $m;
52: }
53: close(F);
54:
55: for (<*>) {
56: my ($a, $m)=(stat($_))[8,9];
57: next if($a==$atime{$_} and $m==$mtime{$_});
58: print "$_ \t", $a-$atime{$_}, " \t",$m-$mtime{$_}, "\n";
59: utime $atime{$_}, $mtime{$_}, $_ or die "utime: $!\n";
60: }
61: }