Diff for /embedaddon/rsync/backup.c between versions 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2013/10/14 07:51:14 version 1.1.1.3, 2016/11/01 09:54:32
Line 2 Line 2
  * Backup handling code.   * Backup handling code.
  *   *
  * Copyright (C) 1999 Andrew Tridgell   * Copyright (C) 1999 Andrew Tridgell
 * Copyright (C) 2003-2013 Wayne Davison * Copyright (C) 2003-2015 Wayne Davison
  *   *
  * This program is free software; you can redistribute it and/or modify   * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by   * it under the terms of the GNU General Public License as published by
Line 157  static BOOL copy_valid_path(const char *fname) Line 157  static BOOL copy_valid_path(const char *fname)
 char *get_backup_name(const char *fname)  char *get_backup_name(const char *fname)
 {  {
         if (backup_dir) {          if (backup_dir) {
                   static int initialized = 0;
                   if (!initialized) {
                           int ret;
                           if (backup_dir_len > 1)
                                   backup_dir_buf[backup_dir_len-1] = '\0';
                           ret = make_path(backup_dir_buf, 0);
                           if (backup_dir_len > 1)
                                   backup_dir_buf[backup_dir_len-1] = '/';
                           if (ret < 0)
                                   return NULL;
                           initialized = 1;
                   }
                 /* copy fname into backup_dir_buf while validating the dirs. */                  /* copy fname into backup_dir_buf while validating the dirs. */
                 if (copy_valid_path(fname))                  if (copy_valid_path(fname))
                         return backup_dir_buf;                          return backup_dir_buf;
Line 208  static inline int link_or_rename(const char *from, con Line 220  static inline int link_or_rename(const char *from, con
         return 0;          return 0;
 }  }
   
/* Hard-link, rename, or copy an item to the backup name.  Returns 2 if item/* Hard-link, rename, or copy an item to the backup name.  Returns 0 for
 * was duplicated into backup area, 1 if item was moved, or 0 for failure.*/ * failure, 1 if item was moved, 2 if item was duplicated or hard linked
  * into backup area, or 3 if item doesn't exist or isn't a regular file. */
 int make_backup(const char *fname, BOOL prefer_rename)  int make_backup(const char *fname, BOOL prefer_rename)
 {  {
         stat_x sx;          stat_x sx;
         struct file_struct *file;          struct file_struct *file;
         int save_preserve_xattrs;          int save_preserve_xattrs;
        char *buf = get_backup_name(fname);        char *buf;
         int ret = 0;          int ret = 0;
   
         if (!buf)  
                 return 0;  
   
         init_stat_x(&sx);          init_stat_x(&sx);
         /* Return success if no file to keep. */          /* Return success if no file to keep. */
         if (x_lstat(fname, &sx.st, NULL) < 0)          if (x_lstat(fname, &sx.st, NULL) < 0)
                return 1;                return 3;
   
           if (!(buf = get_backup_name(fname)))
                   return 0;
   
         /* Try a hard-link or a rename first.  Using rename is not atomic, but          /* Try a hard-link or a rename first.  Using rename is not atomic, but
          * is more efficient than forcing a copy for larger files when no hard-           * is more efficient than forcing a copy for larger files when no hard-
          * linking is possible. */           * linking is possible. */
Line 244  int make_backup(const char *fname, BOOL prefer_rename) Line 257  int make_backup(const char *fname, BOOL prefer_rename)
   
         /* Fall back to making a copy. */          /* Fall back to making a copy. */
         if (!(file = make_file(fname, NULL, &sx.st, 0, NO_FILTERS)))          if (!(file = make_file(fname, NULL, &sx.st, 0, NO_FILTERS)))
                return 1; /* the file could have disappeared */                return 3; /* the file could have disappeared */
   
 #ifdef SUPPORT_ACLS  #ifdef SUPPORT_ACLS
         if (preserve_acls && !S_ISLNK(file->mode)) {          if (preserve_acls && !S_ISLNK(file->mode)) {
Line 299  int make_backup(const char *fname, BOOL prefer_rename) Line 312  int make_backup(const char *fname, BOOL prefer_rename)
 #ifdef SUPPORT_XATTRS  #ifdef SUPPORT_XATTRS
                 uncache_tmp_xattrs();                  uncache_tmp_xattrs();
 #endif  #endif
                return 2;                return 3;
         }          }
   
         /* Copy to backup tree if a file. */          /* Copy to backup tree if a file. */

Removed from v.1.1.1.2  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>