extern int csum_length;
extern int ignore_times;
extern int size_only;
+extern OFF_T max_size;
extern int io_timeout;
extern int protocol_version;
extern int always_checksum;
extern char *partial_dir;
-extern char *compare_dest;
+extern char *basis_dir[];
+extern int copy_dest;
extern int link_dest;
extern int whole_file;
extern int local_server;
extern struct exclude_list_struct server_exclude_list;
-
-/* choose whether to skip a particular file */
-static int skip_file(char *fname, struct file_struct *file, STRUCT_STAT *st)
+static int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
{
- if (st->st_size != file->length)
+ if (preserve_perms
+ && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
return 0;
- if (link_dest) {
- if (preserve_perms
- && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
- return 0;
- if (am_root && preserve_uid && st->st_uid != file->uid)
- return 0;
+ if (am_root && preserve_uid && st->st_uid != file->uid)
+ return 0;
- if (preserve_gid && file->gid != GID_NONE
- && st->st_gid != file->gid)
- return 0;
- }
+ if (preserve_gid && file->gid != GID_NONE && st->st_gid != file->gid)
+ return 0;
+
+ return 1;
+}
+
+/* Perform our quick-check heuristic for determining if a file is unchanged. */
+static int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
+{
+ if (st->st_size != file->length)
+ return 0;
/* if always checksum is set then we use the checksum instead
of the file time to determine whether to sync */
if (always_checksum && S_ISREG(st->st_mode)) {
char sum[MD4_SUM_LENGTH];
- file_checksum(fname,sum,st->st_size);
+ file_checksum(fn, sum, st->st_size);
return memcmp(sum, file->u.sum, protocol_version < 21 ? 2
: MD4_SUM_LENGTH) == 0;
}
*
* This might be made one of several selectable heuristics.
*/
-
static void sum_sizes_sqroot(struct sum_struct *sum, uint64 len)
{
unsigned int blength;
&& verbose && f_out != -1)
rprintf(FINFO, "%s/\n", safe_fname(fname));
return;
+ } else if (max_size && file->length > max_size) {
+ if (verbose > 1)
+ rprintf(FINFO, "%s is over max-size\n", fname);
+ return;
}
if (preserve_links && S_ISLNK(file->mode)) {
fnamecmp = fname;
fnamecmp_type = FNAMECMP_FNAME;
- if (statret == -1 && compare_dest != NULL) {
- /* try the file at compare_dest instead */
- pathjoin(fnamecmpbuf, sizeof fnamecmpbuf, compare_dest, fname);
- if (link_stat(fnamecmpbuf, &st, 0) == 0
- && S_ISREG(st.st_mode)) {
+ if (statret == -1 && basis_dir[0] != NULL) {
+ int fallback_match = -1;
+ int match_level = 0;
+ int i = 0;
+ do {
+ pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
+ basis_dir[i], fname);
+ if (link_stat(fnamecmpbuf, &st, 0) == 0
+ && S_ISREG(st.st_mode)) {
+ statret = 0;
+ if (link_dest) {
+ if (!match_level) {
+ fallback_match = i;
+ match_level = 1;
+ } else if (match_level == 2
+ && !unchanged_attrs(file, &st))
+ continue;
+ if (!unchanged_file(fnamecmpbuf, file, &st))
+ continue;
+ fallback_match = i;
+ match_level = 2;
+ if (!unchanged_attrs(file, &st))
+ continue;
+ }
+ match_level = 3;
+ break;
+ }
+ } while (basis_dir[++i] != NULL);
+ if (statret == 0) {
+ if (match_level < 3) {
+ i = fallback_match;
+ pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
+ basis_dir[i], fname);
+ }
#if HAVE_LINK
- if (link_dest && !dry_run) {
+ if (link_dest && match_level == 3 && !dry_run) {
if (do_link(fnamecmpbuf, fname) < 0) {
if (verbose) {
rsyserr(FINFO, errno,
safe_fname(fname));
}
fnamecmp = fnamecmpbuf;
- fnamecmp_type = FNAMECMP_CMPDEST;
+ fnamecmp_type = FNAMECMP_BASIS_DIR + i;
}
} else
#endif
{
fnamecmp = fnamecmpbuf;
- fnamecmp_type = FNAMECMP_CMPDEST;
+ fnamecmp_type = FNAMECMP_BASIS_DIR + i;
}
- statret = 0;
}
}
return;
}
- if (skip_file(fnamecmp, file, &st)) {
+ if ((link_dest || copy_dest) && fnamecmp_type != FNAMECMP_FNAME)
+ ;
+ else if (unchanged_file(fnamecmp, file, &st)) {
if (fnamecmp_type == FNAMECMP_FNAME)
set_perms(fname, file, &st, PERMS_REPORT);
return;