* Copyright (C) 1996 Andrew Tridgell
* Copyright (C) 1996 Paul Mackerras
* Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2002-2008 Wayne Davison
+ * Copyright (C) 2002-2009 Wayne Davison
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
extern int unsort_ndx;
extern struct stats stats;
extern char *filesfrom_host;
+extern char *usermap, *groupmap;
extern char curr_dir[MAXPATHLEN];
static char empty_sum[MAX_DIGEST_LEN];
static int flist_count_offset; /* for --delete --progress */
-static int dir_count = 0;
static void flist_sort_and_clean(struct file_list *flist, int strip_root);
static void output_flist(struct file_list *flist);
int l1, l2;
int xflags;
- /* Initialize starting value of xflags. */
- if (protocol_version >= 30 && S_ISDIR(file->mode)) {
- dir_count++;
- if (file->flags & FLAG_CONTENT_DIR)
- xflags = file->flags & FLAG_TOP_DIR;
- else if (file->flags & FLAG_IMPLIED_DIR)
- xflags = XMIT_TOP_DIR | XMIT_NO_CONTENT_DIR;
+ /* Initialize starting value of xflags and adjust counts. */
+ if (S_ISREG(file->mode))
+ xflags = 0;
+ else if (S_ISDIR(file->mode)) {
+ stats.num_dirs++;
+ if (protocol_version >= 30) {
+ if (file->flags & FLAG_CONTENT_DIR)
+ xflags = file->flags & FLAG_TOP_DIR;
+ else if (file->flags & FLAG_IMPLIED_DIR)
+ xflags = XMIT_TOP_DIR | XMIT_NO_CONTENT_DIR;
+ else
+ xflags = XMIT_NO_CONTENT_DIR;
+ } else
+ xflags = file->flags & FLAG_TOP_DIR; /* FLAG_TOP_DIR == XMIT_TOP_DIR */
+ } else {
+ if (S_ISLNK(file->mode))
+ stats.num_symlinks++;
+ else if (IS_DEVICE(file->mode))
+ stats.num_devices++;
else
- xflags = XMIT_NO_CONTENT_DIR;
- } else
- xflags = file->flags & FLAG_TOP_DIR; /* FLAG_TOP_DIR == XMIT_TOP_DIR */
+ stats.num_specials++;
+ xflags = 0;
+ }
if (file->mode == mode)
xflags |= XMIT_SAME_MODE;
uid = (uid_t)read_varint(f);
if (xflags & XMIT_USER_NAME_FOLLOWS)
uid = recv_user_name(f, uid);
- else if (inc_recurse && am_root && !numeric_ids)
+ else if (inc_recurse && am_root && (!numeric_ids || usermap))
uid = match_uid(uid);
}
}
gid_flags = 0;
if (xflags & XMIT_GROUP_NAME_FOLLOWS)
gid = recv_group_name(f, gid, &gid_flags);
- else if (inc_recurse && (!am_root || !numeric_ids))
+ else if (inc_recurse && (!am_root || !numeric_ids || groupmap))
gid = match_gid(gid, &gid_flags);
}
}
else if (!pool)
F_DEPTH(file) = extra_len / EXTRA_LEN;
- /* This code is only used by the receiver when it is building
- * a list of files for a delete pass. */
- if (keep_dirlinks && linkname_len && flist) {
- STRUCT_STAT st2;
- int save_mode = file->mode;
- file->mode = S_IFDIR; /* Find a directory with our name. */
- if (flist_find(dir_flist, file) >= 0
- && x_stat(thisname, &st2, NULL) == 0 && S_ISDIR(st2.st_mode)) {
- file->modtime = st2.st_mtime;
- file->len32 = 0;
- file->mode = st2.st_mode;
- if (uid_ndx)
- F_OWNER(file) = st2.st_uid;
- if (gid_ndx)
- F_GROUP(file) = st2.st_gid;
- } else
- file->mode = save_mode;
- }
-
if (basename_len == 0+1) {
if (!pool)
unmake_file(file);
memcpy(F_SUM(file), tmp_sum, checksum_len);
if (unsort_ndx)
- F_NDX(file) = dir_count;
+ F_NDX(file) = stats.num_dirs;
return file;
}
#endif
#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
stat_x sx;
+ init_stat_x(&sx);
#endif
#ifdef SUPPORT_LINKS
#ifdef SUPPORT_ACLS
if (preserve_acls && !S_ISLNK(file->mode)) {
sx.st.st_mode = file->mode;
- sx.acc_acl = sx.def_acl = NULL;
if (get_acl(fname, &sx) < 0) {
io_error |= IOERR_GENERAL;
return NULL;
#endif
#ifdef SUPPORT_XATTRS
if (preserve_xattrs) {
- sx.xattr = NULL;
if (get_xattr(fname, &sx) < 0) {
io_error |= IOERR_GENERAL;
return NULL;
assert(flist != NULL);
if (!(d = opendir(fbuf))) {
+ if (errno == ENOENT)
+ return;
io_error |= IOERR_GENERAL;
rsyserr(FERROR_XFER, errno, "opendir %s failed", full_fname(fbuf));
return;
old_cnt += flist->used;
while (file_total - old_cnt < at_least) {
struct file_struct *file = dir_flist->sorted[send_dir_ndx];
- int dir_ndx, dstart = dir_count;
+ int dir_ndx, dstart = stats.num_dirs;
const char *pathname = F_PATHNAME(file);
int32 *dp;
write_byte(f, 0);
else {
write_shortint(f, XMIT_EXTENDED_FLAGS|XMIT_IO_ERROR_ENDLIST);
- write_int(f, io_error);
+ write_varint(f, io_error);
}
if (need_unsorted_flist) {
flist_sort_and_clean(flist, 0);
- add_dirs_to_tree(send_dir_ndx, flist, dir_count - dstart);
+ add_dirs_to_tree(send_dir_ndx, flist, stats.num_dirs - dstart);
flist_done_allocating(flist);
file_total += flist->used;
start_write = stats.total_written;
gettimeofday(&start_tv, NULL);
- if (!orig_dir)
- orig_dir = strdup(curr_dir);
-
if (relative_paths && protocol_version >= 30)
implied_dirs = 1; /* We send flagged implied dirs */
use_ff_fd = 1;
}
+ if (!orig_dir)
+ orig_dir = strdup(curr_dir);
+
while (1) {
char fbuf[MAXPATHLEN], *fn, name_type;
write_byte(f, 0);
else {
write_shortint(f, XMIT_EXTENDED_FLAGS|XMIT_IO_ERROR_ENDLIST);
- write_int(f, io_error);
+ write_varint(f, io_error);
}
#ifdef SUPPORT_HARD_LINKS
if (inc_recurse) {
send_dir_depth = 1;
- add_dirs_to_tree(-1, flist, dir_count);
+ add_dirs_to_tree(-1, flist, stats.num_dirs);
if (!file_total || strcmp(flist->sorted[flist->low]->basename, ".") != 0)
flist->parent_ndx = -1;
flist_done_allocating(flist);
else if (inc_recurse && INFO_GTE(FLIST, 1) && !am_server)
rprintf(FCLIENT, "receiving incremental file list\n");
rprintf(FLOG, "receiving file list\n");
+ if (usermap)
+ parse_name_map(usermap, True);
+ if (groupmap)
+ parse_name_map(groupmap, False);
}
start_read = stats.total_read;
rprintf(FERROR, "Invalid flist flag: %x\n", flags);
exit_cleanup(RERR_PROTOCOL);
}
- err = read_int(f);
+ err = read_varint(f);
if (!ignore_errors)
io_error |= err;
break;
flist_expand(flist, 1);
file = recv_file_entry(flist, flags, f);
- if (inc_recurse && S_ISDIR(file->mode)) {
- flist_expand(dir_flist, 1);
- dir_flist->files[dir_flist->used++] = file;
- }
+ if (S_ISREG(file->mode)) {
+ /* Already counted */
+ } else if (S_ISDIR(file->mode)) {
+ if (inc_recurse) {
+ flist_expand(dir_flist, 1);
+ dir_flist->files[dir_flist->used++] = file;
+ }
+ stats.num_dirs++;
+ } else if (S_ISLNK(file->mode))
+ stats.num_symlinks++;
+ else if (IS_DEVICE(file->mode))
+ stats.num_symlinks++;
+ else
+ stats.num_specials++;
flist->files[flist->used++] = file;
return -1;
}
+/* Search for an identically-named item in the file list. Differs from
+ * flist_find in that an item that agrees with "f" in directory-ness is
+ * preferred but one that does not is still found. */
+int flist_find_ignore_dirness(struct file_list *flist, struct file_struct *f)
+{
+ mode_t save_mode;
+ int ndx;
+
+ /* First look for an item that agrees in directory-ness. */
+ ndx = flist_find(flist, f);
+ if (ndx >= 0)
+ return ndx;
+
+ /* Temporarily flip f->mode to look for an item of opposite
+ * directory-ness. */
+ save_mode = f->mode;
+ f->mode = S_ISDIR(f->mode) ? S_IFREG : S_IFDIR;
+ ndx = flist_find(flist, f);
+ f->mode = save_mode;
+ return ndx;
+}
+
/*
* Free up any resources a file_struct has allocated
* and clear the file.