#include "rsync.h"
+extern struct stats stats;
+
extern int csum_length;
extern int verbose;
extern int am_server;
extern int always_checksum;
-extern int64 total_size;
extern int cvs_exclude;
extern int remote_version;
extern int io_error;
-static char **local_exclude_list;
+static struct exclude_struct **local_exclude_list;
int link_stat(const char *Path, STRUCT_STAT *Buffer)
{
*/
static int match_file_name(char *fname,STRUCT_STAT *st)
{
- if (check_exclude(fname,local_exclude_list)) {
+ if (check_exclude(fname,local_exclude_list,st)) {
if (verbose > 2)
rprintf(FINFO,"excluding file %s\n",fname);
return 0;
static char *flist_dir;
-static void clean_fname(char *name)
-{
- char *p;
- int l;
- int modified = 1;
-
- if (!name) return;
-
- while (modified) {
- modified = 0;
-
- if ((p=strstr(name,"/./"))) {
- modified = 1;
- while (*p) {
- p[0] = p[2];
- p++;
- }
- }
-
- if ((p=strstr(name,"//"))) {
- modified = 1;
- while (*p) {
- p[0] = p[1];
- p++;
- }
- }
-
- if (strncmp(p=name,"./",2) == 0) {
- modified = 1;
- do {
- p[0] = p[2];
- } while (*p++);
- }
-
- l = strlen(p=name);
- if (l > 1 && p[l-1] == '/') {
- modified = 1;
- p[l-1] = 0;
- }
- }
-}
-
-
void send_file_entry(struct file_struct *file,int f,unsigned base_flags)
{
if (file->gid == last_gid) flags |= SAME_GID;
if (file->modtime == last_time) flags |= SAME_TIME;
- for (l1=0;lastname[l1] && fname[l1] == lastname[l1];l1++) ;
+ for (l1=0;lastname[l1] && (fname[l1] == lastname[l1]) && (l1 < 255);l1++) ;
l2 = strlen(fname) - l1;
if (l1 > 0) flags |= SAME_NAME;
if (l2 > 255) flags |= LONG_NAME;
+ /* we must make sure we don't send a zero flags byte or the other
+ end will terminate the flist transfer */
+ if (flags == 0 && !S_ISDIR(file->mode)) flags |= FLAG_DELETE;
+ if (flags == 0) flags |= LONG_NAME;
+
write_byte(f,flags);
if (flags & SAME_NAME)
write_byte(f,l1);
last_gid = file->gid;
last_time = file->modtime;
- strncpy(lastname,fname,MAXPATHLEN-1);
+ strlcpy(lastname,fname,MAXPATHLEN-1);
lastname[MAXPATHLEN-1] = 0;
}
if (l2 >= MAXPATHLEN-l1) overflow("receive_file_entry");
- strncpy(thisname,lastname,l1);
+ strlcpy(thisname,lastname,l1);
read_sbuf(f,&thisname[l1],l2);
thisname[l1+l2] = 0;
- strncpy(lastname,thisname,MAXPATHLEN-1);
+ strlcpy(lastname,thisname,MAXPATHLEN-1);
lastname[MAXPATHLEN-1] = 0;
clean_fname(thisname);
+ if (relative_paths && thisname[0] == '/') {
+ /* strip / off absolute paths in destination */
+ memmove(thisname, thisname+1, strlen(thisname));
+ if (!thisname[0]) strcpy(thisname,".");
+ }
+
if ((p = strrchr(thisname,'/'))) {
static char *lastdir;
*p = 0;
char *p;
char cleaned_name[MAXPATHLEN];
- strncpy(cleaned_name, fname, MAXPATHLEN-1);
+ strlcpy(cleaned_name, fname, MAXPATHLEN-1);
cleaned_name[MAXPATHLEN-1] = 0;
clean_fname(cleaned_name);
fname = cleaned_name;
}
if (!S_ISDIR(st.st_mode))
- total_size += st.st_size;
+ stats.total_size += st.st_size;
return file;
}
}
if (S_ISDIR(file->mode) && recursive) {
- char **last_exclude_list = local_exclude_list;
- send_directory(f,flist,f_name(file));
- local_exclude_list = last_exclude_list;
- return;
+ struct exclude_struct **last_exclude_list = local_exclude_list;
+ send_directory(f,flist,f_name(file));
+ local_exclude_list = last_exclude_list;
+ return;
}
}
d = opendir(dir);
if (!d) {
io_error = 1;
- rprintf(FERROR,"%s: %s\n",
+ rprintf(FERROR,"opendir(%s): %s\n",
dir,strerror(errno));
return;
}
- strncpy(fname,dir,MAXPATHLEN-1);
- fname[MAXPATHLEN-1]=0;
+ strlcpy(fname,dir,MAXPATHLEN-1);
l = strlen(fname);
if (fname[l-1] != '/') {
if (l == MAXPATHLEN-1) {
closedir(d);
return;
}
- strcat(fname,"/");
+ strlcat(fname,"/", MAXPATHLEN-1);
l++;
}
p = fname + strlen(fname);
if (cvs_exclude) {
if (strlen(fname) + strlen(".cvsignore") <= MAXPATHLEN-1) {
strcpy(p,".cvsignore");
- local_exclude_list = make_exclude_list(fname,NULL,0);
+ local_exclude_list = make_exclude_list(fname,NULL,0,0);
} else {
io_error = 1;
rprintf(FINFO,"cannot cvs-exclude in long-named directory %s\n",fname);
if (strcmp(dname,".")==0 ||
strcmp(dname,"..")==0)
continue;
- strncpy(p,dname,MAXPATHLEN-(l+1));
- send_file_name(f,flist,fname,recurse,FLAG_DELETE);
+ strlcpy(p,dname,MAXPATHLEN-(l+1));
+ send_file_name(f,flist,fname,recurse,0);
}
closedir(d);
int i,l;
STRUCT_STAT st;
char *p,*dir;
- char dbuf[MAXPATHLEN];
char lastpath[MAXPATHLEN]="";
struct file_list *flist;
+ int64 start_write;
if (verbose && recurse && !am_server && f != -1) {
rprintf(FINFO,"building file list ... ");
rflush(FINFO);
}
+ start_write = stats.total_written;
+
flist = (struct file_list *)malloc(sizeof(flist[0]));
if (!flist) out_of_memory("send_file_list");
flist->malloced);
if (!flist->files) out_of_memory("send_file_list");
+ if (f != -1) {
+ io_start_buffering(f);
+ }
+
for (i=0;i<argc;i++) {
char fname2[MAXPATHLEN];
char *fname = fname2;
- strncpy(fname,argv[i],MAXPATHLEN-1);
- fname[MAXPATHLEN-1] = 0;
+ strlcpy(fname,argv[i],MAXPATHLEN-1);
l = strlen(fname);
if (l != 1 && fname[l-1] == '/') {
- strcat(fname,".");
+ strlcat(fname,".",MAXPATHLEN-1);
}
if (link_stat(fname,&st) != 0) {
thus getting their permissions right */
*p = 0;
if (strcmp(lastpath,fname)) {
- strcpy(lastpath, fname);
+ strlcpy(lastpath, fname, sizeof(lastpath)-1);
*p = '/';
for (p=fname+1; (p=strchr(p,'/')); p++) {
+ int copy_links_saved = copy_links;
*p = 0;
+ copy_links = 0;
send_file_name(f, flist, fname, 0, 0);
+ copy_links = copy_links_saved;
*p = '/';
}
} else {
fname = ".";
if (dir && *dir) {
- if (getcwd(dbuf,MAXPATHLEN-1) == NULL) {
- rprintf(FERROR,"getwd : %s\n",strerror(errno));
- exit_cleanup(1);
- }
- if (chdir(dir) != 0) {
+ char *olddir = push_dir(dir, 1);
+
+ if (!olddir) {
io_error=1;
- rprintf(FERROR,"chdir %s : %s\n",
+ rprintf(FERROR,"push_dir %s : %s\n",
dir,strerror(errno));
continue;
}
+
flist_dir = dir;
if (one_file_system)
set_filesystem(fname);
send_file_name(f,flist,fname,recurse,FLAG_DELETE);
flist_dir = NULL;
- if (chdir(dbuf) != 0) {
- rprintf(FERROR,"chdir %s : %s\n",
- dbuf,strerror(errno));
+ if (pop_dir(olddir) != 0) {
+ rprintf(FERROR,"pop_dir %s : %s\n",
+ dir,strerror(errno));
exit_cleanup(1);
}
continue;
if (f != -1) {
send_file_entry(NULL,f,0);
- write_flush(f);
}
if (verbose && recurse && !am_server && f != -1)
write_int(f, io_error);
}
+ if (f != -1) {
+ io_end_buffering(f);
+ stats.flist_size = stats.total_written - start_write;
+ stats.num_files = flist->count;
+ }
+
if (verbose > 2)
rprintf(FINFO,"send_file_list done\n");
{
struct file_list *flist;
unsigned char flags;
+ int64 start_read;
if (verbose && recurse && !am_server) {
rprintf(FINFO,"receiving file list ... ");
rflush(FINFO);
}
+ start_read = stats.total_read;
+
flist = (struct file_list *)malloc(sizeof(flist[0]));
if (!flist)
goto oom;
receive_file_entry(&flist->files[i],flags,f);
if (S_ISREG(flist->files[i]->mode))
- total_size += flist->files[i]->length;
+ stats.total_size += flist->files[i]->length;
flist->count++;
if (verbose > 2)
rprintf(FINFO,"recv_file_list done\n");
+ stats.flist_size = stats.total_read - start_read;
+ stats.num_files = flist->count;
+
return flist;
oom:
n = (n+1)%10;
if (f->dirname) {
- sprintf(p, "%s/%s", f->dirname, f->basename);
+ slprintf(p, MAXPATHLEN-1, "%s/%s", f->dirname, f->basename);
} else {
- strcpy(p, f->basename);
+ strlcpy(p, f->basename, MAXPATHLEN-1);
}
return p;