Some memory allocation improvements
[rsync.git] / backup.c
index fcc1a72b90c8a56ab3da4a7cdc88982b3ca54390..be406bef83003e604555d9a1158b80f76778657e 100644 (file)
--- a/backup.c
+++ b/backup.c
@@ -2,7 +2,7 @@
  * Backup handling code.
  *
  * Copyright (C) 1999 Andrew Tridgell
- * Copyright (C) 2003-2015 Wayne Davison
+ * Copyright (C) 2003-2020 Wayne Davison
  *
  * 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
@@ -157,6 +157,18 @@ static BOOL copy_valid_path(const char *fname)
 char *get_backup_name(const char *fname)
 {
        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. */
                if (copy_valid_path(fname))
                        return backup_dir_buf;
@@ -324,7 +336,7 @@ int make_backup(const char *fname, BOOL prefer_rename)
 
        save_preserve_xattrs = preserve_xattrs;
        preserve_xattrs = 0;
-       set_file_attrs(buf, file, NULL, fname, 0);
+       set_file_attrs(buf, file, NULL, fname, ATTRS_ACCURATE_TIME);
        preserve_xattrs = save_preserve_xattrs;
 
        unmake_file(file);