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