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