Changed some names since "depth" wasn't really the right term.
[rsync/rsync.git] / backup.c
index 88f9eae..97ec957 100644 (file)
--- a/backup.c
+++ b/backup.c
@@ -21,6 +21,7 @@
 #include "rsync.h"
 
 extern int verbose;
+extern int suffix_specified;
 extern char *backup_suffix;
 extern char *backup_dir;
 
@@ -39,11 +40,11 @@ static int make_simple_backup(char *fname)
                return 0;
        }
 
-       slprintf(fnamebak,sizeof(fnamebak),"%s%s",fname,backup_suffix);
+       snprintf(fnamebak,sizeof(fnamebak),"%s%s",fname,backup_suffix);
        if (do_rename(fname,fnamebak) != 0) {
                /* cygwin (at least version b19) reports EINVAL */
                if (errno != ENOENT && errno != EINVAL) {
-                       rprintf(FERROR,"rename %s %s : %s\n",fname,fnamebak,strerror(errno));
+                       rsyserr(FERROR, errno, "rename %s to backup %s", fname, fnamebak);
                        return 0;
                }
        } else if (verbose > 1) {
@@ -92,9 +93,9 @@ static int make_bak_dir(char *fname,char *bak_path)
         while(strncmp(bak_path,"./",2)==0) bak_path += 2;
 
         if(bak_path[strlen(bak_path)-1]!='/') {
-                slprintf(fullpath,sizeof(fullpath),"%s/",bak_path);
+                snprintf(fullpath,sizeof(fullpath),"%s/",bak_path);
         } else {
-                slprintf(fullpath,sizeof(fullpath),"%s",bak_path);
+                snprintf(fullpath,sizeof(fullpath),"%s",bak_path);
         }
         p=fullpath;
         q=&fullpath[strlen(fullpath)];  /* End of bak_path string */
@@ -197,15 +198,23 @@ static int keep_backup(char *fname)
        if (do_stat (fname, &st)) return 1;
 #endif
 
-       file = make_file (0, fname, 0);
+       file = make_file(fname, NULL, NO_EXCLUDES);
+
+       /* the file could have disappeared */
+       if (!file) return 1;
 
         /* make a complete pathname for backup file */
-        if (strlen(backup_dir) + strlen(fname) > (MAXPATHLEN - 1)) {
+        if (strlen(backup_dir) + strlen(fname) + 
+               (suffix_specified ? strlen(backup_suffix) : 0) > (MAXPATHLEN - 1)) {
                 rprintf (FERROR, "keep_backup filename too long\n");
                 return 0;
         }
 
-        slprintf(keep_name, sizeof (keep_name), "%s/%s", backup_dir, fname);
+       if (suffix_specified) {
+               snprintf(keep_name, sizeof (keep_name), "%s/%s%s", backup_dir, fname, backup_suffix);
+               } else {
+               snprintf(keep_name, sizeof (keep_name), "%s/%s", backup_dir, fname);
+               }
 
 
 #ifdef HAVE_MKNOD
@@ -285,4 +294,3 @@ int make_backup(char *fname)
        else
                return (make_simple_backup(fname));
 }
-