blob: 3438c526356290fdf6a94f400fc581c9b48ff361 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#!/usr/bin/perl -w
# copy a file if it is both newer and bigger in size
# if copying, first rename older file to .orig
$src = $ARGV[0];
$dst = $ARGV[1];
# dev,ino,mode,nlink,uid,gid,rdev,size,atime,mtime,ctime,blksize,blocks
@srcstat = stat($src);
@dststat = stat($dst);
$srcsize = $srcstat[7];
$srcmtime = $srcstat[9];
$dstsize = $dststat[7];
$dstmtime = $dststat[9];
# copy if src file is bigger and newer
if ($srcsize > $dstsize && $srcmtime > $dstmtime) {
print "mv -f $dst $dst.orig\n";
system("mv -f $dst $dst.orig");
print "cp -p $src $dst\n";
system("cp -p $src $dst");
die "cp command failed" if ($? != 0);
}
# make sure dst file has newer timestamp
if ($srcmtime > $dstmtime) {
print "touch $dst\n";
system("touch $dst");
}
exit(0);
|