Matt McCutchen's Web Site
/
rsync
/
rsync.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use AC_SEARCH_LIBS() instead of AC_CHECK_LIB() to figure out if
[rsync/rsync.git]
/
flist.c
diff --git
a/flist.c
b/flist.c
index
a80e0fb
..
8f26f03
100644
(file)
--- a/
flist.c
+++ b/
flist.c
@@
-62,10
+62,13
@@
extern struct file_list *the_file_list;
extern char curr_dir[MAXPATHLEN];
extern char curr_dir[MAXPATHLEN];
+extern struct chmod_mode_struct *chmod_modes;
+
extern struct filter_list_struct filter_list;
extern struct filter_list_struct server_filter_list;
int io_error;
extern struct filter_list_struct filter_list;
extern struct filter_list_struct server_filter_list;
int io_error;
+int checksum_len;
dev_t filesystem_dev; /* used to implement -x */
static char empty_sum[MD4_SUM_LENGTH];
dev_t filesystem_dev; /* used to implement -x */
static char empty_sum[MD4_SUM_LENGTH];
@@
-82,9
+85,9
@@
void init_flist(void)
/* Figure out how big the file_struct is without trailing padding */
file_struct_len = offsetof(struct file_struct, flags) + sizeof f.flags;
/* Figure out how big the file_struct is without trailing padding */
file_struct_len = offsetof(struct file_struct, flags) + sizeof f.flags;
+ checksum_len = protocol_version < 21 ? 2 : MD4_SUM_LENGTH;
}
}
-
static int show_filelist_p(void)
{
return verbose && xfer_dirs && !am_server;
static int show_filelist_p(void)
{
return verbose && xfer_dirs && !am_server;
@@
-98,20
+101,17
@@
static void start_filelist_progress(char *kind)
rflush(FINFO);
}
rflush(FINFO);
}
-
static void emit_filelist_progress(int count)
{
rprintf(FINFO, " %d files...\r", count);
}
static void emit_filelist_progress(int count)
{
rprintf(FINFO, " %d files...\r", count);
}
-
static void maybe_emit_filelist_progress(int count)
{
if (do_progress && show_filelist_p() && (count % 100) == 0)
emit_filelist_progress(count);
}
static void maybe_emit_filelist_progress(int count)
{
if (do_progress && show_filelist_p() && (count % 100) == 0)
emit_filelist_progress(count);
}
-
static void finish_filelist_progress(const struct file_list *flist)
{
if (do_progress) {
static void finish_filelist_progress(const struct file_list *flist)
{
if (do_progress) {
@@
-127,7
+127,6
@@
void show_flist_stats(void)
/* Nothing yet */
}
/* Nothing yet */
}
-
static void list_file_entry(struct file_struct *f)
{
char perms[11];
static void list_file_entry(struct file_struct *f)
{
char perms[11];
@@
-155,7
+154,6
@@
static void list_file_entry(struct file_struct *f)
}
}
}
}
-
/**
* Stat either a symlink or its referent, depending on the settings of
* copy_links, copy_unsafe_links, etc.
/**
* Stat either a symlink or its referent, depending on the settings of
* copy_links, copy_unsafe_links, etc.
@@
-261,7
+259,6
@@
static mode_t from_wire_mode(int mode)
return (mode_t)mode;
}
return (mode_t)mode;
}
-
static void send_directory(int f, struct file_list *flist,
char *fbuf, int len);
static void send_directory(int f, struct file_list *flist,
char *fbuf, int len);
@@
-480,14
+477,13
@@
void send_file_entry(struct file_struct *file, int f, unsigned short base_flags)
if (always_checksum && (S_ISREG(mode) || protocol_version < 28)) {
char *sum;
if (always_checksum && (S_ISREG(mode) || protocol_version < 28)) {
char *sum;
- int slen = protocol_version < 21 ? 2 : MD4_SUM_LENGTH;
if (S_ISREG(mode))
sum = file->u.sum;
else {
/* Prior to 28, we sent a useless set of nulls. */
sum = empty_sum;
}
if (S_ISREG(mode))
sum = file->u.sum;
else {
/* Prior to 28, we sent a useless set of nulls. */
sum = empty_sum;
}
- write_buf(f, sum,
s
len);
+ write_buf(f, sum,
checksum_
len);
}
strlcpy(lastname, fname, MAXPATHLEN);
}
strlcpy(lastname, fname, MAXPATHLEN);
@@
-495,8
+491,6
@@
void send_file_entry(struct file_struct *file, int f, unsigned short base_flags)
io_write_phase = "unknown";
}
io_write_phase = "unknown";
}
-
-
static struct file_struct *receive_file_entry(struct file_list *flist,
unsigned short flags, int f)
{
static struct file_struct *receive_file_entry(struct file_list *flist,
unsigned short flags, int f)
{
@@
-705,7
+699,6
@@
static struct file_struct *receive_file_entry(struct file_list *flist,
if (always_checksum && (sum_len || protocol_version < 28)) {
char *sum;
if (always_checksum && (sum_len || protocol_version < 28)) {
char *sum;
- int slen = protocol_version < 21 ? 2 : MD4_SUM_LENGTH;
if (sum_len) {
file->u.sum = sum = bp;
/*bp += sum_len;*/
if (sum_len) {
file->u.sum = sum = bp;
/*bp += sum_len;*/
@@
-713,7
+706,7
@@
static struct file_struct *receive_file_entry(struct file_list *flist,
/* Prior to 28, we get a useless set of nulls. */
sum = empty_sum;
}
/* Prior to 28, we get a useless set of nulls. */
sum = empty_sum;
}
- read_buf(f, sum,
s
len);
+ read_buf(f, sum,
checksum_
len);
}
if (!preserve_perms) {
}
if (!preserve_perms) {
@@
-725,7
+718,6
@@
static struct file_struct *receive_file_entry(struct file_list *flist,
return file;
}
return file;
}
-
/**
* Create a file_struct for a named file by reading its stat()
* information and performing extensive checks against global
/**
* Create a file_struct for a named file by reading its stat()
* information and performing extensive checks against global
@@
-828,7
+820,7
@@
struct file_struct *make_file(char *fname, struct file_list *flist,
return NULL;
}
return NULL;
}
-skip_filters:
+
skip_filters:
if (verbose > 2) {
rprintf(FINFO, "[%s] make_file(%s,*,%d)\n",
if (verbose > 2) {
rprintf(FINFO, "[%s] make_file(%s,*,%d)\n",
@@
-856,7
+848,8
@@
skip_filters:
linkname_len = 0;
#endif
linkname_len = 0;
#endif
- sum_len = always_checksum && S_ISREG(st.st_mode) ? MD4_SUM_LENGTH : 0;
+ sum_len = always_checksum && am_sender && S_ISREG(st.st_mode)
+ ? MD4_SUM_LENGTH : 0;
alloc_len = file_struct_len + dirname_len + basename_len
+ linkname_len + sum_len;
alloc_len = file_struct_len + dirname_len + basename_len
+ linkname_len + sum_len;
@@
-875,7
+868,10
@@
skip_filters:
file->flags = flags;
file->modtime = st.st_mtime;
file->length = st.st_size;
file->flags = flags;
file->modtime = st.st_mtime;
file->length = st.st_size;
- file->mode = st.st_mode;
+ if (chmod_modes && am_sender && (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode)))
+ file->mode = tweak_mode(st.st_mode, chmod_modes);
+ else
+ file->mode = st.st_mode;
file->uid = st.st_uid;
file->gid = st.st_gid;
file->uid = st.st_uid;
file->gid = st.st_gid;
@@
-957,7
+953,6
@@
skip_filters:
return file;
}
return file;
}
-
static struct file_struct *send_file_name(int f, struct file_list *flist,
char *fname, unsigned short base_flags)
{
static struct file_struct *send_file_name(int f, struct file_list *flist,
char *fname, unsigned short base_flags)
{
@@
-979,9
+974,10
@@
static struct file_struct *send_file_name(int f, struct file_list *flist,
}
static void send_if_directory(int f, struct file_list *flist,
}
static void send_if_directory(int f, struct file_list *flist,
- struct file_struct *file)
+ struct file_struct *file,
+ char *fbuf, unsigned int ol)
{
{
- char
fbuf[MAXPATHLEN]
;
+ char
is_dot_dir = fbuf[ol-1] == '.' && (ol == 1 || fbuf[ol-2] == '/')
;
if (S_ISDIR(file->mode)
&& !(file->flags & FLAG_MOUNT_POINT) && f_name_to(file, fbuf)) {
if (S_ISDIR(file->mode)
&& !(file->flags & FLAG_MOUNT_POINT) && f_name_to(file, fbuf)) {
@@
-998,10
+994,12
@@
static void send_if_directory(int f, struct file_list *flist,
save_filters = push_local_filters(fbuf, len);
send_directory(f, flist, fbuf, len);
pop_local_filters(save_filters);
save_filters = push_local_filters(fbuf, len);
send_directory(f, flist, fbuf, len);
pop_local_filters(save_filters);
+ fbuf[ol] = '\0';
+ if (is_dot_dir)
+ fbuf[ol-1] = '.';
}
}
}
}
-
/* This function is normally called by the sender, but the receiving side also
* calls it from get_dirlist() with f set to -1 so that we just construct the
* file list in memory without sending it over the wire. Also, get_dirlist()
/* This function is normally called by the sender, but the receiving side also
* calls it from get_dirlist() with f set to -1 so that we just construct the
* file list in memory without sending it over the wire. Also, get_dirlist()
@@
-1055,14
+1053,13
@@
static void send_directory(int f, struct file_list *flist,
if (recurse) {
int i, end = flist->count - 1;
for (i = start; i <= end; i++)
if (recurse) {
int i, end = flist->count - 1;
for (i = start; i <= end; i++)
- send_if_directory(f, flist, flist->files[i]);
+ send_if_directory(f, flist, flist->files[i]
, fbuf, len
);
}
}
}
}
-
struct file_list *send_file_list(int f, int argc, char *argv[])
{
struct file_list *send_file_list(int f, int argc, char *argv[])
{
- int l;
+ int l
en
;
STRUCT_STAT st;
char *p, *dir, olddir[sizeof curr_dir];
char lastpath[MAXPATHLEN] = "";
STRUCT_STAT st;
char *p, *dir, olddir[sizeof curr_dir];
char lastpath[MAXPATHLEN] = "";
@@
-1090,57
+1087,57
@@
struct file_list *send_file_list(int f, int argc, char *argv[])
}
while (1) {
}
while (1) {
- char f
name2
[MAXPATHLEN];
- char *fn
ame = fname2
;
+ char f
buf
[MAXPATHLEN];
+ char *fn;
int is_dot_dir;
if (use_ff_fd) {
int is_dot_dir;
if (use_ff_fd) {
- if (read_filesfrom_line(filesfrom_fd, f
name
) == 0)
+ if (read_filesfrom_line(filesfrom_fd, f
buf
) == 0)
break;
break;
- sanitize_path(f
name, fname
, "", 0);
+ sanitize_path(f
buf, fbuf
, "", 0);
} else {
if (argc-- == 0)
break;
} else {
if (argc-- == 0)
break;
- strlcpy(f
name
, *argv++, MAXPATHLEN);
+ strlcpy(f
buf
, *argv++, MAXPATHLEN);
if (sanitize_paths)
if (sanitize_paths)
- sanitize_path(f
name, fname
, "", 0);
+ sanitize_path(f
buf, fbuf
, "", 0);
}
}
- l
= strlen(fname
);
- if (!l
|| fname[l
- 1] == '/') {
- if (l
== 2 && fname
[0] == '.') {
+ l
en = strlen(fbuf
);
+ if (!l
en || fbuf[len
- 1] == '/') {
+ if (l
en == 2 && fbuf
[0] == '.') {
/* Turn "./" into just "." rather than "./." */
/* Turn "./" into just "." rather than "./." */
- f
name
[1] = '\0';
+ f
buf
[1] = '\0';
} else {
} else {
- if (l + 1 >= MAXPATHLEN)
+ if (l
en
+ 1 >= MAXPATHLEN)
overflow_exit("send_file_list");
overflow_exit("send_file_list");
- f
name[l
++] = '.';
- f
name[l
] = '\0';
+ f
buf[len
++] = '.';
+ f
buf[len
] = '\0';
}
is_dot_dir = 1;
}
is_dot_dir = 1;
- } else if (l
> 1 && fname[l-1] == '.' && fname[l
-2] == '.'
- && (l
== 2 || fname[l
-3] == '/')) {
- if (l + 2 >= MAXPATHLEN)
+ } else if (l
en > 1 && fbuf[len-1] == '.' && fbuf[len
-2] == '.'
+ && (l
en == 2 || fbuf[len
-3] == '/')) {
+ if (l
en
+ 2 >= MAXPATHLEN)
overflow_exit("send_file_list");
overflow_exit("send_file_list");
- f
name[l
++] = '/';
- f
name[l
++] = '.';
- f
name[l
] = '\0';
+ f
buf[len
++] = '/';
+ f
buf[len
++] = '.';
+ f
buf[len
] = '\0';
is_dot_dir = 1;
} else {
is_dot_dir = 1;
} else {
- is_dot_dir = f
name[l
-1] == '.'
- && (l
== 1 || fname[l
-2] == '/');
+ is_dot_dir = f
buf[len
-1] == '.'
+ && (l
en == 1 || fbuf[len
-2] == '/');
}
}
- if (link_stat(f
name
, &st, keep_dirlinks) != 0) {
+ if (link_stat(f
buf
, &st, keep_dirlinks) != 0) {
io_error |= IOERR_GENERAL;
rsyserr(FERROR, errno, "link_stat %s failed",
io_error |= IOERR_GENERAL;
rsyserr(FERROR, errno, "link_stat %s failed",
- full_fname(f
name
));
+ full_fname(f
buf
));
continue;
}
if (S_ISDIR(st.st_mode) && !xfer_dirs) {
rprintf(FINFO, "skipping directory %s\n",
continue;
}
if (S_ISDIR(st.st_mode) && !xfer_dirs) {
rprintf(FINFO, "skipping directory %s\n",
- safe_fname(f
name
));
+ safe_fname(f
buf
));
continue;
}
continue;
}
@@
-1148,26
+1145,32
@@
struct file_list *send_file_list(int f, int argc, char *argv[])
olddir[0] = '\0';
if (!relative_paths) {
olddir[0] = '\0';
if (!relative_paths) {
- p = strrchr(f
name
, '/');
+ p = strrchr(f
buf
, '/');
if (p) {
*p = '\0';
if (p) {
*p = '\0';
- if (p == f
name
)
+ if (p == f
buf
)
dir = "/";
else
dir = "/";
else
- dir = fname;
- fname = p + 1;
- }
- } else if ((p = strstr(fname, "/./")) != NULL) {
+ dir = fbuf;
+ len -= p - fbuf + 1;
+ fn = p + 1;
+ } else
+ fn = fbuf;
+ } else if ((p = strstr(fbuf, "/./")) != NULL) {
*p = '\0';
*p = '\0';
- if (p == f
name
)
+ if (p == f
buf
)
dir = "/";
else
dir = "/";
else
- dir = fname;
- fname = p + 3;
- }
+ dir = fbuf;
+ len -= p - fbuf + 3;
+ fn = p + 3;
+ } else
+ fn = fbuf;
- if (!*fname)
- fname = ".";
+ if (!*fn) {
+ len = 1;
+ fn = ".";
+ }
if (dir && *dir) {
static char *lastdir;
if (dir && *dir) {
static char *lastdir;
@@
-1191,17
+1194,19
@@
struct file_list *send_file_list(int f, int argc, char *argv[])
}
}
}
}
- if (implied_dirs && (p=strrchr(fname,'/')) && p != fname) {
+ if (fn != fbuf)
+ memmove(fbuf, fn, len + 1);
+
+ if (implied_dirs && (p=strrchr(fbuf,'/')) && p != fbuf) {
/* Send the implied directories at the start of the
* source spec, so we get their permissions right. */
/* Send the implied directories at the start of the
* source spec, so we get their permissions right. */
- char *lp = lastpath, *
fn = fname, *slash = fname
;
+ char *lp = lastpath, *
slash = fbuf
;
*p = '\0';
/* Skip any initial directories in our path that we
* have in common with lastpath. */
*p = '\0';
/* Skip any initial directories in our path that we
* have in common with lastpath. */
-
while (*fn && *lp == *fn
) {
+
for (fn = fbuf; *fn && *lp == *fn; lp++, fn++
) {
if (*fn == '/')
slash = fn;
if (*fn == '/')
slash = fn;
- lp++, fn++;
}
*p = '/';
if (fn != p || (*lp && *lp != '/')) {
}
*p = '/';
if (fn != p || (*lp && *lp != '/')) {
@@
-1211,13
+1216,13
@@
struct file_list *send_file_list(int f, int argc, char *argv[])
xfer_dirs = 1;
while ((slash = strchr(slash+1, '/')) != 0) {
*slash = '\0';
xfer_dirs = 1;
while ((slash = strchr(slash+1, '/')) != 0) {
*slash = '\0';
- send_file_name(f, flist, f
name
, 0);
+ send_file_name(f, flist, f
buf
, 0);
*slash = '/';
}
copy_links = save_copy_links;
xfer_dirs = save_xfer_dirs;
*p = '\0';
*slash = '/';
}
copy_links = save_copy_links;
xfer_dirs = save_xfer_dirs;
*p = '\0';
- strlcpy(lastpath, f
name
, sizeof lastpath);
+ strlcpy(lastpath, f
buf
, sizeof lastpath);
*p = '/';
}
}
*p = '/';
}
}
@@
-1227,10
+1232,10
@@
struct file_list *send_file_list(int f, int argc, char *argv[])
if (recurse || (xfer_dirs && is_dot_dir)) {
struct file_struct *file;
if (recurse || (xfer_dirs && is_dot_dir)) {
struct file_struct *file;
- if ((file = send_file_name(f, flist, f
name
, XMIT_TOP_DIR)))
- send_if_directory(f, flist, file);
+ if ((file = send_file_name(f, flist, f
buf
, XMIT_TOP_DIR)))
+ send_if_directory(f, flist, file
, fbuf, len
);
} else
} else
- send_file_name(f, flist, f
name
, 0);
+ send_file_name(f, flist, f
buf
, 0);
if (olddir[0]) {
flist_dir = NULL;
if (olddir[0]) {
flist_dir = NULL;
@@
-1290,7
+1295,6
@@
struct file_list *send_file_list(int f, int argc, char *argv[])
return flist;
}
return flist;
}
-
struct file_list *recv_file_list(int f)
{
struct file_list *flist;
struct file_list *recv_file_list(int f)
{
struct file_list *flist;
@@
-1310,7
+1314,6
@@
struct file_list *recv_file_list(int f)
if (!flist->files)
goto oom;
if (!flist->files)
goto oom;
-
while ((flags = read_byte(f)) != 0) {
struct file_struct *file;
while ((flags = read_byte(f)) != 0) {
struct file_struct *file;
@@
-1371,18
+1374,16
@@
struct file_list *recv_file_list(int f)
return flist;
return flist;
-oom:
+
oom:
out_of_memory("recv_file_list");
return NULL; /* not reached */
}
out_of_memory("recv_file_list");
return NULL; /* not reached */
}
-
static int file_compare(struct file_struct **file1, struct file_struct **file2)
{
return f_name_cmp(*file1, *file2);
}
static int file_compare(struct file_struct **file1, struct file_struct **file2)
{
return f_name_cmp(*file1, *file2);
}
-
/* Search for an identically-named item in the file list. Note that the
* items must agree in their directory-ness, or no match is returned. */
int flist_find(struct file_list *flist, struct file_struct *f)
/* Search for an identically-named item in the file list. Note that the
* items must agree in their directory-ness, or no match is returned. */
int flist_find(struct file_list *flist, struct file_struct *f)
@@
-1412,7
+1413,6
@@
int flist_find(struct file_list *flist, struct file_struct *f)
return -1;
}
return -1;
}
-
/*
* Free up any resources a file_struct has allocated
* and clear the file.
/*
* Free up any resources a file_struct has allocated
* and clear the file.
@@
-1424,7
+1424,6
@@
void clear_file(int i, struct file_list *flist)
memset(flist->files[i], 0, file_struct_len);
}
memset(flist->files[i], 0, file_struct_len);
}
-
/*
* allocate a new file list
*/
/*
* allocate a new file list
*/
@@
-1464,7
+1463,6
@@
void flist_free(struct file_list *flist)
free(flist);
}
free(flist);
}
-
/*
* This routine ensures we don't have any duplicate names in our file list.
* duplicate names can cause corruption because of the pipelining
/*
* This routine ensures we don't have any duplicate names in our file list.
* duplicate names can cause corruption because of the pipelining
@@
-1569,7
+1567,6
@@
static void clean_flist(struct file_list *flist, int strip_root, int no_dups)
}
}
}
}
-
static void output_flist(struct file_list *flist)
{
char uidbuf[16], gidbuf[16], depthbuf[16];
static void output_flist(struct file_list *flist)
{
char uidbuf[16], gidbuf[16], depthbuf[16];
@@
-1598,7
+1595,6
@@
static void output_flist(struct file_list *flist)
}
}
}
}
-
enum fnc_state { s_DIR, s_SLASH, s_BASE, s_TRAILING };
enum fnc_type { t_PATH, t_ITEM };
enum fnc_state { s_DIR, s_SLASH, s_BASE, s_TRAILING };
enum fnc_type { t_PATH, t_ITEM };
@@
-1745,7
+1741,6
@@
int f_name_cmp(struct file_struct *f1, struct file_struct *f2)
return dif;
}
return dif;
}
-
/* Return a copy of the full filename of a flist entry, using the indicated
* buffer. No size-checking is done because we checked the size when creating
* the file_struct entry.
/* Return a copy of the full filename of a flist entry, using the indicated
* buffer. No size-checking is done because we checked the size when creating
* the file_struct entry.
@@
-1765,7
+1760,6
@@
char *f_name_to(struct file_struct *f, char *fbuf)
return fbuf;
}
return fbuf;
}
-
/* Like f_name_to(), but we rotate through 5 static buffers of our own. */
char *f_name(struct file_struct *f)
{
/* Like f_name_to(), but we rotate through 5 static buffers of our own. */
char *f_name(struct file_struct *f)
{
@@
-1777,7
+1771,6
@@
char *f_name(struct file_struct *f)
return f_name_to(f, names[n]);
}
return f_name_to(f, names[n]);
}
-
/* Do a non-recursive scan of the named directory, possibly ignoring all
* exclude rules except for the daemon's. If "dlen" is >=0, it is the length
* of the dirname string, and also indicates that "dirname" is a MAXPATHLEN
/* Do a non-recursive scan of the named directory, possibly ignoring all
* exclude rules except for the daemon's. If "dlen" is >=0, it is the length
* of the dirname string, and also indicates that "dirname" is a MAXPATHLEN