]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
don't backup to a newer file
authorAndrew Tridgell <tridge@samba.org>
Fri, 28 Jun 2002 03:52:22 +0000 (03:52 +0000)
committerAndrew Tridgell <tridge@samba.org>
Fri, 28 Jun 2002 03:52:22 +0000 (03:52 +0000)
source/tdb/tdbbackup.c

index 48c4272d3312e199d6ca8a8a4da64624be5e0093..f59f98a90f52306bfe1149bef43a8742ac463413 100644 (file)
@@ -224,6 +224,21 @@ static int verify_tdb(const char *fname, const char *bak_name)
 }
 
 
+/*
+  see if one file is newer than another
+*/
+static int file_newer(const char *fname1, const char *fname2)
+{
+       struct stat st1, st2;
+       if (stat(fname1, &st1) != 0) {
+               return 0;
+       }
+       if (stat(fname2, &st2) != 0) {
+               return 1;
+       }
+       return (st1.st_mtime > st2.st_mtime);
+}
+
 static void usage(void)
 {
        printf("Usage: tdbbackup [options] <fname...>\n\n");
@@ -276,7 +291,8 @@ static void usage(void)
                                ret = 1;
                        }
                } else {
-                       if (backup_tdb(fname, bak_name) != 0) {
+                       if (file_newer(fname, bak_name) &&
+                           backup_tdb(fname, bak_name) != 0) {
                                ret = 1;
                        }
                }