|
version 1.1.1.1, 2012/02/17 15:09:30
|
version 1.1.1.4, 2021/03/17 00:32:36
|
|
Line 4
|
Line 4
|
| * Copyright (C) 1996-2000 Andrew Tridgell |
* Copyright (C) 1996-2000 Andrew Tridgell |
| * Copyright (C) 1996 Paul Mackerras |
* Copyright (C) 1996 Paul Mackerras |
| * Copyright (C) 2002 Martin Pool <mbp@samba.org> |
* Copyright (C) 2002 Martin Pool <mbp@samba.org> |
| * Copyright (C) 2003-2009 Wayne Davison | * Copyright (C) 2003-2020 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 21
|
Line 21
|
| */ |
*/ |
| |
|
| #include "rsync.h" |
#include "rsync.h" |
| |
#include "inums.h" |
| |
#include "ifuncs.h" |
| |
|
| extern int verbose; |
|
| extern int dry_run; |
extern int dry_run; |
| extern int do_xfers; |
extern int do_xfers; |
| extern int stdout_format_has_i; |
extern int stdout_format_has_i; |
|
Line 31 extern int am_root;
|
Line 32 extern int am_root;
|
| extern int am_server; |
extern int am_server; |
| extern int am_daemon; |
extern int am_daemon; |
| extern int inc_recurse; |
extern int inc_recurse; |
| extern int do_progress; |
|
| extern int relative_paths; |
extern int relative_paths; |
| extern int implied_dirs; |
extern int implied_dirs; |
| extern int keep_dirlinks; |
extern int keep_dirlinks; |
| extern int preserve_acls; |
extern int preserve_acls; |
| extern int preserve_xattrs; |
extern int preserve_xattrs; |
| |
extern int preserve_hfs_compression; |
| extern int preserve_links; |
extern int preserve_links; |
| extern int preserve_devices; |
extern int preserve_devices; |
| |
extern int copy_devices; |
| |
extern int write_devices; |
| extern int preserve_specials; |
extern int preserve_specials; |
| extern int preserve_hard_links; |
extern int preserve_hard_links; |
| extern int preserve_executability; |
extern int preserve_executability; |
| |
extern int preserve_fileflags; |
| extern int preserve_perms; |
extern int preserve_perms; |
| extern int preserve_times; |
extern int preserve_times; |
| |
extern int force_change; |
| extern int delete_mode; |
extern int delete_mode; |
| extern int delete_before; |
extern int delete_before; |
| extern int delete_during; |
extern int delete_during; |
| extern int delete_after; |
extern int delete_after; |
| |
extern int missing_args; |
| extern int msgdone_cnt; |
extern int msgdone_cnt; |
| extern int ignore_errors; |
extern int ignore_errors; |
| |
extern int checksum_files; |
| extern int remove_source_files; |
extern int remove_source_files; |
| extern int delay_updates; |
extern int delay_updates; |
| extern int update_only; |
extern int update_only; |
| |
extern int downdate_only; |
| |
extern int human_readable; |
| extern int ignore_existing; |
extern int ignore_existing; |
| extern int ignore_non_existing; |
extern int ignore_non_existing; |
| |
extern int want_xattr_optim; |
| |
extern int modify_window; |
| extern int inplace; |
extern int inplace; |
| |
extern int use_db; |
| extern int append_mode; |
extern int append_mode; |
| extern int make_backups; |
extern int make_backups; |
| extern int csum_length; |
extern int csum_length; |
| extern int ignore_times; |
extern int ignore_times; |
| |
extern int date_only; |
| extern int size_only; |
extern int size_only; |
| extern OFF_T max_size; |
extern OFF_T max_size; |
| extern OFF_T min_size; |
extern OFF_T min_size; |
|
Line 67 extern int io_error;
|
Line 80 extern int io_error;
|
| extern int flist_eof; |
extern int flist_eof; |
| extern int allowed_lull; |
extern int allowed_lull; |
| extern int sock_f_out; |
extern int sock_f_out; |
| extern int ignore_timeout; |
|
| extern int protocol_version; |
extern int protocol_version; |
| extern int file_total; |
extern int file_total; |
| extern int fuzzy_basis; |
extern int fuzzy_basis; |
| extern int always_checksum; |
extern int always_checksum; |
| extern int checksum_len; | extern int flist_csum_len; |
| extern char *partial_dir; |
extern char *partial_dir; |
| extern char *basis_dir[MAX_BASIS_DIRS+1]; | extern int alt_dest_type; |
| extern int compare_dest; | extern int detect_renamed; |
| extern int copy_dest; | |
| extern int link_dest; | |
| extern int whole_file; |
extern int whole_file; |
| extern int list_only; |
extern int list_only; |
| extern int read_batch; |
extern int read_batch; |
| |
extern int write_batch; |
| extern int safe_symlinks; |
extern int safe_symlinks; |
| extern long block_size; /* "long" because popt can't set an int32. */ | extern int32 block_size; |
| extern int unsort_ndx; |
extern int unsort_ndx; |
| extern int max_delete; |
extern int max_delete; |
| extern int force_delete; |
extern int force_delete; |
| extern int one_file_system; |
extern int one_file_system; |
| extern struct stats stats; | extern int skipped_deletes; |
| extern dev_t filesystem_dev; |
extern dev_t filesystem_dev; |
| extern mode_t orig_umask; |
extern mode_t orig_umask; |
| extern uid_t our_uid; |
extern uid_t our_uid; |
| extern char *backup_dir; | extern char *tmpdir; |
| extern char *backup_suffix; | extern char *basis_dir[MAX_BASIS_DIRS+1]; |
| extern int backup_suffix_len; | |
| extern struct file_list *cur_flist, *first_flist, *dir_flist; |
extern struct file_list *cur_flist, *first_flist, *dir_flist; |
| extern struct filter_list_struct daemon_filter_list; | extern filter_rule_list filter_list, daemon_filter_list; |
| | extern struct file_list the_fattr_list; |
| |
|
| int ignore_perishable = 0; |
|
| int non_perishable_cnt = 0; |
|
| int maybe_ATTRS_REPORT = 0; |
int maybe_ATTRS_REPORT = 0; |
| |
int maybe_ATTRS_ACCURATE_TIME = 0; |
| |
|
| static dev_t dev_zero; |
static dev_t dev_zero; |
| static int deletion_count = 0; /* used to implement --max-delete */ | static int unexplored_dirs = 1; |
| static int deldelay_size = 0, deldelay_cnt = 0; |
static int deldelay_size = 0, deldelay_cnt = 0; |
| static char *deldelay_buf = NULL; |
static char *deldelay_buf = NULL; |
| static int deldelay_fd = -1; |
static int deldelay_fd = -1; |
|
Line 111 static int dir_tweaking;
|
Line 121 static int dir_tweaking;
|
| static int symlink_timeset_failed_flags; |
static int symlink_timeset_failed_flags; |
| static int need_retouch_dir_times; |
static int need_retouch_dir_times; |
| static int need_retouch_dir_perms; |
static int need_retouch_dir_perms; |
| |
static int started_whole_dir, upcoming_whole_dir; |
| static const char *solo_file = NULL; |
static const char *solo_file = NULL; |
| |
|
| /* For calling delete_item() and delete_dir_contents(). */ |
|
| #define DEL_NO_UID_WRITE (1<<0) /* file/dir has our uid w/o write perm */ |
|
| #define DEL_RECURSE (1<<1) /* if dir, delete all contents */ |
|
| #define DEL_DIR_IS_EMPTY (1<<2) /* internal delete_FUNCTIONS use only */ |
|
| #define DEL_FOR_FILE (1<<3) /* making room for a replacement file */ |
|
| #define DEL_FOR_DIR (1<<4) /* making room for a replacement dir */ |
|
| #define DEL_FOR_SYMLINK (1<<5) /* making room for a replacement symlink */ |
|
| #define DEL_FOR_DEVICE (1<<6) /* making room for a replacement device */ |
|
| #define DEL_FOR_SPECIAL (1<<7) /* making room for a replacement special */ |
|
| |
|
| #define DEL_MAKE_ROOM (DEL_FOR_FILE|DEL_FOR_DIR|DEL_FOR_SYMLINK|DEL_FOR_DEVICE|DEL_FOR_SPECIAL) |
|
| |
|
| enum nonregtype { |
enum nonregtype { |
| TYPE_DIR, TYPE_SPECIAL, TYPE_DEVICE, TYPE_SYMLINK | TYPE_DIR, TYPE_SPECIAL, TYPE_DEVICE, TYPE_SYMLINK |
| }; |
}; |
| |
|
| enum delret { |
|
| DR_SUCCESS = 0, DR_FAILURE, DR_AT_LIMIT, DR_NOT_EMPTY |
|
| }; |
|
| |
|
| /* Forward declarations. */ |
/* Forward declarations. */ |
| static enum delret delete_dir_contents(char *fname, uint16 flags); |
|
| #ifdef SUPPORT_HARD_LINKS |
#ifdef SUPPORT_HARD_LINKS |
| static void handle_skipped_hlink(struct file_struct *file, int itemizing, |
static void handle_skipped_hlink(struct file_struct *file, int itemizing, |
| enum logcode code, int f_out); |
enum logcode code, int f_out); |
| #endif |
#endif |
| |
|
| static int is_backup_file(char *fn) | #define EARLY_DELAY_DONE_MSG() (!delay_updates) |
| { | #define EARLY_DELETE_DONE_MSG() (!(delete_during == 2 || delete_after)) |
| int k = strlen(fn) - backup_suffix_len; | |
| return k > 0 && strcmp(fn+k, backup_suffix) == 0; | |
| } | |
| |
|
| /* Delete a file or directory. If DEL_RECURSE is set in the flags, this will |
|
| * delete recursively. |
|
| * |
|
| * Note that fbuf must point to a MAXPATHLEN buffer if the mode indicates it's |
|
| * a directory! (The buffer is used for recursion, but returned unchanged.) |
|
| */ |
|
| static enum delret delete_item(char *fbuf, uint16 mode, uint16 flags) |
|
| { |
|
| enum delret ret; |
|
| char *what; |
|
| int ok; |
|
| |
|
| if (verbose > 2) { |
|
| rprintf(FINFO, "delete_item(%s) mode=%o flags=%d\n", |
|
| fbuf, (int)mode, (int)flags); |
|
| } |
|
| |
|
| if (flags & DEL_NO_UID_WRITE) |
|
| do_chmod(fbuf, mode | S_IWUSR); |
|
| |
|
| if (S_ISDIR(mode) && !(flags & DEL_DIR_IS_EMPTY)) { |
|
| /* This only happens on the first call to delete_item() since |
|
| * delete_dir_contents() always calls us w/DEL_DIR_IS_EMPTY. */ |
|
| ignore_perishable = 1; |
|
| /* If DEL_RECURSE is not set, this just reports emptiness. */ |
|
| ret = delete_dir_contents(fbuf, flags); |
|
| ignore_perishable = 0; |
|
| if (ret == DR_NOT_EMPTY || ret == DR_AT_LIMIT) |
|
| goto check_ret; |
|
| /* OK: try to delete the directory. */ |
|
| } |
|
| |
|
| if (!(flags & DEL_MAKE_ROOM) && max_delete >= 0 && ++deletion_count > max_delete) |
|
| return DR_AT_LIMIT; |
|
| |
|
| if (S_ISDIR(mode)) { |
|
| what = "rmdir"; |
|
| ok = do_rmdir(fbuf) == 0; |
|
| } else if (make_backups > 0 && (backup_dir || !is_backup_file(fbuf))) { |
|
| what = "make_backup"; |
|
| ok = make_backup(fbuf); |
|
| } else { |
|
| what = "unlink"; |
|
| ok = robust_unlink(fbuf) == 0; |
|
| } |
|
| |
|
| if (ok) { |
|
| if (!(flags & DEL_MAKE_ROOM)) |
|
| log_delete(fbuf, mode); |
|
| ret = DR_SUCCESS; |
|
| } else { |
|
| if (S_ISDIR(mode) && errno == ENOTEMPTY) { |
|
| rprintf(FINFO, "cannot delete non-empty directory: %s\n", |
|
| fbuf); |
|
| ret = DR_NOT_EMPTY; |
|
| } else if (errno != ENOENT) { |
|
| rsyserr(FERROR, errno, "delete_file: %s(%s) failed", |
|
| what, fbuf); |
|
| ret = DR_FAILURE; |
|
| } else { |
|
| deletion_count--; |
|
| ret = DR_SUCCESS; |
|
| } |
|
| } |
|
| |
|
| check_ret: |
|
| if (ret != DR_SUCCESS && flags & DEL_MAKE_ROOM) { |
|
| const char *desc; |
|
| switch (flags & DEL_MAKE_ROOM) { |
|
| case DEL_FOR_FILE: desc = "regular file"; break; |
|
| case DEL_FOR_DIR: desc = "directory"; break; |
|
| case DEL_FOR_SYMLINK: desc = "symlink"; break; |
|
| case DEL_FOR_DEVICE: desc = "device file"; break; |
|
| case DEL_FOR_SPECIAL: desc = "special file"; break; |
|
| default: exit_cleanup(RERR_UNSUPPORTED); /* IMPOSSIBLE */ |
|
| } |
|
| rprintf(FERROR_XFER, "could not make way for new %s: %s\n", |
|
| desc, fbuf); |
|
| } |
|
| return ret; |
|
| } |
|
| |
|
| /* The directory is about to be deleted: if DEL_RECURSE is given, delete all |
|
| * its contents, otherwise just checks for content. Returns DR_SUCCESS or |
|
| * DR_NOT_EMPTY. Note that fname must point to a MAXPATHLEN buffer! (The |
|
| * buffer is used for recursion, but returned unchanged.) |
|
| */ |
|
| static enum delret delete_dir_contents(char *fname, uint16 flags) |
|
| { |
|
| struct file_list *dirlist; |
|
| enum delret ret; |
|
| unsigned remainder; |
|
| void *save_filters; |
|
| int j, dlen; |
|
| char *p; |
|
| |
|
| if (verbose > 3) { |
|
| rprintf(FINFO, "delete_dir_contents(%s) flags=%d\n", |
|
| fname, flags); |
|
| } |
|
| |
|
| dlen = strlen(fname); |
|
| save_filters = push_local_filters(fname, dlen); |
|
| |
|
| non_perishable_cnt = 0; |
|
| dirlist = get_dirlist(fname, dlen, 0); |
|
| ret = non_perishable_cnt ? DR_NOT_EMPTY : DR_SUCCESS; |
|
| |
|
| if (!dirlist->used) |
|
| goto done; |
|
| |
|
| if (!(flags & DEL_RECURSE)) { |
|
| ret = DR_NOT_EMPTY; |
|
| goto done; |
|
| } |
|
| |
|
| p = fname + dlen; |
|
| if (dlen != 1 || *fname != '/') |
|
| *p++ = '/'; |
|
| remainder = MAXPATHLEN - (p - fname); |
|
| |
|
| /* We do our own recursion, so make delete_item() non-recursive. */ |
|
| flags = (flags & ~(DEL_RECURSE|DEL_MAKE_ROOM|DEL_NO_UID_WRITE)) |
|
| | DEL_DIR_IS_EMPTY; |
|
| |
|
| for (j = dirlist->used; j--; ) { |
|
| struct file_struct *fp = dirlist->files[j]; |
|
| |
|
| if (fp->flags & FLAG_MOUNT_DIR && S_ISDIR(fp->mode)) { |
|
| if (verbose > 1) { |
|
| rprintf(FINFO, |
|
| "mount point, %s, pins parent directory\n", |
|
| f_name(fp, NULL)); |
|
| } |
|
| ret = DR_NOT_EMPTY; |
|
| continue; |
|
| } |
|
| |
|
| strlcpy(p, fp->basename, remainder); |
|
| if (!(fp->mode & S_IWUSR) && !am_root && fp->flags & FLAG_OWNED_BY_US) |
|
| do_chmod(fname, fp->mode | S_IWUSR); |
|
| /* Save stack by recursing to ourself directly. */ |
|
| if (S_ISDIR(fp->mode)) { |
|
| if (delete_dir_contents(fname, flags | DEL_RECURSE) != DR_SUCCESS) |
|
| ret = DR_NOT_EMPTY; |
|
| } |
|
| if (delete_item(fname, fp->mode, flags) != DR_SUCCESS) |
|
| ret = DR_NOT_EMPTY; |
|
| } |
|
| |
|
| fname[dlen] = '\0'; |
|
| |
|
| done: |
|
| flist_free(dirlist); |
|
| pop_local_filters(save_filters); |
|
| |
|
| if (ret == DR_NOT_EMPTY) { |
|
| rprintf(FINFO, "cannot delete non-empty directory: %s\n", |
|
| fname); |
|
| } |
|
| return ret; |
|
| } |
|
| |
|
| static int start_delete_delay_temp(void) |
static int start_delete_delay_temp(void) |
| { |
{ |
| char fnametmp[MAXPATHLEN]; |
char fnametmp[MAXPATHLEN]; |
| int save_dry_run = dry_run; |
int save_dry_run = dry_run; |
| |
|
| dry_run = 0; |
dry_run = 0; |
| if (!get_tmpname(fnametmp, "deldelay") | if (!get_tmpname(fnametmp, "deldelay", False) |
| || (deldelay_fd = do_mkstemp(fnametmp, 0600)) < 0) { |
|| (deldelay_fd = do_mkstemp(fnametmp, 0600)) < 0) { |
| rprintf(FINFO, "NOTE: Unable to create delete-delay temp file%s.\n", |
rprintf(FINFO, "NOTE: Unable to create delete-delay temp file%s.\n", |
| inc_recurse ? "" : " -- switching to --delete-after"); |
inc_recurse ? "" : " -- switching to --delete-after"); |
|
Line 355 static int remember_delete(struct file_struct *file, c
|
Line 183 static int remember_delete(struct file_struct *file, c
|
| deldelay_buf[deldelay_cnt++] = '!'; |
deldelay_buf[deldelay_cnt++] = '!'; |
| |
|
| while (1) { |
while (1) { |
| len = snprintf(deldelay_buf + deldelay_cnt, | len = snprintf(deldelay_buf + deldelay_cnt, deldelay_size - deldelay_cnt, |
| deldelay_size - deldelay_cnt, | "%x %s%c", (int)file->mode, fname, '\0'); |
| "%x %s%c", | |
| (int)file->mode, fname, '\0'); | |
| if ((deldelay_cnt += len) <= deldelay_size) |
if ((deldelay_cnt += len) <= deldelay_size) |
| break; |
break; |
| deldelay_cnt -= len; |
deldelay_cnt -= len; |
|
Line 395 static int read_delay_line(char *buf, int *flags_p)
|
Line 221 static int read_delay_line(char *buf, int *flags_p)
|
| deldelay_size - deldelay_cnt); |
deldelay_size - deldelay_cnt); |
| if (len == 0) { |
if (len == 0) { |
| if (deldelay_cnt) { |
if (deldelay_cnt) { |
| rprintf(FERROR, | rprintf(FERROR, "ERROR: unexpected EOF in delete-delay file.\n"); |
| "ERROR: unexpected EOF in delete-delay file.\n"); | |
| } |
} |
| return -1; |
return -1; |
| } |
} |
|
Line 456 static void do_delayed_deletions(char *delbuf)
|
Line 281 static void do_delayed_deletions(char *delbuf)
|
| * all the --delete-WHEN options. Note that the fbuf pointer must point to a |
* all the --delete-WHEN options. Note that the fbuf pointer must point to a |
| * MAXPATHLEN buffer with the name of the directory in it (the functions we |
* MAXPATHLEN buffer with the name of the directory in it (the functions we |
| * call will append names onto the end, but the old dir value will be restored |
* call will append names onto the end, but the old dir value will be restored |
| * on exit). */ | * on exit). |
| static void delete_in_dir(char *fbuf, struct file_struct *file, dev_t *fs_dev) | * |
| | * Note: --detect-rename may use this routine with DEL_NO_DELETIONS set! |
| | */ |
| | static void delete_in_dir(char *fbuf, struct file_struct *file, dev_t *fs_dev, |
| | int del_flags) |
| { |
{ |
| static int already_warned = 0; |
static int already_warned = 0; |
| |
static struct hashtable *dev_tbl; |
| struct file_list *dirlist; |
struct file_list *dirlist; |
| char delbuf[MAXPATHLEN]; | char *p, delbuf[MAXPATHLEN]; |
| int dlen, i; | unsigned remainder; |
| | int dlen, i, restore_dot = 0; |
| |
|
| if (!fbuf) { |
if (!fbuf) { |
| change_local_filter_dir(NULL, 0, 0); |
change_local_filter_dir(NULL, 0, 0); |
| return; |
return; |
| } |
} |
| |
|
| if (verbose > 2) | if (DEBUG_GTE(DEL, 2)) |
| rprintf(FINFO, "delete_in_dir(%s)\n", fbuf); |
rprintf(FINFO, "delete_in_dir(%s)\n", fbuf); |
| |
|
| if (allowed_lull) |
if (allowed_lull) |
| maybe_send_keepalive(); | maybe_send_keepalive(time(NULL), MSK_ALLOW_FLUSH); |
| |
|
| if (io_error && !ignore_errors) { | if (io_error & IOERR_GENERAL && !ignore_errors) { |
| if (already_warned) | if (!already_warned) { |
| | rprintf(FINFO, |
| | "IO error encountered -- skipping file deletion\n"); |
| | already_warned = 1; |
| | } |
| | if (!detect_renamed) |
| return; |
return; |
| rprintf(FINFO, | del_flags |= DEL_NO_DELETIONS; |
| "IO error encountered -- skipping file deletion\n"); | |
| already_warned = 1; | |
| return; | |
| } |
} |
| |
|
| dlen = strlen(fbuf); |
dlen = strlen(fbuf); |
| change_local_filter_dir(fbuf, dlen, F_DEPTH(file)); |
change_local_filter_dir(fbuf, dlen, F_DEPTH(file)); |
| |
|
| |
if (detect_renamed) |
| |
unexplored_dirs--; |
| |
|
| if (one_file_system) { |
if (one_file_system) { |
| if (file->flags & FLAG_TOP_DIR) | if (!dev_tbl) |
| | dev_tbl = hashtable_create(16, HT_KEY64); |
| | if (file->flags & FLAG_TOP_DIR) { |
| | hashtable_find(dev_tbl, *fs_dev+1, ""); |
| filesystem_dev = *fs_dev; |
filesystem_dev = *fs_dev; |
| else if (filesystem_dev != *fs_dev) | } else if (filesystem_dev != *fs_dev) { |
| return; | if (!hashtable_find(dev_tbl, *fs_dev+1, NULL)) |
| | return; |
| | filesystem_dev = *fs_dev; /* it's a prior top-dir dev */ |
| | } |
| } |
} |
| |
|
| dirlist = get_dirlist(fbuf, dlen, 0); |
dirlist = get_dirlist(fbuf, dlen, 0); |
| |
|
| |
p = fbuf + dlen; |
| |
if (dlen == 1 && *fbuf == '.') { |
| |
restore_dot = 1; |
| |
p = fbuf; |
| |
} else if (dlen != 1 || *fbuf != '/') |
| |
*p++ = '/'; |
| |
remainder = MAXPATHLEN - (p - fbuf); |
| |
|
| /* If an item in dirlist is not found in flist, delete it |
/* If an item in dirlist is not found in flist, delete it |
| * from the filesystem. */ |
* from the filesystem. */ |
| for (i = dirlist->used; i--; ) { |
for (i = dirlist->used; i--; ) { |
|
Line 503 static void delete_in_dir(char *fbuf, struct file_stru
|
Line 353 static void delete_in_dir(char *fbuf, struct file_stru
|
| if (!F_IS_ACTIVE(fp)) |
if (!F_IS_ACTIVE(fp)) |
| continue; |
continue; |
| if (fp->flags & FLAG_MOUNT_DIR && S_ISDIR(fp->mode)) { |
if (fp->flags & FLAG_MOUNT_DIR && S_ISDIR(fp->mode)) { |
| if (verbose > 1) | if (INFO_GTE(MOUNT, 1)) |
| rprintf(FINFO, "cannot delete mount point: %s\n", |
rprintf(FINFO, "cannot delete mount point: %s\n", |
| f_name(fp, NULL)); |
f_name(fp, NULL)); |
| continue; |
continue; |
| } |
} |
| |
if (detect_renamed && S_ISREG(fp->mode)) { |
| |
strlcpy(p, fp->basename, remainder); |
| |
look_for_rename(fp, fbuf); |
| |
} |
| /* Here we want to match regardless of file type. Replacement |
/* Here we want to match regardless of file type. Replacement |
| * of a file with one of another type is handled separately by |
* of a file with one of another type is handled separately by |
| * a delete_item call with a DEL_MAKE_ROOM flag. */ |
* a delete_item call with a DEL_MAKE_ROOM flag. */ |
|
Line 516 static void delete_in_dir(char *fbuf, struct file_stru
|
Line 370 static void delete_in_dir(char *fbuf, struct file_stru
|
| if (!(fp->mode & S_IWUSR) && !am_root && fp->flags & FLAG_OWNED_BY_US) |
if (!(fp->mode & S_IWUSR) && !am_root && fp->flags & FLAG_OWNED_BY_US) |
| flags |= DEL_NO_UID_WRITE; |
flags |= DEL_NO_UID_WRITE; |
| f_name(fp, delbuf); |
f_name(fp, delbuf); |
| if (delete_during == 2) { | if (delete_during == 2 && !(del_flags & DEL_NO_DELETIONS)) { |
| if (!remember_delete(fp, delbuf, flags)) | if (!remember_delete(fp, delbuf, del_flags | flags)) |
| break; |
break; |
| } else |
} else |
| delete_item(delbuf, fp->mode, flags); | delete_item(delbuf, fp->mode, del_flags | flags); |
| } | } else if (detect_renamed && S_ISDIR(fp->mode)) |
| | unexplored_dirs++; |
| } |
} |
| |
|
| |
if (restore_dot) |
| |
fbuf[0] = '.'; |
| |
fbuf[dlen] = '\0'; |
| |
|
| flist_free(dirlist); |
flist_free(dirlist); |
| } |
} |
| |
|
|
Line 542 static void do_delete_pass(void)
|
Line 401 static void do_delete_pass(void)
|
| for (j = 0; j < cur_flist->used; j++) { |
for (j = 0; j < cur_flist->used; j++) { |
| struct file_struct *file = cur_flist->sorted[j]; |
struct file_struct *file = cur_flist->sorted[j]; |
| |
|
| |
if (!F_IS_ACTIVE(file)) |
| |
continue; |
| |
|
| f_name(file, fbuf); |
f_name(file, fbuf); |
| |
|
| if (!(file->flags & FLAG_CONTENT_DIR)) { |
if (!(file->flags & FLAG_CONTENT_DIR)) { |
|
Line 549 static void do_delete_pass(void)
|
Line 411 static void do_delete_pass(void)
|
| continue; |
continue; |
| } |
} |
| |
|
| if (verbose > 1 && file->flags & FLAG_TOP_DIR) | if (DEBUG_GTE(DEL, 1) && file->flags & FLAG_TOP_DIR) |
| rprintf(FINFO, "deleting in %s\n", fbuf); |
rprintf(FINFO, "deleting in %s\n", fbuf); |
| |
|
| if (link_stat(fbuf, &st, keep_dirlinks) < 0 |
if (link_stat(fbuf, &st, keep_dirlinks) < 0 |
| || !S_ISDIR(st.st_mode)) |
|| !S_ISDIR(st.st_mode)) |
| continue; |
continue; |
| |
|
| delete_in_dir(fbuf, file, &st.st_dev); | delete_in_dir(fbuf, file, &st.st_dev, 0); |
| } |
} |
| delete_in_dir(NULL, NULL, &dev_zero); | delete_in_dir(NULL, NULL, &dev_zero, 0); |
| |
|
| if (do_progress && !am_server) | if (INFO_GTE(FLIST, 2) && !am_server) |
| rprintf(FINFO, " \r"); |
rprintf(FINFO, " \r"); |
| } |
} |
| |
|
| static inline int time_differs(struct file_struct *file, stat_x *sxp) | /* Search for a regular file that matches either (1) the size & modified |
| | * time (plus the basename, if possible) or (2) the size & checksum. If |
| | * we find an exact match down to the dirname, return -1 because we found |
| | * an up-to-date file in the transfer, not a renamed file. */ |
| | static int fattr_find(struct file_struct *f, char *fname) |
| { |
{ |
| return cmp_time(sxp->st.st_mtime, file->modtime); | int low = the_fattr_list.low, high = the_fattr_list.high; |
| | int mid, ok_match = -1, good_match = -1; |
| | struct file_struct *fmid; |
| | int diff; |
| | |
| | while (low <= high) { |
| | mid = (low + high) / 2; |
| | fmid = the_fattr_list.files[mid]; |
| | if (F_LENGTH(fmid) != F_LENGTH(f)) { |
| | if (F_LENGTH(fmid) < F_LENGTH(f)) |
| | low = mid + 1; |
| | else |
| | high = mid - 1; |
| | continue; |
| | } |
| | if (always_checksum) { |
| | /* We use the FLAG_FILE_SENT flag to indicate when we |
| | * have computed the checksum for an entry. */ |
| | if (!(f->flags & FLAG_FILE_SENT)) { |
| | STRUCT_STAT st; |
| | if (fmid->modtime == f->modtime |
| | && f_name_cmp(fmid, f) == 0) |
| | return -1; /* assume we can't help */ |
| | st.st_size = F_LENGTH(f); |
| | st.st_mtime = f->modtime; |
| | file_checksum(fname, &st, F_SUM(f)); |
| | f->flags |= FLAG_FILE_SENT; |
| | } |
| | diff = u_memcmp(F_SUM(fmid), F_SUM(f), flist_csum_len); |
| | if (diff) { |
| | if (diff < 0) |
| | low = mid + 1; |
| | else |
| | high = mid - 1; |
| | continue; |
| | } |
| | } else { |
| | if (fmid->modtime != f->modtime) { |
| | if (fmid->modtime < f->modtime) |
| | low = mid + 1; |
| | else |
| | high = mid - 1; |
| | continue; |
| | } |
| | } |
| | ok_match = mid; |
| | diff = u_strcmp(fmid->basename, f->basename); |
| | if (diff == 0) { |
| | good_match = mid; |
| | if (fmid->dirname == f->dirname) |
| | return -1; /* file is up-to-date */ |
| | if (!fmid->dirname) { |
| | low = mid + 1; |
| | continue; |
| | } |
| | if (!f->dirname) { |
| | high = mid - 1; |
| | continue; |
| | } |
| | diff = u_strcmp(fmid->dirname, f->dirname); |
| | if (diff == 0) |
| | return -1; /* file is up-to-date */ |
| | } |
| | if (diff < 0) |
| | low = mid + 1; |
| | else |
| | high = mid - 1; |
| | } |
| | |
| | return good_match >= 0 ? good_match : ok_match; |
| } |
} |
| |
|
| |
void look_for_rename(struct file_struct *file, char *fname) |
| |
{ |
| |
struct file_struct *fp; |
| |
char *partialptr, *fn; |
| |
STRUCT_STAT st; |
| |
int ndx; |
| |
|
| |
if (!partial_dir || (ndx = fattr_find(file, fname)) < 0) |
| |
return; |
| |
|
| |
fp = the_fattr_list.files[ndx]; |
| |
fn = f_name(fp, NULL); |
| |
/* We don't provide an alternate-basis file if there is a basis file. */ |
| |
if (link_stat(fn, &st, 0) == 0) |
| |
return; |
| |
|
| |
if (!dry_run) { |
| |
if ((partialptr = partial_dir_fname(fn)) == NULL |
| |
|| !handle_partial_dir(partialptr, PDIR_CREATE)) |
| |
return; |
| |
/* We only use the file if we can hard-link it into our tmp dir. */ |
| |
if (link(fname, partialptr) != 0) { |
| |
if (errno != EEXIST) |
| |
handle_partial_dir(partialptr, PDIR_DELETE); |
| |
return; |
| |
} |
| |
} |
| |
|
| |
/* I think this falls into the -vv category with "%s is uptodate", etc. */ |
| |
if (INFO_GTE(MISC, 2)) |
| |
rprintf(FINFO, "found renamed: %s => %s\n", fname, fn); |
| |
} |
| |
|
| |
static inline int mtime_differs(STRUCT_STAT *stp, struct file_struct *file) |
| |
{ |
| |
#ifdef ST_MTIME_NSEC |
| |
return !same_time(stp->st_mtime, stp->ST_MTIME_NSEC, file->modtime, F_MOD_NSEC_or_0(file)); |
| |
#else |
| |
return !same_time(stp->st_mtime, 0, file->modtime, 0); |
| |
#endif |
| |
} |
| |
|
| |
static inline int any_time_differs(stat_x *sxp, struct file_struct *file, UNUSED(const char *fname)) |
| |
{ |
| |
int differs = mtime_differs(&sxp->st, file); |
| |
#ifdef SUPPORT_CRTIMES |
| |
if (!differs && crtimes_ndx) { |
| |
if (sxp->crtime == 0) |
| |
sxp->crtime = get_create_time(fname); |
| |
differs = !same_time(sxp->crtime, 0, F_CRTIME(file), 0); |
| |
} |
| |
#endif |
| |
return differs; |
| |
} |
| |
|
| static inline int perms_differ(struct file_struct *file, stat_x *sxp) |
static inline int perms_differ(struct file_struct *file, stat_x *sxp) |
| { |
{ |
| if (preserve_perms) |
if (preserve_perms) |
|
Line 623 int unchanged_attrs(const char *fname, struct file_str
|
Line 613 int unchanged_attrs(const char *fname, struct file_str
|
| { |
{ |
| if (S_ISLNK(file->mode)) { |
if (S_ISLNK(file->mode)) { |
| #ifdef CAN_SET_SYMLINK_TIMES |
#ifdef CAN_SET_SYMLINK_TIMES |
| if (preserve_times & PRESERVE_LINK_TIMES && time_differs(file, sxp)) | if (preserve_times & PRESERVE_LINK_TIMES && any_time_differs(sxp, file, fname)) |
| return 0; |
return 0; |
| #endif |
#endif |
| #ifdef CAN_CHMOD_SYMLINK |
#ifdef CAN_CHMOD_SYMLINK |
|
Line 643 int unchanged_attrs(const char *fname, struct file_str
|
Line 633 int unchanged_attrs(const char *fname, struct file_str
|
| return 0; |
return 0; |
| #endif |
#endif |
| } else { |
} else { |
| if (preserve_times && time_differs(file, sxp)) | if (preserve_times && any_time_differs(sxp, file, fname)) |
| return 0; |
return 0; |
| if (perms_differ(file, sxp)) |
if (perms_differ(file, sxp)) |
| return 0; |
return 0; |
| |
#ifdef SUPPORT_FILEFLAGS |
| |
if (preserve_fileflags && sxp->st.st_flags != F_FFLAGS(file)) |
| |
return 0; |
| |
#endif |
| if (ownership_differs(file, sxp)) |
if (ownership_differs(file, sxp)) |
| return 0; |
return 0; |
| #ifdef SUPPORT_ACLS |
#ifdef SUPPORT_ACLS |
|
Line 667 void itemize(const char *fnamecmp, struct file_struct
|
Line 661 void itemize(const char *fnamecmp, struct file_struct
|
| const char *xname) |
const char *xname) |
| { |
{ |
| if (statret >= 0) { /* A from-dest-dir statret can == 1! */ |
if (statret >= 0) { /* A from-dest-dir statret can == 1! */ |
| |
int omit_changes = omit_dir_changes && S_ISDIR(sxp->st.st_mode); |
| int keep_time = !preserve_times ? 0 |
int keep_time = !preserve_times ? 0 |
| : S_ISDIR(file->mode) ? preserve_times & PRESERVE_DIR_TIMES |
: S_ISDIR(file->mode) ? preserve_times & PRESERVE_DIR_TIMES |
| : S_ISLNK(file->mode) ? preserve_times & PRESERVE_LINK_TIMES |
: S_ISLNK(file->mode) ? preserve_times & PRESERVE_LINK_TIMES |
|
Line 678 void itemize(const char *fnamecmp, struct file_struct
|
Line 673 void itemize(const char *fnamecmp, struct file_struct
|
| if (iflags & ITEM_LOCAL_CHANGE) |
if (iflags & ITEM_LOCAL_CHANGE) |
| iflags |= symlink_timeset_failed_flags; |
iflags |= symlink_timeset_failed_flags; |
| } else if (keep_time |
} else if (keep_time |
| ? cmp_time(file->modtime, sxp->st.st_mtime) != 0 | ? mtime_differs(&sxp->st, file) |
| : iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !(iflags & ITEM_MATCHED) |
: iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !(iflags & ITEM_MATCHED) |
| && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname)) |
&& (!(iflags & ITEM_XNAME_FOLLOWS) || *xname)) |
| iflags |= ITEM_REPORT_TIME; |
iflags |= ITEM_REPORT_TIME; |
| |
if (atimes_ndx && !S_ISDIR(file->mode) && !S_ISLNK(file->mode) |
| |
&& !same_time(F_ATIME(file), 0, sxp->st.st_atime, 0)) |
| |
iflags |= ITEM_REPORT_ATIME; |
| |
#ifdef SUPPORT_CRTIMES |
| |
if (crtimes_ndx) { |
| |
if (sxp->crtime == 0) |
| |
sxp->crtime = get_create_time(fnamecmp); |
| |
if (!same_time(sxp->crtime, 0, F_CRTIME(file), 0)) |
| |
iflags |= ITEM_REPORT_CRTIME; |
| |
} |
| |
#endif |
| #if !defined HAVE_LCHMOD && !defined HAVE_SETATTRLIST |
#if !defined HAVE_LCHMOD && !defined HAVE_SETATTRLIST |
| if (S_ISLNK(file->mode)) { |
if (S_ISLNK(file->mode)) { |
| ; |
; |
|
Line 693 void itemize(const char *fnamecmp, struct file_struct
|
Line 699 void itemize(const char *fnamecmp, struct file_struct
|
| } else if (preserve_executability |
} else if (preserve_executability |
| && ((sxp->st.st_mode & 0111 ? 1 : 0) ^ (file->mode & 0111 ? 1 : 0))) |
&& ((sxp->st.st_mode & 0111 ? 1 : 0) ^ (file->mode & 0111 ? 1 : 0))) |
| iflags |= ITEM_REPORT_PERMS; |
iflags |= ITEM_REPORT_PERMS; |
| if (uid_ndx && am_root && (uid_t)F_OWNER(file) != sxp->st.st_uid) | if (uid_ndx && am_root && !omit_changes && (uid_t)F_OWNER(file) != sxp->st.st_uid) |
| iflags |= ITEM_REPORT_OWNER; |
iflags |= ITEM_REPORT_OWNER; |
| if (gid_ndx && !(file->flags & FLAG_SKIP_GROUP) | if (gid_ndx && !omit_changes && !(file->flags & FLAG_SKIP_GROUP) && sxp->st.st_gid != (gid_t)F_GROUP(file)) |
| && sxp->st.st_gid != (gid_t)F_GROUP(file)) | |
| iflags |= ITEM_REPORT_GROUP; |
iflags |= ITEM_REPORT_GROUP; |
| |
#ifdef SUPPORT_FILEFLAGS |
| |
if (preserve_fileflags && !S_ISLNK(file->mode) |
| |
&& sxp->st.st_flags != F_FFLAGS(file)) |
| |
iflags |= ITEM_REPORT_FFLAGS; |
| |
#endif |
| #ifdef SUPPORT_ACLS |
#ifdef SUPPORT_ACLS |
| if (preserve_acls && !S_ISLNK(file->mode)) { |
if (preserve_acls && !S_ISLNK(file->mode)) { |
| if (!ACL_READY(*sxp)) |
if (!ACL_READY(*sxp)) |
|
Line 723 void itemize(const char *fnamecmp, struct file_struct
|
Line 733 void itemize(const char *fnamecmp, struct file_struct
|
| } |
} |
| |
|
| iflags &= 0xffff; |
iflags &= 0xffff; |
| if ((iflags & (SIGNIFICANT_ITEM_FLAGS|ITEM_REPORT_XATTR) || verbose > 1 | if ((iflags & (SIGNIFICANT_ITEM_FLAGS|ITEM_REPORT_XATTR) || INFO_GTE(NAME, 2) |
| || stdout_format_has_i > 1 || (xname && *xname)) && !read_batch) { |
|| stdout_format_has_i > 1 || (xname && *xname)) && !read_batch) { |
| if (protocol_version >= 29) { |
if (protocol_version >= 29) { |
| if (ndx >= 0) |
if (ndx >= 0) |
|
Line 736 void itemize(const char *fnamecmp, struct file_struct
|
Line 746 void itemize(const char *fnamecmp, struct file_struct
|
| #ifdef SUPPORT_XATTRS |
#ifdef SUPPORT_XATTRS |
| if (preserve_xattrs && do_xfers |
if (preserve_xattrs && do_xfers |
| && iflags & (ITEM_REPORT_XATTR|ITEM_TRANSFER)) { |
&& iflags & (ITEM_REPORT_XATTR|ITEM_TRANSFER)) { |
| send_xattr_request(NULL, file, | int fd = iflags & ITEM_REPORT_XATTR |
| iflags & ITEM_REPORT_XATTR ? sock_f_out : -1); | && !(want_xattr_optim && BITS_SET(iflags, ITEM_XNAME_FOLLOWS|ITEM_LOCAL_CHANGE)) |
| | ? sock_f_out : -1; |
| | send_xattr_request(NULL, file, fd); |
| } |
} |
| #endif |
#endif |
| } else if (ndx >= 0) { |
} else if (ndx >= 0) { |
| enum logcode code = logfile_format_has_i ? FINFO : FCLIENT; |
enum logcode code = logfile_format_has_i ? FINFO : FCLIENT; |
| log_item(code, file, &stats, iflags, xname); | log_item(code, file, iflags, xname); |
| } |
} |
| } |
} |
| } |
} |
| |
|
| |
|
| /* Perform our quick-check heuristic for determining if a file is unchanged. */ |
/* Perform our quick-check heuristic for determining if a file is unchanged. */ |
| int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st) | int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st, int slot) |
| { |
{ |
| |
if (date_only) |
| |
return !mtime_differs(st, file); |
| |
|
| if (st->st_size != F_LENGTH(file)) |
if (st->st_size != F_LENGTH(file)) |
| return 0; |
return 0; |
| |
|
|
Line 758 int unchanged_file(char *fn, struct file_struct *file,
|
Line 773 int unchanged_file(char *fn, struct file_struct *file,
|
| of the file time to determine whether to sync */ |
of the file time to determine whether to sync */ |
| if (always_checksum > 0 && S_ISREG(st->st_mode)) { |
if (always_checksum > 0 && S_ISREG(st->st_mode)) { |
| char sum[MAX_DIGEST_LEN]; |
char sum[MAX_DIGEST_LEN]; |
| file_checksum(fn, sum, st->st_size); | if (checksum_files && slot >= 0) |
| return memcmp(sum, F_SUM(file), checksum_len) == 0; | get_cached_checksum(slot, fn, file, -1, st, sum); |
| | else |
| | file_checksum(fn, st, sum); |
| | return memcmp(sum, F_SUM(file), flist_csum_len) == 0; |
| } |
} |
| |
|
| if (size_only > 0) |
if (size_only > 0) |
|
Line 768 int unchanged_file(char *fn, struct file_struct *file,
|
Line 786 int unchanged_file(char *fn, struct file_struct *file,
|
| if (ignore_times) |
if (ignore_times) |
| return 0; |
return 0; |
| |
|
| return cmp_time(st->st_mtime, file->modtime) == 0; | return !mtime_differs(st, file); |
| } |
} |
| |
|
| |
|
|
Line 813 static void sum_sizes_sqroot(struct sum_struct *sum, i
|
Line 831 static void sum_sizes_sqroot(struct sum_struct *sum, i
|
| if (c < 0 || c >= max_blength) |
if (c < 0 || c >= max_blength) |
| blength = max_blength; |
blength = max_blength; |
| else { |
else { |
| blength = 0; | blength = 0; |
| do { | do { |
| blength |= c; | blength |= c; |
| if (len < (int64)blength * blength) | if (len < (int64)blength * blength) |
| blength &= ~c; | blength &= ~c; |
| c >>= 1; | c >>= 1; |
| } while (c >= 8); /* round to multiple of 8 */ | } while (c >= 8); /* round to multiple of 8 */ |
| blength = MAX(blength, BLOCK_SIZE); | blength = MAX(blength, BLOCK_SIZE); |
| } |
} |
| } |
} |
| |
|
|
Line 848 static void sum_sizes_sqroot(struct sum_struct *sum, i
|
Line 866 static void sum_sizes_sqroot(struct sum_struct *sum, i
|
| if ((int64)sum->count != l) |
if ((int64)sum->count != l) |
| sum->count = -1; |
sum->count = -1; |
| |
|
| if (sum->count && verbose > 2) { | if (sum->count && DEBUG_GTE(DELTASUM, 2)) { |
| rprintf(FINFO, |
rprintf(FINFO, |
| "count=%.0f rem=%ld blength=%ld s2length=%d flength=%.0f\n", | "count=%s rem=%ld blength=%ld s2length=%d flength=%s\n", |
| (double)sum->count, (long)sum->remainder, (long)sum->blength, | big_num(sum->count), (long)sum->remainder, (long)sum->blength, |
| sum->s2length, (double)sum->flength); | sum->s2length, big_num(sum->flength)); |
| } |
} |
| } |
} |
| |
|
|
Line 877 static int generate_and_send_sums(int fd, OFF_T len, i
|
Line 895 static int generate_and_send_sums(int fd, OFF_T len, i
|
| if (append_mode > 0 && f_copy < 0) |
if (append_mode > 0 && f_copy < 0) |
| return 0; |
return 0; |
| |
|
| if (len > 0) | if (len > 0) { |
| mapbuf = map_file(fd, len, MAX_MAP_SIZE, sum.blength); |
mapbuf = map_file(fd, len, MAX_MAP_SIZE, sum.blength); |
| else | checksum2_enable_prefetch(mapbuf, len, sum.blength); |
| | } else { |
| mapbuf = NULL; |
mapbuf = NULL; |
| |
} |
| |
|
| for (i = 0; i < sum.count; i++) { |
for (i = 0; i < sum.count; i++) { |
| int32 n1 = (int32)MIN(len, (OFF_T)sum.blength); |
int32 n1 = (int32)MIN(len, (OFF_T)sum.blength); |
|
Line 898 static int generate_and_send_sums(int fd, OFF_T len, i
|
Line 918 static int generate_and_send_sums(int fd, OFF_T len, i
|
| } |
} |
| |
|
| sum1 = get_checksum1(map, n1); |
sum1 = get_checksum1(map, n1); |
| get_checksum2(map, n1, sum2); | get_checksum2(map, n1, sum2, offset - n1); |
| |
|
| if (verbose > 3) { | if (DEBUG_GTE(DELTASUM, 3)) { |
| rprintf(FINFO, |
rprintf(FINFO, |
| "chunk[%.0f] offset=%.0f len=%ld sum1=%08lx\n", | "chunk[%s] offset=%s len=%ld sum1=%08lx\n", |
| (double)i, (double)offset - n1, (long)n1, | big_num(i), big_num(offset - n1), (long)n1, |
| (unsigned long)sum1); |
(unsigned long)sum1); |
| } |
} |
| write_int(f_out, sum1); |
write_int(f_out, sum1); |
| write_buf(f_out, sum2, sum.s2length); |
write_buf(f_out, sum2, sum.s2length); |
| } |
} |
| |
|
| if (mapbuf) | if (mapbuf) { |
| unmap_file(mapbuf); |
unmap_file(mapbuf); |
| |
checksum2_disable_prefetch(); |
| |
} |
| |
|
| return 0; |
return 0; |
| } |
} |
| |
|
| |
|
| /* Try to find a filename in the same dir as "fname" with a similar name. */ |
/* Try to find a filename in the same dir as "fname" with a similar name. */ |
| static int find_fuzzy(struct file_struct *file, struct file_list *dirlist) | static struct file_struct *find_fuzzy(struct file_struct *file, struct file_list *dirlist_array[], uchar *fnamecmp_type_ptr) |
| { |
{ |
| int fname_len, fname_suf_len; |
int fname_len, fname_suf_len; |
| const char *fname_suf, *fname = file->basename; |
const char *fname_suf, *fname = file->basename; |
| uint32 lowest_dist = 25 << 16; /* ignore a distance greater than 25 */ |
uint32 lowest_dist = 25 << 16; /* ignore a distance greater than 25 */ |
| int j, lowest_j = -1; | int i, j; |
| | struct file_struct *lowest_fp = NULL; |
| |
|
| fname_len = strlen(fname); |
fname_len = strlen(fname); |
| fname_suf = find_filename_suffix(fname, fname_len, &fname_suf_len); |
fname_suf = find_filename_suffix(fname, fname_len, &fname_suf_len); |
| |
|
| for (j = 0; j < dirlist->used; j++) { | /* Try to find an exact size+mtime match first. */ |
| struct file_struct *fp = dirlist->files[j]; | for (i = 0; i < fuzzy_basis; i++) { |
| const char *suf, *name; | struct file_list *dirlist = dirlist_array[i]; |
| int len, suf_len; | |
| uint32 dist; | |
| |
|
| if (!S_ISREG(fp->mode) || !F_LENGTH(fp) | if (!dirlist) |
| || fp->flags & FLAG_FILE_SENT) | |
| continue; |
continue; |
| |
|
| name = fp->basename; | for (j = 0; j < dirlist->used; j++) { |
| | struct file_struct *fp = dirlist->files[j]; |
| |
|
| if (F_LENGTH(fp) == F_LENGTH(file) | if (!F_IS_ACTIVE(fp)) |
| && cmp_time(fp->modtime, file->modtime) == 0) { | continue; |
| if (verbose > 4) { | |
| rprintf(FINFO, | if (!S_ISREG(fp->mode) || !F_LENGTH(fp) || fp->flags & FLAG_FILE_SENT) |
| "fuzzy size/modtime match for %s\n", | continue; |
| name); | |
| | if (F_LENGTH(fp) == F_LENGTH(file) && same_time(fp->modtime, 0, file->modtime, 0)) { |
| | if (DEBUG_GTE(FUZZY, 2)) |
| | rprintf(FINFO, "fuzzy size/modtime match for %s\n", f_name(fp, NULL)); |
| | *fnamecmp_type_ptr = FNAMECMP_FUZZY + i; |
| | return fp; |
| } |
} |
| return j; | |
| } |
} |
| |
} |
| |
|
| len = strlen(name); | for (i = 0; i < fuzzy_basis; i++) { |
| suf = find_filename_suffix(name, len, &suf_len); | struct file_list *dirlist = dirlist_array[i]; |
| |
|
| dist = fuzzy_distance(name, len, fname, fname_len); | if (!dirlist) |
| /* Add some extra weight to how well the suffixes match. */ | continue; |
| dist += fuzzy_distance(suf, suf_len, fname_suf, fname_suf_len) | |
| * 10; | for (j = 0; j < dirlist->used; j++) { |
| if (verbose > 4) { | struct file_struct *fp = dirlist->files[j]; |
| rprintf(FINFO, "fuzzy distance for %s = %d.%05d\n", | const char *suf, *name; |
| name, (int)(dist>>16), (int)(dist&0xFFFF)); | int len, suf_len; |
| | uint32 dist; |
| | |
| | if (!F_IS_ACTIVE(fp)) |
| | continue; |
| | |
| | if (!S_ISREG(fp->mode) || !F_LENGTH(fp) || fp->flags & FLAG_FILE_SENT) |
| | continue; |
| | |
| | name = fp->basename; |
| | len = strlen(name); |
| | suf = find_filename_suffix(name, len, &suf_len); |
| | |
| | dist = fuzzy_distance(name, len, fname, fname_len); |
| | /* Add some extra weight to how well the suffixes match. */ |
| | dist += fuzzy_distance(suf, suf_len, fname_suf, fname_suf_len) * 10; |
| | if (DEBUG_GTE(FUZZY, 2)) { |
| | rprintf(FINFO, "fuzzy distance for %s = %d.%05d\n", |
| | f_name(fp, NULL), (int)(dist>>16), (int)(dist&0xFFFF)); |
| | } |
| | if (dist <= lowest_dist) { |
| | lowest_dist = dist; |
| | lowest_fp = fp; |
| | *fnamecmp_type_ptr = FNAMECMP_FUZZY + i; |
| | } |
| } |
} |
| if (dist <= lowest_dist) { |
|
| lowest_dist = dist; |
|
| lowest_j = j; |
|
| } |
|
| } |
} |
| |
|
| return lowest_j; | return lowest_fp; |
| } |
} |
| |
|
| /* Copy a file found in our --copy-dest handling. */ |
/* Copy a file found in our --copy-dest handling. */ |
|
Line 989 static int copy_altdest_file(const char *src, const ch
|
Line 1036 static int copy_altdest_file(const char *src, const ch
|
| copy_to = buf; |
copy_to = buf; |
| } |
} |
| cleanup_set(copy_to, NULL, NULL, -1, -1); |
cleanup_set(copy_to, NULL, NULL, -1, -1); |
| if (copy_file(src, copy_to, fd_w, file->mode, 0) < 0) { | if (copy_file(src, copy_to, fd_w, file->mode) < 0) { |
| if (verbose) { | if (INFO_GTE(COPY, 1)) { |
| rsyserr(FINFO, errno, "copy_file %s => %s", |
rsyserr(FINFO, errno, "copy_file %s => %s", |
| full_fname(src), copy_to); |
full_fname(src), copy_to); |
| } |
} |
|
Line 1009 static int copy_altdest_file(const char *src, const ch
|
Line 1056 static int copy_altdest_file(const char *src, const ch
|
| |
|
| /* This is only called for regular files. We return -2 if we've finished |
/* This is only called for regular files. We return -2 if we've finished |
| * handling the file, -1 if no dest-linking occurred, or a non-negative |
* handling the file, -1 if no dest-linking occurred, or a non-negative |
| * value if we found an alternate basis file. */ | * value if we found an alternate basis file. If we're called with the |
| | * find_exact_for_existing flag, the destination file already exists, so |
| | * we only try to find an exact alt-dest match. In this case, the returns |
| | * are only -2 & -1 (both as above). */ |
| static int try_dests_reg(struct file_struct *file, char *fname, int ndx, |
static int try_dests_reg(struct file_struct *file, char *fname, int ndx, |
| char *cmpbuf, stat_x *sxp, int itemizing, | char *cmpbuf, stat_x *sxp, int find_exact_for_existing, |
| enum logcode code) | int itemizing, enum logcode code) |
| { |
{ |
| |
STRUCT_STAT real_st = sxp->st; |
| int best_match = -1; |
int best_match = -1; |
| int match_level = 0; |
int match_level = 0; |
| int j = 0; |
int j = 0; |
|
Line 1022 static int try_dests_reg(struct file_struct *file, cha
|
Line 1073 static int try_dests_reg(struct file_struct *file, cha
|
| pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname); |
pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname); |
| if (link_stat(cmpbuf, &sxp->st, 0) < 0 || !S_ISREG(sxp->st.st_mode)) |
if (link_stat(cmpbuf, &sxp->st, 0) < 0 || !S_ISREG(sxp->st.st_mode)) |
| continue; |
continue; |
| switch (match_level) { | if (match_level == 0) { |
| case 0: | |
| best_match = j; |
best_match = j; |
| match_level = 1; |
match_level = 1; |
| /* FALL THROUGH */ | } |
| case 1: | if (!unchanged_file(cmpbuf, file, &sxp->st, j+1)) |
| if (!unchanged_file(cmpbuf, file, &sxp->st)) | continue; |
| continue; | if (match_level == 1) { |
| best_match = j; |
best_match = j; |
| match_level = 2; |
match_level = 2; |
| /* FALL THROUGH */ | } |
| case 2: | if (alt_dest_type == CLONE_DEST || unchanged_attrs(cmpbuf, file, sxp)) { |
| if (!unchanged_attrs(cmpbuf, file, sxp)) | |
| continue; | |
| best_match = j; |
best_match = j; |
| match_level = 3; |
match_level = 3; |
| break; |
break; |
| } |
} |
| break; | free_stat_x(sxp); |
| } while (basis_dir[++j] != NULL); |
} while (basis_dir[++j] != NULL); |
| |
|
| if (!match_level) |
if (!match_level) |
| return -1; | goto got_nothing_for_ya; |
| |
|
| if (j != best_match) { |
if (j != best_match) { |
| j = best_match; |
j = best_match; |
| pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname); |
pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname); |
| if (link_stat(cmpbuf, &sxp->st, 0) < 0) |
if (link_stat(cmpbuf, &sxp->st, 0) < 0) |
| return -1; | goto got_nothing_for_ya; |
| } |
} |
| |
|
| if (match_level == 3 && !copy_dest) { | if (match_level == 3 && alt_dest_type != COPY_DEST) { |
| | if (find_exact_for_existing) { |
| | if (alt_dest_type == LINK_DEST && real_st.st_dev == sxp->st.st_dev && real_st.st_ino == sxp->st.st_ino) |
| | return -1; |
| | if (do_unlink(fname) < 0 && errno != ENOENT) |
| | goto got_nothing_for_ya; |
| | } |
| #ifdef SUPPORT_HARD_LINKS |
#ifdef SUPPORT_HARD_LINKS |
| if (link_dest) { | if (alt_dest_type == LINK_DEST) { |
| if (!hard_link_one(file, fname, cmpbuf, 1)) |
if (!hard_link_one(file, fname, cmpbuf, 1)) |
| goto try_a_copy; |
goto try_a_copy; |
| |
if (atimes_ndx) |
| |
set_file_attrs(fname, file, sxp, NULL, 0); |
| if (preserve_hard_links && F_IS_HLINKED(file)) |
if (preserve_hard_links && F_IS_HLINKED(file)) |
| finish_hard_link(file, fname, ndx, &sxp->st, itemizing, code, j); |
finish_hard_link(file, fname, ndx, &sxp->st, itemizing, code, j); |
| if (!maybe_ATTRS_REPORT && (verbose > 1 || stdout_format_has_i > 1)) { | if (!maybe_ATTRS_REPORT && (INFO_GTE(NAME, 2) || stdout_format_has_i > 1)) { |
| itemize(cmpbuf, file, ndx, 1, sxp, |
itemize(cmpbuf, file, ndx, 1, sxp, |
| ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, |
ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, |
| 0, ""); |
0, ""); |
| } |
} |
| } else |
} else |
| #endif |
#endif |
| if (itemizing) | if (alt_dest_type == CLONE_DEST) { |
| itemize(cmpbuf, file, ndx, 0, sxp, 0, 0, NULL); | if (do_clone(cmpbuf, fname, file->mode) < 0) { |
| if (verbose > 1 && maybe_ATTRS_REPORT) | rsyserr(FERROR_XFER, errno, "failed to clone %s to %s", cmpbuf, fname); |
| | exit_cleanup(RERR_UNSUPPORTED); |
| | } |
| | } else { |
| | if (itemizing) |
| | itemize(cmpbuf, file, ndx, 0, sxp, 0, 0, NULL); |
| | } |
| | if (INFO_GTE(NAME, 2) && maybe_ATTRS_REPORT) |
| rprintf(FCLIENT, "%s is uptodate\n", fname); |
rprintf(FCLIENT, "%s is uptodate\n", fname); |
| return -2; |
return -2; |
| } |
} |
| |
|
| |
if (find_exact_for_existing) |
| |
goto got_nothing_for_ya; |
| |
|
| if (match_level >= 2) { |
if (match_level >= 2) { |
| #ifdef SUPPORT_HARD_LINKS |
#ifdef SUPPORT_HARD_LINKS |
| try_a_copy: /* Copy the file locally. */ |
try_a_copy: /* Copy the file locally. */ |
| #endif |
#endif |
| if (!dry_run && copy_altdest_file(cmpbuf, fname, file) < 0) | if (!dry_run && copy_altdest_file(cmpbuf, fname, file) < 0) { |
| | if (find_exact_for_existing) /* Can get here via hard-link failure */ |
| | goto got_nothing_for_ya; |
| return -1; |
return -1; |
| |
} |
| if (itemizing) |
if (itemizing) |
| itemize(cmpbuf, file, ndx, 0, sxp, ITEM_LOCAL_CHANGE, 0, NULL); |
itemize(cmpbuf, file, ndx, 0, sxp, ITEM_LOCAL_CHANGE, 0, NULL); |
| if (maybe_ATTRS_REPORT |
if (maybe_ATTRS_REPORT |
| && ((!itemizing && verbose && match_level == 2) | && ((!itemizing && INFO_GTE(NAME, 1) && match_level == 2) |
| || (verbose > 1 && match_level == 3))) { | || (INFO_GTE(NAME, 2) && match_level == 3))) { |
| code = match_level == 3 ? FCLIENT : FINFO; |
code = match_level == 3 ? FCLIENT : FINFO; |
| rprintf(code, "%s%s\n", fname, |
rprintf(code, "%s%s\n", fname, |
| match_level == 3 ? " is uptodate" : ""); |
match_level == 3 ? " is uptodate" : ""); |
|
Line 1097 static int try_dests_reg(struct file_struct *file, cha
|
Line 1166 static int try_dests_reg(struct file_struct *file, cha
|
| } |
} |
| |
|
| return FNAMECMP_BASIS_DIR_LOW + j; |
return FNAMECMP_BASIS_DIR_LOW + j; |
| |
|
| |
got_nothing_for_ya: |
| |
sxp->st = real_st; |
| |
return -1; |
| } |
} |
| |
|
| /* This is only called for non-regular files. We return -2 if we've finished |
/* This is only called for non-regular files. We return -2 if we've finished |
|
Line 1106 static int try_dests_non(struct file_struct *file, cha
|
Line 1179 static int try_dests_non(struct file_struct *file, cha
|
| char *cmpbuf, stat_x *sxp, int itemizing, |
char *cmpbuf, stat_x *sxp, int itemizing, |
| enum logcode code) |
enum logcode code) |
| { |
{ |
| char lnk[MAXPATHLEN]; |
|
| int best_match = -1; |
int best_match = -1; |
| int match_level = 0; |
int match_level = 0; |
| enum nonregtype type; |
enum nonregtype type; |
| uint32 *devp; |
uint32 *devp; |
| int len, j = 0; | #ifdef SUPPORT_LINKS |
| | char lnk[MAXPATHLEN]; |
| | int len; |
| | #endif |
| | int j = 0; |
| |
|
| #ifndef SUPPORT_LINKS |
#ifndef SUPPORT_LINKS |
| if (S_ISLNK(file->mode)) |
if (S_ISLNK(file->mode)) |
|
Line 1151 static int try_dests_non(struct file_struct *file, cha
|
Line 1227 static int try_dests_non(struct file_struct *file, cha
|
| if (!IS_DEVICE(sxp->st.st_mode)) |
if (!IS_DEVICE(sxp->st.st_mode)) |
| continue; |
continue; |
| break; |
break; |
| #ifdef SUPPORT_LINKS |
|
| case TYPE_SYMLINK: |
case TYPE_SYMLINK: |
| |
#ifdef SUPPORT_LINKS |
| if (!S_ISLNK(sxp->st.st_mode)) |
if (!S_ISLNK(sxp->st.st_mode)) |
| continue; |
continue; |
| break; |
break; |
| |
#else |
| |
return -1; |
| #endif |
#endif |
| } |
} |
| if (match_level < 1) { |
if (match_level < 1) { |
|
Line 1171 static int try_dests_non(struct file_struct *file, cha
|
Line 1249 static int try_dests_non(struct file_struct *file, cha
|
| if (sxp->st.st_rdev != MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp))) |
if (sxp->st.st_rdev != MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp))) |
| continue; |
continue; |
| break; |
break; |
| #ifdef SUPPORT_LINKS |
|
| case TYPE_SYMLINK: |
case TYPE_SYMLINK: |
| if ((len = readlink(cmpbuf, lnk, MAXPATHLEN-1)) <= 0) | #ifdef SUPPORT_LINKS |
| | if ((len = do_readlink(cmpbuf, lnk, MAXPATHLEN-1)) <= 0) |
| continue; |
continue; |
| lnk[len] = '\0'; |
lnk[len] = '\0'; |
| if (strcmp(lnk, F_SYMLINK(file)) != 0) |
if (strcmp(lnk, F_SYMLINK(file)) != 0) |
| continue; |
continue; |
| break; |
break; |
| |
#else |
| |
return -1; |
| #endif |
#endif |
| } |
} |
| if (match_level < 2) { |
if (match_level < 2) { |
|
Line 1204 static int try_dests_non(struct file_struct *file, cha
|
Line 1284 static int try_dests_non(struct file_struct *file, cha
|
| |
|
| if (match_level == 3) { |
if (match_level == 3) { |
| #ifdef SUPPORT_HARD_LINKS |
#ifdef SUPPORT_HARD_LINKS |
| if (link_dest | if ((alt_dest_type == LINK_DEST || alt_dest_type == CLONE_DEST) |
| #ifndef CAN_HARDLINK_SYMLINK |
#ifndef CAN_HARDLINK_SYMLINK |
| && !S_ISLNK(file->mode) |
&& !S_ISLNK(file->mode) |
| #endif |
#endif |
|
Line 1224 static int try_dests_non(struct file_struct *file, cha
|
Line 1304 static int try_dests_non(struct file_struct *file, cha
|
| #endif |
#endif |
| match_level = 2; |
match_level = 2; |
| if (itemizing && stdout_format_has_i |
if (itemizing && stdout_format_has_i |
| && (verbose > 1 || stdout_format_has_i > 1)) { | && (INFO_GTE(NAME, 2) || stdout_format_has_i > 1)) { |
| int chg = compare_dest && type != TYPE_DIR ? 0 | int chg = alt_dest_type == COMPARE_DEST && type != TYPE_DIR ? 0 |
| : ITEM_LOCAL_CHANGE + (match_level == 3 ? ITEM_XNAME_FOLLOWS : 0); |
: ITEM_LOCAL_CHANGE + (match_level == 3 ? ITEM_XNAME_FOLLOWS : 0); |
| char *lp = match_level == 3 ? "" : NULL; |
char *lp = match_level == 3 ? "" : NULL; |
| itemize(cmpbuf, file, ndx, 0, sxp, chg + ITEM_MATCHED, 0, lp); |
itemize(cmpbuf, file, ndx, 0, sxp, chg + ITEM_MATCHED, 0, lp); |
| } |
} |
| if (verbose > 1 && maybe_ATTRS_REPORT) { | if (INFO_GTE(NAME, 2) && maybe_ATTRS_REPORT) { |
| rprintf(FCLIENT, "%s%s is uptodate\n", |
rprintf(FCLIENT, "%s%s is uptodate\n", |
| fname, type == TYPE_DIR ? "/" : ""); |
fname, type == TYPE_DIR ? "/" : ""); |
| } |
} |
|
Line 1243 static int try_dests_non(struct file_struct *file, cha
|
Line 1323 static int try_dests_non(struct file_struct *file, cha
|
| static void list_file_entry(struct file_struct *f) |
static void list_file_entry(struct file_struct *f) |
| { |
{ |
| char permbuf[PERMSTRING_SIZE]; |
char permbuf[PERMSTRING_SIZE]; |
| double len; | const char *mtime_str = timestring(f->modtime); |
| | int size_width = human_readable ? 14 : 11; |
| | int mtime_width = 1 + strlen(mtime_str); |
| | int atime_width = atimes_ndx ? mtime_width : 0; |
| | int crtime_width = crtimes_ndx ? mtime_width : 0; |
| |
|
| if (!F_IS_ACTIVE(f)) { |
if (!F_IS_ACTIVE(f)) { |
| /* this can happen if duplicate names were removed */ |
/* this can happen if duplicate names were removed */ |
| return; |
return; |
| } |
} |
| |
|
| permstring(permbuf, f->mode); |
|
| len = F_LENGTH(f); |
|
| |
|
| /* TODO: indicate '+' if the entry has an ACL. */ |
/* TODO: indicate '+' if the entry has an ACL. */ |
| |
|
| |
if (missing_args == 2 && f->mode == 0) { |
| |
rprintf(FINFO, "%-*s %s\n", |
| |
10 + 1 + size_width + mtime_width + atime_width + crtime_width, "*missing", |
| |
f_name(f, NULL)); |
| |
} else { |
| |
const char *atime_str = atimes_ndx && !S_ISDIR(f->mode) ? timestring(F_ATIME(f)) : ""; |
| |
const char *crtime_str = crtimes_ndx ? timestring(F_CRTIME(f)) : ""; |
| |
const char *arrow, *lnk; |
| |
|
| |
permstring(permbuf, f->mode); |
| |
|
| #ifdef SUPPORT_LINKS |
#ifdef SUPPORT_LINKS |
| if (preserve_links && S_ISLNK(f->mode)) { | if (preserve_links && S_ISLNK(f->mode)) { |
| rprintf(FINFO, "%s %11.0f %s %s -> %s\n", | arrow = " -> "; |
| permbuf, len, timestring(f->modtime), | lnk = F_SYMLINK(f); |
| f_name(f, NULL), F_SYMLINK(f)); | } else |
| } else | |
| #endif |
#endif |
| { | arrow = lnk = ""; |
| rprintf(FINFO, "%s %11.0f %s %s\n", | |
| permbuf, len, timestring(f->modtime), | rprintf(FINFO, "%s %*s %s%*s%*s %s%s%s\n", |
| f_name(f, NULL)); | permbuf, size_width, human_num(F_LENGTH(f)), |
| | timestring(f->modtime), atime_width, atime_str, crtime_width, crtime_str, |
| | f_name(f, NULL), arrow, lnk); |
| } |
} |
| } |
} |
| |
|
| |
static struct bitbag *delayed_bits = NULL; |
| static int phase = 0; |
static int phase = 0; |
| static int dflt_perms; |
static int dflt_perms; |
| |
|
|
Line 1295 static void recv_generator(char *fname, struct file_st
|
Line 1389 static void recv_generator(char *fname, struct file_st
|
| int itemizing, enum logcode code, int f_out) |
int itemizing, enum logcode code, int f_out) |
| { |
{ |
| static const char *parent_dirname = ""; |
static const char *parent_dirname = ""; |
| |
static struct file_struct *prior_dir_file = NULL; |
| /* Missing dir not created due to --dry-run; will still be scanned. */ |
/* Missing dir not created due to --dry-run; will still be scanned. */ |
| static struct file_struct *dry_missing_dir = NULL; |
static struct file_struct *dry_missing_dir = NULL; |
| /* Missing dir whose contents are skipped altogether due to |
/* Missing dir whose contents are skipped altogether due to |
| * --ignore-non-existing, daemon exclude, or mkdir failure. */ |
* --ignore-non-existing, daemon exclude, or mkdir failure. */ |
| static struct file_struct *skip_dir = NULL; |
static struct file_struct *skip_dir = NULL; |
| static struct file_list *fuzzy_dirlist = NULL; | static struct file_list *fuzzy_dirlist[MAX_BASIS_DIRS+1]; |
| static int need_fuzzy_dirlist = 0; | static int need_new_dirscan = 0; |
| struct file_struct *fuzzy_file = NULL; |
struct file_struct *fuzzy_file = NULL; |
| int fd = -1, f_copy = -1; |
int fd = -1, f_copy = -1; |
| stat_x sx, real_sx; |
stat_x sx, real_sx; |
|
Line 1316 static void recv_generator(char *fname, struct file_st
|
Line 1411 static void recv_generator(char *fname, struct file_st
|
| : inc_recurse && ndx != cur_flist->ndx_start - 1 ? -1 |
: inc_recurse && ndx != cur_flist->ndx_start - 1 ? -1 |
| : 1; |
: 1; |
| |
|
| if (verbose > 2) | if (DEBUG_GTE(GENR, 1)) |
| rprintf(FINFO, "recv_generator(%s,%d)\n", fname, ndx); |
rprintf(FINFO, "recv_generator(%s,%d)\n", fname, ndx); |
| |
|
| if (list_only) { |
if (list_only) { |
|
Line 1327 static void recv_generator(char *fname, struct file_st
|
Line 1422 static void recv_generator(char *fname, struct file_st
|
| return; |
return; |
| } |
} |
| |
|
| |
maybe_ATTRS_ACCURATE_TIME = always_checksum ? ATTRS_ACCURATE_TIME : 0; |
| |
|
| if (skip_dir) { |
if (skip_dir) { |
| if (is_below(file, skip_dir)) { |
if (is_below(file, skip_dir)) { |
| if (is_dir) |
if (is_dir) |
|
Line 1340 static void recv_generator(char *fname, struct file_st
|
Line 1437 static void recv_generator(char *fname, struct file_st
|
| skip_dir = NULL; |
skip_dir = NULL; |
| } |
} |
| |
|
| #ifdef SUPPORT_ACLS | init_stat_x(&sx); |
| sx.acc_acl = sx.def_acl = NULL; | |
| #endif | |
| #ifdef SUPPORT_XATTRS | |
| sx.xattr = NULL; | |
| #endif | |
| if (daemon_filter_list.head && (*fname != '.' || fname[1])) { |
if (daemon_filter_list.head && (*fname != '.' || fname[1])) { |
| if (check_filter(&daemon_filter_list, FLOG, fname, is_dir) < 0) { |
if (check_filter(&daemon_filter_list, FLOG, fname, is_dir) < 0) { |
| if (is_dir < 0) |
if (is_dir < 0) |
|
Line 1362 static void recv_generator(char *fname, struct file_st
|
Line 1454 static void recv_generator(char *fname, struct file_st
|
| return; |
return; |
| } |
} |
| } |
} |
| |
sx.crtime = 0; |
| |
|
| if (dry_run > 1 || (dry_missing_dir && is_below(file, dry_missing_dir))) { |
if (dry_run > 1 || (dry_missing_dir && is_below(file, dry_missing_dir))) { |
| |
int i; |
| parent_is_dry_missing: |
parent_is_dry_missing: |
| if (fuzzy_dirlist) { | for (i = 0; i < fuzzy_basis; i++) { |
| flist_free(fuzzy_dirlist); | if (fuzzy_dirlist[i]) { |
| fuzzy_dirlist = NULL; | flist_free(fuzzy_dirlist[i]); |
| | fuzzy_dirlist[i] = NULL; |
| | } |
| } |
} |
| parent_dirname = ""; |
parent_dirname = ""; |
| statret = -1; |
statret = -1; |
|
Line 1376 static void recv_generator(char *fname, struct file_st
|
Line 1472 static void recv_generator(char *fname, struct file_st
|
| const char *dn = file->dirname ? file->dirname : "."; |
const char *dn = file->dirname ? file->dirname : "."; |
| dry_missing_dir = NULL; |
dry_missing_dir = NULL; |
| if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) { |
if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) { |
| if (relative_paths && !implied_dirs | /* Each parent dir must be in the file list or the flist data is bad. |
| | * Optimization: most of the time the parent dir will be the last dir |
| | * this function was asked to process in the file list. */ |
| | if (!inc_recurse |
| | && (*dn != '.' || dn[1]) /* Avoid an issue with --relative and the "." dir. */ |
| | && (!prior_dir_file || strcmp(dn, f_name(prior_dir_file, NULL)) != 0)) { |
| | int ok = 0, j = flist_find_name(cur_flist, dn, -1); |
| | if (j >= 0) { |
| | struct file_struct *f = cur_flist->sorted[j]; |
| | if (S_ISDIR(f->mode) || (missing_args == 2 && !file->mode && !f->mode)) |
| | ok = 1; |
| | } |
| | /* The --delete-missing-args option can actually put invalid entries into |
| | * the file list, so if that option was specified, we'll just complain about |
| | * it and allow it. */ |
| | if (!ok && missing_args == 2 && file->mode == 0 && j < 0) |
| | rprintf(FERROR, "WARNING: parent dir is absent in the file list: %s\n", dn); |
| | else if (!ok) { |
| | rprintf(FERROR, "ABORTING due to invalid path from sender: %s/%s\n", |
| | dn, file->basename); |
| | exit_cleanup(RERR_PROTOCOL); |
| | } |
| | } |
| | if (relative_paths && !implied_dirs && file->mode != 0 |
| && do_stat(dn, &sx.st) < 0) { |
&& do_stat(dn, &sx.st) < 0) { |
| if (dry_run) |
if (dry_run) |
| goto parent_is_dry_missing; |
goto parent_is_dry_missing; |
| if (create_directory_path(fname) < 0) { | if (make_path(fname, ACCESSPERMS, MKP_DROP_NAME | MKP_SKIP_SLASH) < 0) { |
| rsyserr(FERROR_XFER, errno, |
rsyserr(FERROR_XFER, errno, |
| "recv_generator: mkdir %s failed", |
"recv_generator: mkdir %s failed", |
| full_fname(dn)); |
full_fname(dn)); |
| } |
} |
| } |
} |
| if (fuzzy_dirlist) { | if (fuzzy_basis) { |
| flist_free(fuzzy_dirlist); | int i; |
| fuzzy_dirlist = NULL; | for (i = 0; i < fuzzy_basis; i++) { |
| } | if (fuzzy_dirlist[i]) { |
| if (fuzzy_basis) | flist_free(fuzzy_dirlist[i]); |
| need_fuzzy_dirlist = 1; | fuzzy_dirlist[i] = NULL; |
| | } |
| | } |
| | need_new_dirscan = 1; |
| | } else if (checksum_files) |
| | need_new_dirscan = 1; |
| #ifdef SUPPORT_ACLS |
#ifdef SUPPORT_ACLS |
| if (!preserve_perms) |
if (!preserve_perms) |
| dflt_perms = default_perms_for_dir(dn); |
dflt_perms = default_perms_for_dir(dn); |
|
Line 1399 static void recv_generator(char *fname, struct file_st
|
Line 1523 static void recv_generator(char *fname, struct file_st
|
| } |
} |
| parent_dirname = dn; |
parent_dirname = dn; |
| |
|
| if (need_fuzzy_dirlist && S_ISREG(file->mode)) { | if (need_new_dirscan && S_ISREG(file->mode)) { |
| | int i; |
| strlcpy(fnamecmpbuf, dn, sizeof fnamecmpbuf); |
strlcpy(fnamecmpbuf, dn, sizeof fnamecmpbuf); |
| fuzzy_dirlist = get_dirlist(fnamecmpbuf, -1, GDL_IGNORE_FILTER_RULES); | for (i = 0; i < fuzzy_basis; i++) { |
| need_fuzzy_dirlist = 0; | if (i && pathjoin(fnamecmpbuf, MAXPATHLEN, basis_dir[i-1], dn) >= MAXPATHLEN) |
| | continue; |
| | fuzzy_dirlist[i] = get_dirlist(fnamecmpbuf, -1, GDL_IGNORE_FILTER_RULES | GDL_PERHAPS_DIR); |
| | if (fuzzy_dirlist[i] && fuzzy_dirlist[i]->used == 0) { |
| | flist_free(fuzzy_dirlist[i]); |
| | fuzzy_dirlist[i] = NULL; |
| | } |
| | } |
| | if (checksum_files) { |
| | reset_checksum_cache(started_whole_dir); |
| | started_whole_dir = upcoming_whole_dir; |
| | } |
| | need_new_dirscan = 0; |
| } |
} |
| |
|
| statret = link_stat(fname, &sx.st, keep_dirlinks && is_dir); |
statret = link_stat(fname, &sx.st, keep_dirlinks && is_dir); |
| stat_errno = errno; |
stat_errno = errno; |
| } |
} |
| |
|
| |
if (missing_args == 2 && file->mode == 0) { |
| |
if (filter_list.head && check_filter(&filter_list, FINFO, fname, is_dir) < 0) |
| |
return; |
| |
if (statret == 0) |
| |
delete_item(fname, sx.st.st_mode, del_opts); |
| |
return; |
| |
} |
| |
|
| if (ignore_non_existing > 0 && statret == -1 && stat_errno == ENOENT) { |
if (ignore_non_existing > 0 && statret == -1 && stat_errno == ENOENT) { |
| if (is_dir) { |
if (is_dir) { |
| if (is_dir < 0) |
if (is_dir < 0) |
|
Line 1420 static void recv_generator(char *fname, struct file_st
|
Line 1565 static void recv_generator(char *fname, struct file_st
|
| else if (F_IS_HLINKED(file)) |
else if (F_IS_HLINKED(file)) |
| handle_skipped_hlink(file, itemizing, code, f_out); |
handle_skipped_hlink(file, itemizing, code, f_out); |
| #endif |
#endif |
| if (verbose > 1) { | if (INFO_GTE(SKIP, 1)) { |
| rprintf(FINFO, "not creating new %s \"%s\"\n", |
rprintf(FINFO, "not creating new %s \"%s\"\n", |
| is_dir ? "directory" : "file", fname); |
is_dir ? "directory" : "file", fname); |
| } |
} |
|
Line 1433 static void recv_generator(char *fname, struct file_st
|
Line 1578 static void recv_generator(char *fname, struct file_st
|
| |
|
| if (ignore_existing > 0 && statret == 0 |
if (ignore_existing > 0 && statret == 0 |
| && (!is_dir || !S_ISDIR(sx.st.st_mode))) { |
&& (!is_dir || !S_ISDIR(sx.st.st_mode))) { |
| if (verbose > 1 && is_dir >= 0) | if (INFO_GTE(SKIP, 1) && is_dir >= 0) |
| rprintf(FINFO, "%s exists\n", fname); |
rprintf(FINFO, "%s exists\n", fname); |
| #ifdef SUPPORT_HARD_LINKS |
#ifdef SUPPORT_HARD_LINKS |
| if (F_IS_HLINKED(file)) |
if (F_IS_HLINKED(file)) |
|
Line 1455 static void recv_generator(char *fname, struct file_st
|
Line 1600 static void recv_generator(char *fname, struct file_st
|
| } else |
} else |
| added_perms = 0; |
added_perms = 0; |
| if (is_dir < 0) { |
if (is_dir < 0) { |
| |
if (!(preserve_times & PRESERVE_DIR_TIMES)) |
| |
goto cleanup; |
| /* In inc_recurse mode we want to make sure any missing |
/* In inc_recurse mode we want to make sure any missing |
| * directories get created while we're still processing |
* directories get created while we're still processing |
| * the parent dir (which allows us to touch the parent |
* the parent dir (which allows us to touch the parent |
|
Line 1483 static void recv_generator(char *fname, struct file_st
|
Line 1630 static void recv_generator(char *fname, struct file_st
|
| dry_missing_dir = file; |
dry_missing_dir = file; |
| file->flags |= FLAG_MISSING_DIR; |
file->flags |= FLAG_MISSING_DIR; |
| } |
} |
| |
init_stat_x(&real_sx); |
| |
real_sx.st = sx.st; |
| real_ret = statret; |
real_ret = statret; |
| real_sx = sx; |
|
| if (file->flags & FLAG_DIR_CREATED) |
if (file->flags & FLAG_DIR_CREATED) |
| statret = -1; |
statret = -1; |
| if (!preserve_perms) { /* See comment in non-dir code below. */ | if (!preserve_perms || omit_dir_changes) { /* See comment in non-dir code below. */ |
| file->mode = dest_mode(file->mode, sx.st.st_mode, | file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms, statret == 0); |
| dflt_perms, statret == 0); | |
| } |
} |
| |
#ifdef SUPPORT_FORCE_CHANGE |
| |
if (force_change && !preserve_fileflags) |
| |
F_FFLAGS(file) = sx.st.st_flags; |
| |
#endif |
| if (statret != 0 && basis_dir[0] != NULL) { |
if (statret != 0 && basis_dir[0] != NULL) { |
| int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, | int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, itemizing, code); |
| itemizing, code); | |
| if (j == -2) { |
if (j == -2) { |
| itemizing = 0; |
itemizing = 0; |
| code = FNONE; |
code = FNONE; |
|
Line 1509 static void recv_generator(char *fname, struct file_st
|
Line 1659 static void recv_generator(char *fname, struct file_st
|
| } |
} |
| if (real_ret != 0 && do_mkdir(fname,file->mode|added_perms) < 0 && errno != EEXIST) { |
if (real_ret != 0 && do_mkdir(fname,file->mode|added_perms) < 0 && errno != EEXIST) { |
| if (!relative_paths || errno != ENOENT |
if (!relative_paths || errno != ENOENT |
| || create_directory_path(fname) < 0 | || make_path(fname, ACCESSPERMS, MKP_DROP_NAME | MKP_SKIP_SLASH) < 0 |
| || (do_mkdir(fname, file->mode|added_perms) < 0 && errno != EEXIST)) { |
|| (do_mkdir(fname, file->mode|added_perms) < 0 && errno != EEXIST)) { |
| rsyserr(FERROR_XFER, errno, |
rsyserr(FERROR_XFER, errno, |
| "recv_generator: mkdir %s failed", |
"recv_generator: mkdir %s failed", |
| full_fname(fname)); |
full_fname(fname)); |
| skipping_dir_contents: |
skipping_dir_contents: |
| rprintf(FERROR, | rprintf(FERROR, "*** Skipping any contents from this failed directory ***\n"); |
| "*** Skipping any contents from this failed directory ***\n"); | |
| skip_dir = file; |
skip_dir = file; |
| file->flags |= FLAG_MISSING_DIR; |
file->flags |= FLAG_MISSING_DIR; |
| goto cleanup; |
goto cleanup; |
|
Line 1528 static void recv_generator(char *fname, struct file_st
|
Line 1677 static void recv_generator(char *fname, struct file_st
|
| copy_xattrs(fnamecmpbuf, fname); |
copy_xattrs(fnamecmpbuf, fname); |
| #endif |
#endif |
| if (set_file_attrs(fname, file, real_ret ? NULL : &real_sx, NULL, 0) |
if (set_file_attrs(fname, file, real_ret ? NULL : &real_sx, NULL, 0) |
| && verbose && code != FNONE && f_out != -1) | && INFO_GTE(NAME, 1) && code != FNONE && f_out != -1) |
| rprintf(code, "%s/\n", fname); |
rprintf(code, "%s/\n", fname); |
| |
|
| /* We need to ensure that the dirs in the transfer have both |
/* We need to ensure that the dirs in the transfer have both |
| * readable and writable permissions during the time we are |
* readable and writable permissions during the time we are |
| * putting files within them. This is then restored to the |
* putting files within them. This is then restored to the |
| * former permissions after the transfer is done. */ |
* former permissions after the transfer is done. */ |
| |
#ifdef SUPPORT_FORCE_CHANGE |
| |
if (force_change && F_FFLAGS(file) & force_change |
| |
&& make_mutable(fname, file->mode, F_FFLAGS(file), force_change)) |
| |
need_retouch_dir_perms = 1; |
| |
#endif |
| #ifdef HAVE_CHMOD |
#ifdef HAVE_CHMOD |
| if (!am_root && (file->mode & S_IRWXU) != S_IRWXU && dir_tweaking) { |
if (!am_root && (file->mode & S_IRWXU) != S_IRWXU && dir_tweaking) { |
| mode_t mode = file->mode | S_IRWXU; |
mode_t mode = file->mode | S_IRWXU; |
| if (do_chmod(fname, mode) < 0) { | if (do_chmod(fname, mode, 0) < 0) { |
| rsyserr(FERROR_XFER, errno, |
rsyserr(FERROR_XFER, errno, |
| "failed to modify permissions on %s", |
"failed to modify permissions on %s", |
| full_fname(fname)); |
full_fname(fname)); |
|
Line 1558 static void recv_generator(char *fname, struct file_st
|
Line 1712 static void recv_generator(char *fname, struct file_st
|
| } |
} |
| else if (delete_during && f_out != -1 && !phase |
else if (delete_during && f_out != -1 && !phase |
| && !(file->flags & FLAG_MISSING_DIR)) { |
&& !(file->flags & FLAG_MISSING_DIR)) { |
| if (file->flags & FLAG_CONTENT_DIR) | if (file->flags & FLAG_CONTENT_DIR) { |
| delete_in_dir(fname, file, &real_sx.st.st_dev); | if (detect_renamed && real_ret != 0) |
| else | unexplored_dirs++; |
| | delete_in_dir(fname, file, &real_sx.st.st_dev, |
| | delete_during < 0 ? DEL_NO_DELETIONS : 0); |
| | } else |
| change_local_filter_dir(fname, strlen(fname), F_DEPTH(file)); |
change_local_filter_dir(fname, strlen(fname), F_DEPTH(file)); |
| } |
} |
| |
upcoming_whole_dir = file->flags & FLAG_CONTENT_DIR && f_out != -1 ? 1 : 0; |
| |
prior_dir_file = file; |
| goto cleanup; |
goto cleanup; |
| } |
} |
| |
|
|
Line 1570 static void recv_generator(char *fname, struct file_st
|
Line 1729 static void recv_generator(char *fname, struct file_st
|
| * mode based on the local permissions and some heuristics. */ |
* mode based on the local permissions and some heuristics. */ |
| if (!preserve_perms) { |
if (!preserve_perms) { |
| int exists = statret == 0 && !S_ISDIR(sx.st.st_mode); |
int exists = statret == 0 && !S_ISDIR(sx.st.st_mode); |
| file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms, | file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms, exists); |
| exists); | |
| } |
} |
| |
#ifdef SUPPORT_FORCE_CHANGE |
| |
if (force_change && !preserve_fileflags) |
| |
F_FFLAGS(file) = sx.st.st_flags; |
| |
#endif |
| |
|
| #ifdef SUPPORT_HARD_LINKS |
#ifdef SUPPORT_HARD_LINKS |
| if (preserve_hard_links && F_HLINK_NOT_FIRST(file) |
if (preserve_hard_links && F_HLINK_NOT_FIRST(file) |
|
Line 1584 static void recv_generator(char *fname, struct file_st
|
Line 1746 static void recv_generator(char *fname, struct file_st
|
| #ifdef SUPPORT_LINKS |
#ifdef SUPPORT_LINKS |
| const char *sl = F_SYMLINK(file); |
const char *sl = F_SYMLINK(file); |
| if (safe_symlinks && unsafe_symlink(sl, fname)) { |
if (safe_symlinks && unsafe_symlink(sl, fname)) { |
| if (verbose) { | if (INFO_GTE(NAME, 1)) { |
| if (solo_file) { |
if (solo_file) { |
| /* fname contains the destination path, but we |
/* fname contains the destination path, but we |
| * want to report the source path. */ |
* want to report the source path. */ |
|
Line 1594 static void recv_generator(char *fname, struct file_st
|
Line 1756 static void recv_generator(char *fname, struct file_st
|
| "ignoring unsafe symlink \"%s\" -> \"%s\"\n", |
"ignoring unsafe symlink \"%s\" -> \"%s\"\n", |
| fname, sl); |
fname, sl); |
| } |
} |
| return; | goto cleanup; |
| } |
} |
| if (statret == 0) { |
if (statret == 0) { |
| char lnk[MAXPATHLEN]; |
char lnk[MAXPATHLEN]; |
| int len; |
int len; |
| |
|
| if (!S_ISLNK(sx.st.st_mode)) | if (S_ISLNK(sx.st.st_mode) |
| statret = -1; | && (len = do_readlink(fname, lnk, MAXPATHLEN-1)) > 0 |
| else if ((len = readlink(fname, lnk, MAXPATHLEN-1)) > 0 | && strncmp(lnk, sl, len) == 0 && sl[len] == '\0') { |
| && strncmp(lnk, sl, len) == 0 && sl[len] == '\0') { | |
| /* The link is pointing to the right place. */ |
/* The link is pointing to the right place. */ |
| set_file_attrs(fname, file, &sx, NULL, maybe_ATTRS_REPORT); |
set_file_attrs(fname, file, &sx, NULL, maybe_ATTRS_REPORT); |
| if (itemizing) |
if (itemizing) |
| itemize(fname, file, ndx, 0, &sx, 0, 0, NULL); |
itemize(fname, file, ndx, 0, &sx, 0, 0, NULL); |
| #if defined SUPPORT_HARD_LINKS && defined CAN_HARDLINK_SYMLINK | #ifdef SUPPORT_HARD_LINKS |
| if (preserve_hard_links && F_IS_HLINKED(file)) |
if (preserve_hard_links && F_IS_HLINKED(file)) |
| finish_hard_link(file, fname, ndx, &sx.st, itemizing, code, -1); |
finish_hard_link(file, fname, ndx, &sx.st, itemizing, code, -1); |
| #endif |
#endif |
|
Line 1616 static void recv_generator(char *fname, struct file_st
|
Line 1777 static void recv_generator(char *fname, struct file_st
|
| goto return_with_success; |
goto return_with_success; |
| goto cleanup; |
goto cleanup; |
| } |
} |
| /* Not the right symlink (or not a symlink), so |
|
| * delete it. */ |
|
| if (delete_item(fname, sx.st.st_mode, del_opts | DEL_FOR_SYMLINK) != 0) |
|
| goto cleanup; |
|
| } else if (basis_dir[0] != NULL) { |
} else if (basis_dir[0] != NULL) { |
| int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, | int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, itemizing, code); |
| itemizing, code); | |
| if (j == -2) { |
if (j == -2) { |
| #ifndef CAN_HARDLINK_SYMLINK |
#ifndef CAN_HARDLINK_SYMLINK |
| if (link_dest) { | if (alt_dest_type == LINK_DEST) { |
| /* Resort to --copy-dest behavior. */ |
/* Resort to --copy-dest behavior. */ |
| } else |
} else |
| #endif |
#endif |
| if (!copy_dest) | if (alt_dest_type != COPY_DEST) |
| goto cleanup; |
goto cleanup; |
| itemizing = 0; |
itemizing = 0; |
| code = FNONE; |
code = FNONE; |
| } else if (j >= 0) | } else if (j >= 0) { |
| statret = 1; |
statret = 1; |
| |
fnamecmp = fnamecmpbuf; |
| |
} |
| } |
} |
| #ifdef SUPPORT_HARD_LINKS | if (atomic_create(file, fname, sl, NULL, MAKEDEV(0, 0), &sx, statret == 0 ? DEL_FOR_SYMLINK : 0)) { |
| if (preserve_hard_links && F_HLINK_NOT_LAST(file)) { | |
| cur_flist->in_progress++; | |
| goto cleanup; | |
| } | |
| #endif | |
| if (do_symlink(sl, fname) != 0) { | |
| rsyserr(FERROR_XFER, errno, "symlink %s -> \"%s\" failed", | |
| full_fname(fname), sl); | |
| } else { | |
| set_file_attrs(fname, file, NULL, NULL, 0); |
set_file_attrs(fname, file, NULL, NULL, 0); |
| if (itemizing) { |
if (itemizing) { |
| itemize(fname, file, ndx, statret, &sx, | if (statret == 0 && !S_ISLNK(sx.st.st_mode)) |
| | statret = -1; |
| | itemize(fnamecmp, file, ndx, statret, &sx, |
| ITEM_LOCAL_CHANGE|ITEM_REPORT_CHANGE, 0, NULL); |
ITEM_LOCAL_CHANGE|ITEM_REPORT_CHANGE, 0, NULL); |
| } |
} |
| if (code != FNONE && verbose) | if (code != FNONE && INFO_GTE(NAME, 1)) |
| rprintf(code, "%s -> %s\n", fname, sl); |
rprintf(code, "%s -> %s\n", fname, sl); |
| #ifdef SUPPORT_HARD_LINKS |
#ifdef SUPPORT_HARD_LINKS |
| if (preserve_hard_links && F_IS_HLINKED(file)) |
if (preserve_hard_links && F_IS_HLINKED(file)) |
|
Line 1670 static void recv_generator(char *fname, struct file_st
|
Line 1821 static void recv_generator(char *fname, struct file_st
|
| if ((am_root && preserve_devices && IS_DEVICE(file->mode)) |
if ((am_root && preserve_devices && IS_DEVICE(file->mode)) |
| || (preserve_specials && IS_SPECIAL(file->mode))) { |
|| (preserve_specials && IS_SPECIAL(file->mode))) { |
| dev_t rdev; |
dev_t rdev; |
| |
int del_for_flag = 0; |
| if (IS_DEVICE(file->mode)) { |
if (IS_DEVICE(file->mode)) { |
| uint32 *devp = F_RDEV_P(file); |
uint32 *devp = F_RDEV_P(file); |
| rdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp)); |
rdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp)); |
| } else |
} else |
| rdev = 0; |
rdev = 0; |
| if (statret == 0) { |
if (statret == 0) { |
| int del_for_flag; |
|
| if (IS_DEVICE(file->mode)) { |
if (IS_DEVICE(file->mode)) { |
| if (!IS_DEVICE(sx.st.st_mode)) |
if (!IS_DEVICE(sx.st.st_mode)) |
| statret = -1; |
statret = -1; |
|
Line 1701 static void recv_generator(char *fname, struct file_st
|
Line 1852 static void recv_generator(char *fname, struct file_st
|
| goto return_with_success; |
goto return_with_success; |
| goto cleanup; |
goto cleanup; |
| } |
} |
| if (delete_item(fname, sx.st.st_mode, del_opts | del_for_flag) != 0) |
|
| goto cleanup; |
|
| } else if (basis_dir[0] != NULL) { |
} else if (basis_dir[0] != NULL) { |
| int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, | int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, itemizing, code); |
| itemizing, code); | |
| if (j == -2) { |
if (j == -2) { |
| #ifndef CAN_HARDLINK_SPECIAL |
#ifndef CAN_HARDLINK_SPECIAL |
| if (link_dest) { | if (alt_dest_type == LINK_DEST) { |
| /* Resort to --copy-dest behavior. */ |
/* Resort to --copy-dest behavior. */ |
| } else |
} else |
| #endif |
#endif |
| if (!copy_dest) | if (alt_dest_type != COPY_DEST) |
| goto cleanup; |
goto cleanup; |
| itemizing = 0; |
itemizing = 0; |
| code = FNONE; |
code = FNONE; |
| } else if (j >= 0) | } else if (j >= 0) { |
| statret = 1; |
statret = 1; |
| |
fnamecmp = fnamecmpbuf; |
| |
} |
| } |
} |
| #ifdef SUPPORT_HARD_LINKS | if (DEBUG_GTE(GENR, 1)) { |
| if (preserve_hard_links && F_HLINK_NOT_LAST(file)) { | |
| cur_flist->in_progress++; | |
| goto cleanup; | |
| } | |
| #endif | |
| if (verbose > 2) { | |
| rprintf(FINFO, "mknod(%s, 0%o, [%ld,%ld])\n", |
rprintf(FINFO, "mknod(%s, 0%o, [%ld,%ld])\n", |
| fname, (int)file->mode, |
fname, (int)file->mode, |
| (long)major(rdev), (long)minor(rdev)); |
(long)major(rdev), (long)minor(rdev)); |
| } |
} |
| if (do_mknod(fname, file->mode, rdev) < 0) { | if (atomic_create(file, fname, NULL, NULL, rdev, &sx, del_for_flag)) { |
| rsyserr(FERROR_XFER, errno, "mknod %s failed", | |
| full_fname(fname)); | |
| } else { | |
| set_file_attrs(fname, file, NULL, NULL, 0); |
set_file_attrs(fname, file, NULL, NULL, 0); |
| if (itemizing) { |
if (itemizing) { |
| itemize(fname, file, ndx, statret, &sx, | itemize(fnamecmp, file, ndx, statret, &sx, |
| ITEM_LOCAL_CHANGE|ITEM_REPORT_CHANGE, 0, NULL); |
ITEM_LOCAL_CHANGE|ITEM_REPORT_CHANGE, 0, NULL); |
| } |
} |
| if (code != FNONE && verbose) | if (code != FNONE && INFO_GTE(NAME, 1)) |
| rprintf(code, "%s\n", fname); |
rprintf(code, "%s\n", fname); |
| #ifdef SUPPORT_HARD_LINKS |
#ifdef SUPPORT_HARD_LINKS |
| if (preserve_hard_links && F_IS_HLINKED(file)) |
if (preserve_hard_links && F_IS_HLINKED(file)) |
|
Line 1751 static void recv_generator(char *fname, struct file_st
|
Line 1892 static void recv_generator(char *fname, struct file_st
|
| goto cleanup; |
goto cleanup; |
| } |
} |
| |
|
| if (!S_ISREG(file->mode)) { | if (!(S_ISREG(file->mode) || (copy_devices && IS_DEVICE(file->mode)))) { |
| if (solo_file) |
if (solo_file) |
| fname = f_name(file, NULL); |
fname = f_name(file, NULL); |
| rprintf(FINFO, "skipping non-regular file \"%s\"\n", fname); |
rprintf(FINFO, "skipping non-regular file \"%s\"\n", fname); |
| goto cleanup; |
goto cleanup; |
| } |
} |
| |
|
| if (max_size > 0 && F_LENGTH(file) > max_size) { | if (max_size >= 0 && F_LENGTH(file) > max_size) { |
| if (verbose > 1) { | if (INFO_GTE(SKIP, 1)) { |
| if (solo_file) |
if (solo_file) |
| fname = f_name(file, NULL); |
fname = f_name(file, NULL); |
| rprintf(FINFO, "%s is over max-size\n", fname); |
rprintf(FINFO, "%s is over max-size\n", fname); |
| } |
} |
| goto cleanup; |
goto cleanup; |
| } |
} |
| if (min_size > 0 && F_LENGTH(file) < min_size) { | if (min_size >= 0 && F_LENGTH(file) < min_size) { |
| if (verbose > 1) { | if (INFO_GTE(SKIP, 1)) { |
| if (solo_file) |
if (solo_file) |
| fname = f_name(file, NULL); |
fname = f_name(file, NULL); |
| rprintf(FINFO, "%s is under min-size\n", fname); |
rprintf(FINFO, "%s is under min-size\n", fname); |
|
Line 1775 static void recv_generator(char *fname, struct file_st
|
Line 1916 static void recv_generator(char *fname, struct file_st
|
| goto cleanup; |
goto cleanup; |
| } |
} |
| |
|
| if (update_only > 0 && statret == 0 | if (update_only > 0 && statret == 0 && file->modtime - sx.st.st_mtime <= modify_window) { |
| && cmp_time(sx.st.st_mtime, file->modtime) > 0) { | if (INFO_GTE(SKIP, 1)) |
| if (verbose > 1) | |
| rprintf(FINFO, "%s is newer\n", fname); |
rprintf(FINFO, "%s is newer\n", fname); |
| #ifdef SUPPORT_HARD_LINKS |
#ifdef SUPPORT_HARD_LINKS |
| if (F_IS_HLINKED(file)) |
if (F_IS_HLINKED(file)) |
|
Line 1786 static void recv_generator(char *fname, struct file_st
|
Line 1926 static void recv_generator(char *fname, struct file_st
|
| goto cleanup; |
goto cleanup; |
| } |
} |
| |
|
| |
if (downdate_only > 0 && statret == 0 && file->modtime - sx.st.st_mtime >= modify_window) { |
| |
if (INFO_GTE(SKIP, 1)) |
| |
rprintf(FINFO, "%s is older\n", fname); |
| |
return; |
| |
} |
| |
|
| fnamecmp_type = FNAMECMP_FNAME; |
fnamecmp_type = FNAMECMP_FNAME; |
| |
|
| if (statret == 0 && !S_ISREG(sx.st.st_mode)) { | if (statret == 0 && !(S_ISREG(sx.st.st_mode) || (write_devices && IS_DEVICE(sx.st.st_mode)))) { |
| if (delete_item(fname, sx.st.st_mode, del_opts | DEL_FOR_FILE) != 0) |
if (delete_item(fname, sx.st.st_mode, del_opts | DEL_FOR_FILE) != 0) |
| goto cleanup; |
goto cleanup; |
| statret = -1; |
statret = -1; |
| stat_errno = ENOENT; |
stat_errno = ENOENT; |
| } |
} |
| |
|
| if (statret != 0 && basis_dir[0] != NULL) { | if (basis_dir[0] != NULL && (statret != 0 || alt_dest_type != COPY_DEST)) { |
| int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx, | int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx, statret == 0, itemizing, code); |
| itemizing, code); | |
| if (j == -2) { |
if (j == -2) { |
| if (remove_source_files == 1) |
if (remove_source_files == 1) |
| goto return_with_success; |
goto return_with_success; |
|
Line 1810 static void recv_generator(char *fname, struct file_st
|
Line 1955 static void recv_generator(char *fname, struct file_st
|
| } |
} |
| } |
} |
| |
|
| |
init_stat_x(&real_sx); |
| |
real_sx.st = sx.st; /* Don't copy xattr/acl pointers, as they would free wrong. */ |
| real_ret = statret; |
real_ret = statret; |
| real_sx = sx; |
|
| |
|
| if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL |
if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL |
| && link_stat(partialptr, &partial_st, 0) == 0 | && link_stat(partialptr, &partial_st, 0) == 0 |
| && S_ISREG(partial_st.st_mode)) { | && S_ISREG(partial_st.st_mode)) { |
| if (statret != 0) |
if (statret != 0) |
| goto prepare_to_open; |
goto prepare_to_open; |
| } else |
} else |
| partialptr = NULL; |
partialptr = NULL; |
| |
|
| if (statret != 0 && fuzzy_dirlist) { | if (statret != 0 && fuzzy_basis) { |
| int j = find_fuzzy(file, fuzzy_dirlist); | /* Sets fnamecmp_type to FNAMECMP_FUZZY or above. */ |
| if (j >= 0) { | fuzzy_file = find_fuzzy(file, fuzzy_dirlist, &fnamecmp_type); |
| fuzzy_file = fuzzy_dirlist->files[j]; | if (fuzzy_file) { |
| f_name(fuzzy_file, fnamecmpbuf); |
f_name(fuzzy_file, fnamecmpbuf); |
| if (verbose > 2) { | if (DEBUG_GTE(FUZZY, 1)) { |
| rprintf(FINFO, "fuzzy basis selected for %s: %s\n", |
rprintf(FINFO, "fuzzy basis selected for %s: %s\n", |
| fname, fnamecmpbuf); |
fname, fnamecmpbuf); |
| } |
} |
| sx.st.st_size = F_LENGTH(fuzzy_file); |
sx.st.st_size = F_LENGTH(fuzzy_file); |
| |
#ifdef SUPPORT_HFS_COMPRESSION |
| |
if (sx.st.st_flags & UF_COMPRESSED) { |
| |
if (preserve_hfs_compression) |
| |
sx.st.st_size = 0; |
| |
else |
| |
sx.st.st_flags &= ~UF_COMPRESSED; |
| |
} |
| |
#endif |
| statret = 0; |
statret = 0; |
| fnamecmp = fnamecmpbuf; |
fnamecmp = fnamecmpbuf; |
| fnamecmp_type = FNAMECMP_FUZZY; |
|
| } |
} |
| } |
} |
| |
|
|
Line 1844 static void recv_generator(char *fname, struct file_st
|
Line 1997 static void recv_generator(char *fname, struct file_st
|
| goto cleanup; |
goto cleanup; |
| } |
} |
| #endif |
#endif |
| if (stat_errno == ENOENT) | if (stat_errno == ENOENT) { |
| | if (detect_renamed && unexplored_dirs > 0 |
| | && F_LENGTH(file)) { |
| | bitbag_set_bit(delayed_bits, ndx); |
| | return; |
| | } |
| goto notify_others; |
goto notify_others; |
| |
} |
| rsyserr(FERROR_XFER, stat_errno, "recv_generator: failed to stat %s", |
rsyserr(FERROR_XFER, stat_errno, "recv_generator: failed to stat %s", |
| full_fname(fname)); |
full_fname(fname)); |
| goto cleanup; |
goto cleanup; |
|
Line 1853 static void recv_generator(char *fname, struct file_st
|
Line 2012 static void recv_generator(char *fname, struct file_st
|
| |
|
| if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH) |
if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH) |
| ; |
; |
| else if (fnamecmp_type == FNAMECMP_FUZZY) | else if (fnamecmp_type >= FNAMECMP_FUZZY) |
| ; |
; |
| else if (unchanged_file(fnamecmp, file, &sx.st)) { | else if (unchanged_file(fnamecmp, file, &sx.st, fnamecmp_type == FNAMECMP_FNAME ? 0 : -1)) { |
| if (partialptr) { |
if (partialptr) { |
| do_unlink(partialptr); |
do_unlink(partialptr); |
| handle_partial_dir(partialptr, PDIR_DELETE); |
handle_partial_dir(partialptr, PDIR_DELETE); |
| } |
} |
| set_file_attrs(fname, file, &sx, NULL, maybe_ATTRS_REPORT); | set_file_attrs(fname, file, &sx, NULL, maybe_ATTRS_REPORT | maybe_ATTRS_ACCURATE_TIME); |
| | if (checksum_files & CSF_UPDATE) |
| | set_cached_checksum(cur_flist, file); |
| if (itemizing) |
if (itemizing) |
| itemize(fnamecmp, file, ndx, statret, &sx, 0, 0, NULL); |
itemize(fnamecmp, file, ndx, statret, &sx, 0, 0, NULL); |
| #ifdef SUPPORT_HARD_LINKS |
#ifdef SUPPORT_HARD_LINKS |
|
Line 1889 static void recv_generator(char *fname, struct file_st
|
Line 2050 static void recv_generator(char *fname, struct file_st
|
| fnamecmp = partialptr; |
fnamecmp = partialptr; |
| fnamecmp_type = FNAMECMP_PARTIAL_DIR; |
fnamecmp_type = FNAMECMP_PARTIAL_DIR; |
| statret = 0; |
statret = 0; |
| |
if (detect_renamed > 1 && unchanged_file(fnamecmp, file, &sx.st)) { |
| |
/* Adopt the partial file. */ |
| |
finish_transfer(fname, fnamecmp, NULL, NULL, file, 1, 1); |
| |
handle_partial_dir(partialptr, PDIR_DELETE); |
| |
if (itemizing) |
| |
itemize(fnamecmp, file, ndx, -1, &sx, |
| |
ITEM_LOCAL_CHANGE, fnamecmp_type, NULL); |
| |
#ifdef SUPPORT_HARD_LINKS |
| |
if (preserve_hard_links && F_IS_HLINKED(file)) |
| |
finish_hard_link(file, fname, ndx, &sx.st, itemizing, code, -1); |
| |
#endif |
| |
if (remove_source_files == 1) |
| |
goto return_with_success; |
| |
goto cleanup; |
| |
} |
| } |
} |
| |
|
| if (!do_xfers) |
if (!do_xfers) |
| goto notify_others; |
goto notify_others; |
| |
|
| if (read_batch || whole_file) { |
if (read_batch || whole_file) { |
| if (inplace && make_backups > 0 && fnamecmp_type == FNAMECMP_FNAME) { | if (inplace && make_backups > 1 && fnamecmp_type == FNAMECMP_FNAME) { |
| if (!(backupptr = get_backup_name(fname))) |
if (!(backupptr = get_backup_name(fname))) |
| goto cleanup; |
goto cleanup; |
| if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) |
if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) |
| goto pretend_missing; |
goto pretend_missing; |
| if (copy_file(fname, backupptr, -1, back_file->mode, 1) < 0) { | if (copy_file(fname, backupptr, -1, back_file->mode) < 0) { |
| unmake_file(back_file); |
unmake_file(back_file); |
| back_file = NULL; |
back_file = NULL; |
| goto cleanup; |
goto cleanup; |
|
Line 1909 static void recv_generator(char *fname, struct file_st
|
Line 2085 static void recv_generator(char *fname, struct file_st
|
| goto notify_others; |
goto notify_others; |
| } |
} |
| |
|
| if (fuzzy_dirlist) { | if (fuzzy_dirlist[0]) { |
| int j = flist_find(fuzzy_dirlist, file); | int j = flist_find(fuzzy_dirlist[0], file); |
| if (j >= 0) /* don't use changing file as future fuzzy basis */ |
if (j >= 0) /* don't use changing file as future fuzzy basis */ |
| fuzzy_dirlist->files[j]->flags |= FLAG_FILE_SENT; | fuzzy_dirlist[0]->files[j]->flags |= FLAG_FILE_SENT; |
| } |
} |
| |
|
| /* open the file */ |
/* open the file */ |
|
Line 1931 static void recv_generator(char *fname, struct file_st
|
Line 2107 static void recv_generator(char *fname, struct file_st
|
| goto notify_others; |
goto notify_others; |
| } |
} |
| |
|
| if (inplace && make_backups > 0 && fnamecmp_type == FNAMECMP_FNAME) { | if (inplace && make_backups > 1 && fnamecmp_type == FNAMECMP_FNAME) { |
| if (!(backupptr = get_backup_name(fname))) { |
if (!(backupptr = get_backup_name(fname))) { |
| close(fd); |
close(fd); |
| goto cleanup; |
goto cleanup; |
|
Line 1949 static void recv_generator(char *fname, struct file_st
|
Line 2125 static void recv_generator(char *fname, struct file_st
|
| goto cleanup; |
goto cleanup; |
| } |
} |
| if ((f_copy = do_open(backupptr, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) { |
if ((f_copy = do_open(backupptr, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) { |
| int save_errno = errno ? errno : EINVAL; /* 0 paranoia */ | rsyserr(FERROR_XFER, errno, "open %s", full_fname(backupptr)); |
| if (errno == ENOENT && make_bak_dir(backupptr) == 0) { | unmake_file(back_file); |
| if ((f_copy = do_open(backupptr, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) | back_file = NULL; |
| save_errno = errno ? errno : save_errno; | close(fd); |
| else | goto cleanup; |
| save_errno = 0; | |
| } | |
| if (save_errno) { | |
| rsyserr(FERROR_XFER, save_errno, "open %s", full_fname(backupptr)); | |
| unmake_file(back_file); | |
| back_file = NULL; | |
| close(fd); | |
| goto cleanup; | |
| } | |
| } |
} |
| fnamecmp_type = FNAMECMP_BACKUP; |
fnamecmp_type = FNAMECMP_BACKUP; |
| } |
} |
| |
|
| if (verbose > 3) { | if (IS_DEVICE(sx.st.st_mode) && sx.st.st_size == 0) |
| rprintf(FINFO, "gen mapped %s of size %.0f\n", | sx.st.st_size = get_device_size(fd, fnamecmp); |
| fnamecmp, (double)sx.st.st_size); | |
| | if (DEBUG_GTE(DELTASUM, 3)) { |
| | rprintf(FINFO, "gen mapped %s of size %s\n", |
| | fnamecmp, big_num(sx.st.st_size)); |
| } |
} |
| |
|
| if (verbose > 2) | if (DEBUG_GTE(DELTASUM, 2)) |
| rprintf(FINFO, "generating and sending sums for %d\n", ndx); |
rprintf(FINFO, "generating and sending sums for %d\n", ndx); |
| |
|
| notify_others: |
notify_others: |
| if (remove_source_files && !delay_updates && !phase && !dry_run) |
if (remove_source_files && !delay_updates && !phase && !dry_run) |
| increment_active_files(ndx, itemizing, code); |
increment_active_files(ndx, itemizing, code); |
| if (inc_recurse && !dry_run) | if (inc_recurse && (!dry_run || write_batch < 0)) |
| cur_flist->in_progress++; |
cur_flist->in_progress++; |
| #ifdef SUPPORT_HARD_LINKS |
#ifdef SUPPORT_HARD_LINKS |
| if (preserve_hard_links && F_IS_HLINKED(file)) |
if (preserve_hard_links && F_IS_HLINKED(file)) |
|
Line 1991 static void recv_generator(char *fname, struct file_st
|
Line 2161 static void recv_generator(char *fname, struct file_st
|
| iflags |= ITEM_REPORT_CHANGE; |
iflags |= ITEM_REPORT_CHANGE; |
| if (fnamecmp_type != FNAMECMP_FNAME) |
if (fnamecmp_type != FNAMECMP_FNAME) |
| iflags |= ITEM_BASIS_TYPE_FOLLOWS; |
iflags |= ITEM_BASIS_TYPE_FOLLOWS; |
| if (fnamecmp_type == FNAMECMP_FUZZY) | if (fnamecmp_type >= FNAMECMP_FUZZY) |
| iflags |= ITEM_XNAME_FOLLOWS; |
iflags |= ITEM_XNAME_FOLLOWS; |
| itemize(fnamecmp, file, -1, real_ret, &real_sx, iflags, fnamecmp_type, |
itemize(fnamecmp, file, -1, real_ret, &real_sx, iflags, fnamecmp_type, |
| fuzzy_file ? fuzzy_file->basename : NULL); |
fuzzy_file ? fuzzy_file->basename : NULL); |
| #ifdef SUPPORT_ACLS | free_stat_x(&real_sx); |
| if (preserve_acls) | |
| free_acl(&real_sx); | |
| #endif | |
| #ifdef SUPPORT_XATTRS | |
| if (preserve_xattrs) | |
| free_xattr(&real_sx); | |
| #endif | |
| } |
} |
| |
|
| if (!do_xfers) { |
if (!do_xfers) { |
|
Line 2015 static void recv_generator(char *fname, struct file_st
|
Line 2178 static void recv_generator(char *fname, struct file_st
|
| if (read_batch) |
if (read_batch) |
| goto cleanup; |
goto cleanup; |
| |
|
| |
#ifdef SUPPORT_HFS_COMPRESSION |
| |
if (F_FFLAGS(file) & UF_COMPRESSED) { |
| |
/* At this point the attrs have already been copied, we don't need to transfer a data fork |
| |
* If my filesystem doesn't support HFS compression, the existing file's content |
| |
* will not be automatically truncated, so we'll do that manually here */ |
| |
if (preserve_hfs_compression && sx.st.st_size > 0) { |
| |
if (ftruncate(fd, 0) == 0) |
| |
sx.st.st_size = 0; |
| |
} |
| |
} |
| |
#endif |
| |
|
| if (statret != 0 || whole_file) |
if (statret != 0 || whole_file) |
| write_sum_head(f_out, NULL); |
write_sum_head(f_out, NULL); |
| else if (sx.st.st_size <= 0) { |
else if (sx.st.st_size <= 0) { |
|
Line 2023 static void recv_generator(char *fname, struct file_st
|
Line 2198 static void recv_generator(char *fname, struct file_st
|
| } else { |
} else { |
| if (generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy) < 0) { |
if (generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy) < 0) { |
| rprintf(FWARNING, |
rprintf(FWARNING, |
| "WARNING: file is too large for checksum sending: %s\n", | "WARNING: file is too large for checksum sending: %s\n", |
| fnamecmp); | fnamecmp); |
| write_sum_head(f_out, NULL); |
write_sum_head(f_out, NULL); |
| } |
} |
| close(fd); |
close(fd); |
|
Line 2043 static void recv_generator(char *fname, struct file_st
|
Line 2218 static void recv_generator(char *fname, struct file_st
|
| #endif |
#endif |
| set_file_attrs(backupptr, back_file, NULL, NULL, 0); |
set_file_attrs(backupptr, back_file, NULL, NULL, 0); |
| preserve_xattrs = save_preserve_xattrs; |
preserve_xattrs = save_preserve_xattrs; |
| if (verbose > 1) { | if (INFO_GTE(BACKUP, 1)) { |
| rprintf(FINFO, "backed up %s to %s\n", |
rprintf(FINFO, "backed up %s to %s\n", |
| fname, backupptr); |
fname, backupptr); |
| } |
} |
| unmake_file(back_file); |
unmake_file(back_file); |
| } |
} |
| |
|
| #ifdef SUPPORT_ACLS | free_stat_x(&sx); |
| if (preserve_acls) | } |
| free_acl(&sx); | |
| | /* If we are replacing an existing hard link, symlink, device, or special file, |
| | * create a temp-name item and rename it into place. A symlimk specifies slnk, |
| | * a hard link specifies hlnk, otherwise we create a device based on rdev. |
| | * Specify 0 for the del_for_flag if there is not a file to replace. This |
| | * returns 1 on success and 0 on failure. */ |
| | int atomic_create(struct file_struct *file, char *fname, const char *slnk, const char *hlnk, |
| | dev_t rdev, stat_x *sxp, int del_for_flag) |
| | { |
| | char tmpname[MAXPATHLEN]; |
| | const char *create_name; |
| | int skip_atomic, dir_in_the_way = del_for_flag && S_ISDIR(sxp->st.st_mode); |
| | |
| | if (!del_for_flag || dir_in_the_way || tmpdir || !get_tmpname(tmpname, fname, True)) |
| | skip_atomic = 1; |
| | else |
| | skip_atomic = 0; |
| | |
| | if (del_for_flag) { |
| | if (make_backups > 1 && !dir_in_the_way) { |
| | if (!make_backup(fname, skip_atomic)) |
| | return 0; |
| | } else if (skip_atomic) { |
| | int del_opts = delete_mode || force_delete ? DEL_RECURSE : 0; |
| | if (delete_item(fname, sxp->st.st_mode, del_opts | del_for_flag) != 0) |
| | return 0; |
| | } |
| | } |
| | |
| | create_name = skip_atomic ? fname : tmpname; |
| | |
| | if (slnk) { |
| | #ifdef SUPPORT_LINKS |
| | if (do_symlink(slnk, create_name) < 0) { |
| | rsyserr(FERROR_XFER, errno, "symlink %s -> \"%s\" failed", |
| | full_fname(create_name), slnk); |
| | return 0; |
| | } |
| | #else |
| | return 0; |
| #endif |
#endif |
| #ifdef SUPPORT_XATTRS | } else if (hlnk) { |
| if (preserve_xattrs) | #ifdef SUPPORT_HARD_LINKS |
| free_xattr(&sx); | if (!hard_link_one(file, create_name, hlnk, 0)) |
| | return 0; |
| | #else |
| | return 0; |
| #endif |
#endif |
| return; | } else { |
| | if (do_mknod(create_name, file->mode, rdev) < 0) { |
| | rsyserr(FERROR_XFER, errno, "mknod %s failed", |
| | full_fname(create_name)); |
| | return 0; |
| | } |
| | } |
| | |
| | if (!skip_atomic) { |
| | if (do_rename(tmpname, fname) < 0) { |
| | rsyserr(FERROR_XFER, errno, "rename %s -> \"%s\" failed", |
| | full_fname(tmpname), full_fname(fname)); |
| | do_unlink(tmpname); |
| | return 0; |
| | } |
| | } |
| | |
| | return 1; |
| } |
} |
| |
|
| #ifdef SUPPORT_HARD_LINKS |
#ifdef SUPPORT_HARD_LINKS |
|
Line 2101 static void touch_up_dirs(struct file_list *flist, int
|
Line 2335 static void touch_up_dirs(struct file_list *flist, int
|
| * transfer and/or re-set any tweaked modified-time values. */ |
* transfer and/or re-set any tweaked modified-time values. */ |
| for (i = start; i <= end; i++, counter++) { |
for (i = start; i <= end; i++, counter++) { |
| file = flist->files[i]; |
file = flist->files[i]; |
| |
if (!F_IS_ACTIVE(file)) |
| |
continue; |
| if (!S_ISDIR(file->mode) |
if (!S_ISDIR(file->mode) |
| || (!implied_dirs && file->flags & FLAG_IMPLIED_DIR)) |
|| (!implied_dirs && file->flags & FLAG_IMPLIED_DIR)) |
| continue; |
continue; |
| if (verbose > 3) { | if (DEBUG_GTE(TIME, 2)) { |
| fname = f_name(file, NULL); |
fname = f_name(file, NULL); |
| rprintf(FINFO, "touch_up_dirs: %s (%d)\n", |
rprintf(FINFO, "touch_up_dirs: %s (%d)\n", |
| NS(fname), i); |
NS(fname), i); |
| } |
} |
| /* Be sure not to retouch permissions with --fake-super. */ |
/* Be sure not to retouch permissions with --fake-super. */ |
| fix_dir_perms = !am_root && !(file->mode & S_IWUSR); |
fix_dir_perms = !am_root && !(file->mode & S_IWUSR); |
| if (!F_IS_ACTIVE(file) || file->flags & FLAG_MISSING_DIR | if (file->flags & FLAG_MISSING_DIR || !(need_retouch_dir_times || fix_dir_perms)) |
| || !(need_retouch_dir_times || fix_dir_perms)) | |
| continue; |
continue; |
| fname = f_name(file, NULL); |
fname = f_name(file, NULL); |
| if (fix_dir_perms) |
if (fix_dir_perms) |
| do_chmod(fname, file->mode); | do_chmod(fname, file->mode, 0); |
| if (need_retouch_dir_times) { |
if (need_retouch_dir_times) { |
| STRUCT_STAT st; |
STRUCT_STAT st; |
| if (link_stat(fname, &st, 0) == 0 | if (link_stat(fname, &st, 0) == 0 && mtime_differs(&st, file)) { |
| && cmp_time(st.st_mtime, file->modtime) != 0) | st.st_mtime = file->modtime; |
| set_modtime(fname, file->modtime, file->mode); | #ifdef ST_MTIME_NSEC |
| | st.ST_MTIME_NSEC = F_MOD_NSEC_or_0(file); |
| | #endif |
| | #ifdef SUPPORT_FORCE_CHANGE |
| | st.st_mode = file->mode; |
| | st.st_flags = 0; |
| | #endif |
| | set_times(fname, &st); |
| | } |
| } |
} |
| |
#ifdef SUPPORT_FORCE_CHANGE |
| |
if (force_change && F_FFLAGS(file) & force_change) |
| |
undo_make_mutable(fname, F_FFLAGS(file)); |
| |
#endif |
| if (counter >= loopchk_limit) { |
if (counter >= loopchk_limit) { |
| if (allowed_lull) |
if (allowed_lull) |
| maybe_send_keepalive(); | maybe_send_keepalive(time(NULL), MSK_ALLOW_FLUSH); |
| else |
else |
| maybe_flush_socket(0); |
maybe_flush_socket(0); |
| counter = 0; |
counter = 0; |
|
Line 2159 void check_for_finished_files(int itemizing, enum logc
|
Line 2406 void check_for_finished_files(int itemizing, enum logc
|
| #endif |
#endif |
| |
|
| if (check_redo && (ndx = get_redo_num()) != -1) { |
if (check_redo && (ndx = get_redo_num()) != -1) { |
| |
OFF_T save_max_size = max_size; |
| |
OFF_T save_min_size = min_size; |
| csum_length = SUM_LENGTH; |
csum_length = SUM_LENGTH; |
| max_size = -max_size; | max_size = -1; |
| min_size = -min_size; | min_size = -1; |
| ignore_existing = -ignore_existing; |
ignore_existing = -ignore_existing; |
| ignore_non_existing = -ignore_non_existing; |
ignore_non_existing = -ignore_non_existing; |
| update_only = -update_only; |
update_only = -update_only; |
| |
downdate_only = -downdate_only; |
| |
downdate_only = -downdate_only; |
| always_checksum = -always_checksum; |
always_checksum = -always_checksum; |
| size_only = -size_only; |
size_only = -size_only; |
| append_mode = -append_mode; |
append_mode = -append_mode; |
|
Line 2185 void check_for_finished_files(int itemizing, enum logc
|
Line 2436 void check_for_finished_files(int itemizing, enum logc
|
| cur_flist = flist; |
cur_flist = flist; |
| |
|
| csum_length = SHORT_SUM_LENGTH; |
csum_length = SHORT_SUM_LENGTH; |
| max_size = -max_size; | max_size = save_max_size; |
| min_size = -min_size; | min_size = save_min_size; |
| ignore_existing = -ignore_existing; |
ignore_existing = -ignore_existing; |
| ignore_non_existing = -ignore_non_existing; |
ignore_non_existing = -ignore_non_existing; |
| update_only = -update_only; |
update_only = -update_only; |
|
Line 2206 void check_for_finished_files(int itemizing, enum logc
|
Line 2457 void check_for_finished_files(int itemizing, enum logc
|
| break; |
break; |
| |
|
| write_ndx(sock_f_out, NDX_DONE); |
write_ndx(sock_f_out, NDX_DONE); |
| if (!read_batch) | if (!read_batch && !flist_eof) { |
| maybe_flush_socket(1); | int old_total = 0; |
| | for (flist = first_flist; flist != cur_flist; flist = flist->next) |
| | old_total += flist->used; |
| | maybe_flush_socket(!flist_eof && file_total - old_total < MIN_FILECNT_LOOKAHEAD/2); |
| | } |
| |
|
| if (delete_during == 2 || !dir_tweaking) { |
if (delete_during == 2 || !dir_tweaking) { |
| /* Skip directory touch-up. */ |
/* Skip directory touch-up. */ |
|
Line 2224 void generate_files(int f_out, const char *local_name)
|
Line 2479 void generate_files(int f_out, const char *local_name)
|
| char fbuf[MAXPATHLEN]; |
char fbuf[MAXPATHLEN]; |
| int itemizing; |
int itemizing; |
| enum logcode code; |
enum logcode code; |
| int save_do_progress = do_progress; | int save_info_flist = info_levels[INFO_FLIST]; |
| | int save_info_progress = info_levels[INFO_PROGRESS]; |
| |
|
| if (protocol_version >= 29) { |
if (protocol_version >= 29) { |
| itemizing = 1; |
itemizing = 1; |
|
Line 2251 void generate_files(int f_out, const char *local_name)
|
Line 2507 void generate_files(int f_out, const char *local_name)
|
| | (protocol_version >= 30 || !am_server ? ITEM_REPORT_TIMEFAIL : 0); |
| (protocol_version >= 30 || !am_server ? ITEM_REPORT_TIMEFAIL : 0); |
| implied_dirs_are_missing = relative_paths && !implied_dirs && protocol_version < 30; |
implied_dirs_are_missing = relative_paths && !implied_dirs && protocol_version < 30; |
| |
|
| if (verbose > 2) | if (DEBUG_GTE(GENR, 1)) |
| rprintf(FINFO, "generator starting pid=%ld\n", (long)getpid()); | rprintf(FINFO, "generator starting pid=%d\n", (int)getpid()); |
| |
|
| |
if (detect_renamed) { |
| |
delayed_bits = bitbag_create(cur_flist->used); |
| |
if (!delete_before && !delete_during) |
| |
delete_during = -1; |
| |
} |
| |
|
| if (delete_before && !solo_file && cur_flist->used > 0) |
if (delete_before && !solo_file && cur_flist->used > 0) |
| do_delete_pass(); |
do_delete_pass(); |
| if (delete_during == 2) { |
if (delete_during == 2) { |
| deldelay_size = BIGPATHBUFLEN * 4; |
deldelay_size = BIGPATHBUFLEN * 4; |
| deldelay_buf = new_array(char, deldelay_size); |
deldelay_buf = new_array(char, deldelay_size); |
| if (!deldelay_buf) |
|
| out_of_memory("delete-delay"); |
|
| } |
} |
| do_progress = 0; | info_levels[INFO_FLIST] = info_levels[INFO_PROGRESS] = 0; |
| |
|
| if (append_mode > 0 || whole_file < 0) | if (append_mode > 0 || detect_renamed || whole_file < 0) |
| whole_file = 0; |
whole_file = 0; |
| if (verbose >= 2) { | if (DEBUG_GTE(FLIST, 1)) { |
| rprintf(FINFO, "delta-transmission %s\n", |
rprintf(FINFO, "delta-transmission %s\n", |
| whole_file |
whole_file |
| ? "disabled for local transfer or --whole-file" |
? "disabled for local transfer or --whole-file" |
| : "enabled"); |
: "enabled"); |
| } |
} |
| |
|
| /* Since we often fill up the outgoing socket and then just sit around | if (use_db) { |
| * waiting for the other 2 processes to do their thing, we don't want | if (always_checksum || (append_mode != 1 && protocol_version >= 30)) |
| * to exit on a timeout. If the data stops flowing, the receiver will | db_connect(0); /* Will reset use_db on error. */ |
| * notice that and let us know via the message pipe (or its closing). */ | else |
| ignore_timeout = 1; | use_db = 0; |
| | } |
| |
|
| dflt_perms = (ACCESSPERMS & ~orig_umask); |
dflt_perms = (ACCESSPERMS & ~orig_umask); |
| |
|
| do { |
do { |
| #ifdef SUPPORT_HARD_LINKS |
#ifdef SUPPORT_HARD_LINKS |
| if (preserve_hard_links && inc_recurse) { |
if (preserve_hard_links && inc_recurse) { |
| while (!flist_eof && file_total < FILECNT_LOOKAHEAD/2) | while (!flist_eof && file_total < MIN_FILECNT_LOOKAHEAD/2) |
| wait_for_receiver(); |
wait_for_receiver(); |
| } |
} |
| #endif |
#endif |
|
Line 2306 void generate_files(int f_out, const char *local_name)
|
Line 2567 void generate_files(int f_out, const char *local_name)
|
| dirdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp)); |
dirdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp)); |
| } else |
} else |
| dirdev = MAKEDEV(0, 0); |
dirdev = MAKEDEV(0, 0); |
| delete_in_dir(fbuf, fp, &dirdev); | delete_in_dir(fbuf, fp, &dirdev, 0); |
| } else |
} else |
| change_local_filter_dir(fbuf, strlen(fbuf), F_DEPTH(fp)); |
change_local_filter_dir(fbuf, strlen(fbuf), F_DEPTH(fp)); |
| } |
} |
| |
upcoming_whole_dir = fp->flags & FLAG_CONTENT_DIR ? 1 : 0; |
| } |
} |
| for (i = cur_flist->low; i <= cur_flist->high; i++) { |
for (i = cur_flist->low; i <= cur_flist->high; i++) { |
| struct file_struct *file = cur_flist->sorted[i]; |
struct file_struct *file = cur_flist->sorted[i]; |
|
Line 2332 void generate_files(int f_out, const char *local_name)
|
Line 2594 void generate_files(int f_out, const char *local_name)
|
| |
|
| if (i + cur_flist->ndx_start >= next_loopchk) { |
if (i + cur_flist->ndx_start >= next_loopchk) { |
| if (allowed_lull) |
if (allowed_lull) |
| maybe_send_keepalive(); | maybe_send_keepalive(time(NULL), MSK_ALLOW_FLUSH); |
| else |
else |
| maybe_flush_socket(0); |
maybe_flush_socket(0); |
| next_loopchk += loopchk_limit; |
next_loopchk += loopchk_limit; |
|
Line 2353 void generate_files(int f_out, const char *local_name)
|
Line 2615 void generate_files(int f_out, const char *local_name)
|
| } while ((cur_flist = cur_flist->next) != NULL); |
} while ((cur_flist = cur_flist->next) != NULL); |
| |
|
| if (delete_during) |
if (delete_during) |
| delete_in_dir(NULL, NULL, &dev_zero); | delete_in_dir(NULL, NULL, &dev_zero, 0); |
| | if (detect_renamed) { |
| | if (delete_during < 0) |
| | delete_during = 0; |
| | detect_renamed = 0; |
| | |
| | for (i = -1; (i = bitbag_next_bit(delayed_bits, i)) >= 0; ) { |
| | struct file_struct *file = cur_flist->files[i]; |
| | if (local_name) |
| | strlcpy(fbuf, local_name, sizeof fbuf); |
| | else |
| | f_name(file, fbuf); |
| | recv_generator(fbuf, file, i, itemizing, code, f_out); |
| | } |
| | } |
| phase++; |
phase++; |
| if (verbose > 2) | if (DEBUG_GTE(GENR, 1)) |
| rprintf(FINFO, "generate_files phase=%d\n", phase); |
rprintf(FINFO, "generate_files phase=%d\n", phase); |
| |
|
| while (1) { |
while (1) { |
|
Line 2366 void generate_files(int f_out, const char *local_name)
|
Line 2642 void generate_files(int f_out, const char *local_name)
|
| } |
} |
| |
|
| phase++; |
phase++; |
| if (verbose > 2) | if (DEBUG_GTE(GENR, 1)) |
| rprintf(FINFO, "generate_files phase=%d\n", phase); |
rprintf(FINFO, "generate_files phase=%d\n", phase); |
| |
|
| write_ndx(f_out, NDX_DONE); |
write_ndx(f_out, NDX_DONE); |
| |
|
| /* Reduce round-trip lag-time for a useless delay-updates phase. */ |
/* Reduce round-trip lag-time for a useless delay-updates phase. */ |
| if (protocol_version >= 29 && !delay_updates) | if (protocol_version >= 29 && EARLY_DELAY_DONE_MSG()) |
| write_ndx(f_out, NDX_DONE); |
write_ndx(f_out, NDX_DONE); |
| |
|
| |
if (protocol_version >= 31 && EARLY_DELETE_DONE_MSG()) { |
| |
if ((INFO_GTE(STATS, 2) && (delete_mode || force_delete)) || read_batch) |
| |
write_del_stats(f_out); |
| |
if (EARLY_DELAY_DONE_MSG()) /* Can't send this before delay */ |
| |
write_ndx(f_out, NDX_DONE); |
| |
} |
| |
|
| /* Read MSG_DONE for the redo phase (and any prior messages). */ |
/* Read MSG_DONE for the redo phase (and any prior messages). */ |
| while (1) { |
while (1) { |
| check_for_finished_files(itemizing, code, 0); |
check_for_finished_files(itemizing, code, 0); |
|
Line 2385 void generate_files(int f_out, const char *local_name)
|
Line 2668 void generate_files(int f_out, const char *local_name)
|
| |
|
| if (protocol_version >= 29) { |
if (protocol_version >= 29) { |
| phase++; |
phase++; |
| if (verbose > 2) | if (DEBUG_GTE(GENR, 1)) |
| rprintf(FINFO, "generate_files phase=%d\n", phase); |
rprintf(FINFO, "generate_files phase=%d\n", phase); |
| if (delay_updates) | if (!EARLY_DELAY_DONE_MSG()) { |
| write_ndx(f_out, NDX_DONE); |
write_ndx(f_out, NDX_DONE); |
| |
if (protocol_version >= 31 && EARLY_DELETE_DONE_MSG()) |
| |
write_ndx(f_out, NDX_DONE); |
| |
} |
| /* Read MSG_DONE for delay-updates phase & prior messages. */ |
/* Read MSG_DONE for delay-updates phase & prior messages. */ |
| while (msgdone_cnt == 2) |
while (msgdone_cnt == 2) |
| wait_for_receiver(); |
wait_for_receiver(); |
| } |
} |
| |
|
| do_progress = save_do_progress; | if (checksum_files) |
| | reset_checksum_cache(started_whole_dir); |
| | |
| | if (use_db) |
| | db_disconnect(True); |
| | |
| | info_levels[INFO_FLIST] = save_info_flist; |
| | info_levels[INFO_PROGRESS] = save_info_progress; |
| | |
| if (delete_during == 2) |
if (delete_during == 2) |
| do_delayed_deletions(fbuf); |
do_delayed_deletions(fbuf); |
| if (delete_after && !solo_file && file_total > 0) |
if (delete_after && !solo_file && file_total > 0) |
| do_delete_pass(); |
do_delete_pass(); |
| |
|
| if ((need_retouch_dir_perms || need_retouch_dir_times) | if (max_delete >= 0 && skipped_deletes) { |
| && dir_tweaking && (!inc_recurse || delete_during == 2)) | |
| touch_up_dirs(dir_flist, -1); | |
| |
| if (max_delete >= 0 && deletion_count > max_delete) { | |
| rprintf(FWARNING, |
rprintf(FWARNING, |
| "Deletions stopped due to --max-delete limit (%d skipped)\n", |
"Deletions stopped due to --max-delete limit (%d skipped)\n", |
| deletion_count - max_delete); | skipped_deletes); |
| io_error |= IOERR_DEL_LIMIT; |
io_error |= IOERR_DEL_LIMIT; |
| } |
} |
| |
|
| if (verbose > 2) | if (protocol_version >= 31) { |
| | if (!EARLY_DELETE_DONE_MSG()) { |
| | if (INFO_GTE(STATS, 2) || read_batch) |
| | write_del_stats(f_out); |
| | write_ndx(f_out, NDX_DONE); |
| | } |
| | |
| | /* Read MSG_DONE for late-delete phase & prior messages. */ |
| | while (msgdone_cnt == 3) |
| | wait_for_receiver(); |
| | } |
| | |
| | if ((need_retouch_dir_perms || need_retouch_dir_times) |
| | && dir_tweaking && (!inc_recurse || delete_during == 2)) |
| | touch_up_dirs(dir_flist, -1); |
| | |
| | if (DEBUG_GTE(GENR, 1)) |
| rprintf(FINFO, "generate_files finished\n"); |
rprintf(FINFO, "generate_files finished\n"); |
| } |
} |