Go to the source code of this file.
Functions | |
void | clean_flist (struct file_list *flist, int strip_root) |
int | show_filelist_p (void) |
void | start_filelist_progress (char *kind) |
void | emit_filelist_progress (const struct file_list *flist) |
void | maybe_emit_filelist_progress (const struct file_list *flist) |
void | finish_filelist_progress (const struct file_list *flist) |
void | show_flist_stats (void) |
string_area * | string_area_new (int size) |
void | string_area_free (struct string_area *a) |
char * | string_area_malloc (struct string_area **ap, int size) |
char * | string_area_strdup (struct string_area **ap, const char *src) |
void | list_file_entry (struct file_struct *f) |
int | readlink_stat (const char *path, STRUCT_STAT *buffer, char *linkbuf) |
Stat either a symlink or its referent, depending on the settings of copy_links, copy_unsafe_links, etc. More... | |
int | link_stat (const char *path, STRUCT_STAT *buffer) |
int | check_exclude_file (int f, char *fname, STRUCT_STAT *st) |
void | set_filesystem (char *fname) |
int | to_wire_mode (mode_t mode) |
mode_t | from_wire_mode (int mode) |
void | send_directory (int f, struct file_list *flist, char *dir) |
void | flist_expand (struct file_list *flist) |
Make sure flist is big enough to hold at least flist->count entries. More... | |
void | send_file_entry (struct file_struct *file, int f, unsigned base_flags) |
void | receive_file_entry (struct file_struct **fptr, unsigned flags, int f) |
int | skip_filesystem (char *fname, STRUCT_STAT *st) |
file_struct * | make_file (int f, char *fname, struct string_area **ap, int noexcludes) |
Create a file_struct for a named file by reading its stat() information and performing extensive checks against global options. More... | |
void | send_file_name (int f, struct file_list *flist, char *fname, int recursive, unsigned base_flags) |
file_list * | send_file_list (int f, int argc, char *argv[]) |
I think f==-1 means that the list should just be built in memory and not transmitted. More... | |
file_list * | recv_file_list (int f) |
int | file_compare (struct file_struct **f1, struct file_struct **f2) |
int | flist_find (struct file_list *flist, struct file_struct *f) |
void | free_file (struct file_struct *file) |
file_list * | flist_new () |
void | flist_free (struct file_list *flist) |
char * | f_name (struct file_struct *f) |
Variables | |
stats | stats |
int | verbose |
int | do_progress |
int | am_server |
int | always_checksum |
int | cvs_exclude |
int | recurse |
int | one_file_system |
int | make_backups |
int | preserve_links |
int | preserve_hard_links |
int | preserve_perms |
int | preserve_devices |
int | preserve_uid |
int | preserve_gid |
int | preserve_times |
int | relative_paths |
int | copy_links |
int | copy_unsafe_links |
int | remote_version |
int | io_error |
int | sanitize_paths |
int | read_batch |
int | write_batch |
char | topsrcname [MAXPATHLEN] |
exclude_struct ** | local_exclude_list |
file_struct | null_file |
dev_t | filesystem_dev |
char * | flist_dir |
Definition in file flist.c.
|
Definition at line 1245 of file flist.c. References am_server, file_struct::basename, file_list::count, file_struct::dirname, f_name(), file_compare(), file_list::files, FINFO, free_file(), file_struct::length, memmove(), file_struct::mode, rprintf(), file_list::string_area, and verbose. Referenced by recv_file_list(), and send_file_list().
01246 { 01247 int i; 01248 01249 if (!flist || flist->count == 0) 01250 return; 01251 01252 qsort(flist->files, flist->count, 01253 sizeof(flist->files[0]), (int (*)()) file_compare); 01254 01255 for (i = 1; i < flist->count; i++) { 01256 if (flist->files[i]->basename && 01257 flist->files[i - 1]->basename && 01258 strcmp(f_name(flist->files[i]), 01259 f_name(flist->files[i - 1])) == 0) { 01260 if (verbose > 1 && !am_server) 01261 rprintf(FINFO, 01262 "removing duplicate name %s from file list %d\n", 01263 f_name(flist->files[i - 1]), 01264 i - 1); 01265 /* it's not great that the flist knows the semantics of the 01266 * file memory usage, but i'd rather not add a flag byte 01267 * to that struct. XXX can i use a bit in the flags field? */ 01268 if (flist->string_area) 01269 flist->files[i][0] = null_file; 01270 else 01271 free_file(flist->files[i]); 01272 } 01273 } 01274 01275 /* FIXME: There is a bug here when filenames are repeated more 01276 * than once, because we don't handle freed files when doing 01277 * the comparison. */ 01278 01279 if (strip_root) { 01280 /* we need to strip off the root directory in the case 01281 of relative paths, but this must be done _after_ 01282 the sorting phase */ 01283 for (i = 0; i < flist->count; i++) { 01284 if (flist->files[i]->dirname && 01285 flist->files[i]->dirname[0] == '/') { 01286 memmove(&flist->files[i]->dirname[0], 01287 &flist->files[i]->dirname[1], 01288 strlen(flist->files[i]->dirname)); 01289 } 01290 01291 if (flist->files[i]->dirname && 01292 !flist->files[i]->dirname[0]) { 01293 flist->files[i]->dirname = NULL; 01294 } 01295 } 01296 } 01297 01298 01299 if (verbose <= 3) 01300 return; 01301 01302 for (i = 0; i < flist->count; i++) { 01303 rprintf(FINFO, "[%d] i=%d %s %s mode=0%o len=%.0f\n", 01304 (int) getpid(), i, 01305 NS(flist->files[i]->dirname), 01306 NS(flist->files[i]->basename), 01307 (int) flist->files[i]->mode, 01308 (double) flist->files[i]->length); 01309 } 01310 } |
|
Definition at line 73 of file flist.c. References am_server, recurse, and verbose. Referenced by maybe_emit_filelist_progress(), recv_file_list(), and send_file_list().
|
|
Definition at line 78 of file flist.c. References do_progress, FINFO, rflush(), rprintf(), and verbose. Referenced by recv_file_list(), and send_file_list().
|
|
Definition at line 87 of file flist.c. References file_list::count, FINFO, and rprintf(). Referenced by maybe_emit_filelist_progress().
|
|
Definition at line 93 of file flist.c. References file_list::count, do_progress, emit_filelist_progress(), and show_filelist_p(). Referenced by recv_file_list(), and send_file_name().
00094 { 00095 if (do_progress && show_filelist_p() && ((flist->count % 100) == 0)) 00096 emit_filelist_progress(flist); 00097 } |
|
Definition at line 100 of file flist.c. References file_list::count, FINFO, and rprintf(). Referenced by recv_file_list(), and send_file_list().
|
|
Definition at line 111 of file flist.c. Referenced by report().
00112 { 00113 /* Nothing yet */ 00114 } |
|
Definition at line 117 of file flist.c. References string_area::base, string_area::current, string_area::end, string_area::next, and out_of_memory(). Referenced by flist_new(), and string_area_malloc().
00118 { 00119 struct string_area *a; 00120 00121 if (size <= 0) 00122 size = ARENA_SIZE; 00123 a = malloc(sizeof(*a)); 00124 if (!a) 00125 out_of_memory("string_area_new"); 00126 a->current = a->base = malloc(size); 00127 if (!a->current) 00128 out_of_memory("string_area_new buffer"); 00129 a->end = a->base + size; 00130 a->next = NULL; 00131 00132 return a; 00133 } |
|
Definition at line 135 of file flist.c. References string_area::base, and string_area::next. Referenced by flist_free().
00136 { 00137 struct string_area *next; 00138 00139 for (; a; a = next) { 00140 next = a->next; 00141 free(a->base); 00142 } 00143 } |
|
Definition at line 145 of file flist.c. References string_area::current, string_area::end, string_area::next, and string_area_new(). Referenced by string_area_strdup().
00146 { 00147 char *p; 00148 struct string_area *a; 00149 00150 /* does the request fit into the current space? */ 00151 a = *ap; 00152 if (a->current + size >= a->end) { 00153 /* no; get space, move new string_area to front of the list */ 00154 a = string_area_new(size > ARENA_SIZE ? size : ARENA_SIZE); 00155 a->next = *ap; 00156 *ap = a; 00157 } 00158 00159 /* have space; do the "allocation." */ 00160 p = a->current; 00161 a->current += size; 00162 return p; 00163 } |
|
Definition at line 165 of file flist.c. References string_area_malloc().
00166 { 00167 char *dest = string_area_malloc(ap, strlen(src) + 1); 00168 return strcpy(dest, src); 00169 } |
|
Definition at line 171 of file flist.c. References file_struct::basename, f_name(), FINFO, file_struct::length, file_struct::link, file_struct::mode, file_struct::modtime, permstring(), preserve_links, rprintf(), and timestring(). Referenced by recv_file_list().
00172 { 00173 char perms[11]; 00174 00175 if (!f->basename) 00176 /* this can happen if duplicate names were removed */ 00177 return; 00178 00179 permstring(perms, f->mode); 00180 00181 if (preserve_links && S_ISLNK(f->mode)) { 00182 rprintf(FINFO, "%s %11.0f %s %s -> %s\n", 00183 perms, 00184 (double) f->length, timestring(f->modtime), 00185 f_name(f), f->link); 00186 } else { 00187 rprintf(FINFO, "%s %11.0f %s %s\n", 00188 perms, 00189 (double) f->length, timestring(f->modtime), 00190 f_name(f)); 00191 } 00192 } |
|
Stat either a symlink or its referent, depending on the settings of copy_links, copy_unsafe_links, etc.
Definition at line 209 of file flist.c. References copy_unsafe_links, do_lstat(), do_stat(), topsrcname, and unsafe_symlink(). Referenced by make_file().
00210 { 00211 #if SUPPORT_LINKS 00212 if (copy_links) { 00213 return do_stat(path, buffer); 00214 } 00215 if (do_lstat(path, buffer) == -1) { 00216 return -1; 00217 } 00218 if (S_ISLNK(buffer->st_mode)) { 00219 int l; 00220 l = readlink((char *) path, linkbuf, MAXPATHLEN - 1); 00221 if (l == -1) 00222 return -1; 00223 linkbuf[l] = 0; 00224 if (copy_unsafe_links && (topsrcname[0] != '\0') && 00225 unsafe_symlink(linkbuf, topsrcname)) { 00226 return do_stat(path, buffer); 00227 } 00228 } 00229 return 0; 00230 #else 00231 return do_stat(path, buffer); 00232 #endif 00233 } |
|
Definition at line 235 of file flist.c. References do_lstat(), and do_stat(). Referenced by delete_already_done(), hard_link_one(), recv_generator(), send_file_list(), set_filesystem(), set_perms(), and skip_filesystem().
|
|
Definition at line 252 of file flist.c. References check_exclude(), and delete_excluded. Referenced by make_file().
00253 { 00254 extern int delete_excluded; 00255 00256 /* f is set to -1 when calculating deletion file list */ 00257 if ((f == -1) && delete_excluded) { 00258 return 0; 00259 } 00260 if (check_exclude(fname, local_exclude_list, st)) { 00261 return 1; 00262 } 00263 return 0; 00264 } |
|
Definition at line 269 of file flist.c. References filesystem_dev, and link_stat(). Referenced by send_file_list().
00270 { 00271 STRUCT_STAT st; 00272 if (link_stat(fname, &st) != 0) 00273 return; 00274 filesystem_dev = st.st_dev; 00275 } |
|
Definition at line 278 of file flist.c. Referenced by send_file_entry().
00279 { 00280 if (S_ISLNK(mode) && (_S_IFLNK != 0120000)) { 00281 return (mode & ~(_S_IFMT)) | 0120000; 00282 } 00283 return (int) mode; 00284 } |
|
Definition at line 286 of file flist.c. Referenced by receive_file_entry().
00287 { 00288 if ((mode & (_S_IFMT)) == 0120000 && (_S_IFLNK != 0120000)) { 00289 return (mode & ~(_S_IFMT)) | _S_IFLNK; 00290 } 00291 return (mode_t) mode; 00292 } |
|
Definition at line 808 of file flist.c. References add_exclude_list(), d_name(), FERROR, FINFO, io_error, make_exclude_list(), recurse, rprintf(), send_file_name(), strlcat(), and strlcpy(). Referenced by send_file_name().
00809 { 00810 DIR *d; 00811 struct dirent *di; 00812 char fname[MAXPATHLEN]; 00813 int l; 00814 char *p; 00815 00816 d = opendir(dir); 00817 if (!d) { 00818 io_error = 1; 00819 rprintf(FERROR, "opendir(%s): %s\n", dir, strerror(errno)); 00820 return; 00821 } 00822 00823 strlcpy(fname, dir, MAXPATHLEN); 00824 l = strlen(fname); 00825 if (fname[l - 1] != '/') { 00826 if (l == MAXPATHLEN - 1) { 00827 io_error = 1; 00828 rprintf(FERROR, 00829 "skipping long-named directory %s\n", 00830 fname); 00831 closedir(d); 00832 return; 00833 } 00834 strlcat(fname, "/", MAXPATHLEN); 00835 l++; 00836 } 00837 p = fname + strlen(fname); 00838 00839 local_exclude_list = NULL; 00840 00841 if (cvs_exclude) { 00842 if (strlen(fname) + strlen(".cvsignore") <= MAXPATHLEN - 1) { 00843 strcpy(p, ".cvsignore"); 00844 local_exclude_list = 00845 make_exclude_list(fname, NULL, 0, 0); 00846 } else { 00847 io_error = 1; 00848 rprintf(FINFO, 00849 "cannot cvs-exclude in long-named directory %s\n", 00850 fname); 00851 } 00852 } 00853 00854 for (di = readdir(d); di; di = readdir(d)) { 00855 char *dname = d_name(di); 00856 if (strcmp(dname, ".") == 0 || strcmp(dname, "..") == 0) 00857 continue; 00858 strlcpy(p, dname, MAXPATHLEN - l); 00859 send_file_name(f, flist, fname, recurse, 0); 00860 } 00861 00862 if (local_exclude_list) { 00863 add_exclude_list("!", &local_exclude_list, 0); 00864 } 00865 00866 closedir(d); 00867 } |
|
Make sure
Definition at line 304 of file flist.c. References file_list::count, file_list::files, FINFO, file_list::malloced, out_of_memory(), rprintf(), and verbose. Referenced by recv_file_list(), and send_file_name().
00305 { 00306 if (flist->count >= flist->malloced) { 00307 size_t new_bytes; 00308 void *new_ptr; 00309 00310 if (flist->malloced < 1000) 00311 flist->malloced += 1000; 00312 else 00313 flist->malloced *= 2; 00314 00315 new_bytes = sizeof(flist->files[0]) * flist->malloced; 00316 00317 if (flist->files) 00318 new_ptr = realloc(flist->files, new_bytes); 00319 else 00320 new_ptr = malloc(new_bytes); 00321 00322 if (verbose >= 2) { 00323 rprintf(FINFO, "expand file_list to %.0f bytes, did%s move\n", 00324 (double) new_bytes, 00325 (new_ptr == flist->files) ? " not" : ""); 00326 } 00327 00328 flist->files = (struct file_struct **) new_ptr; 00329 00330 if (!flist->files) 00331 out_of_memory("flist_expand"); 00332 } 00333 } |
|
Definition at line 336 of file flist.c. References add_gid(), add_uid(), file_struct::dev, f_name(), file_struct::gid, file_struct::inode, file_struct::length, file_struct::link, file_struct::mode, file_struct::modtime, preserve_devices, preserve_gid, preserve_hard_links, preserve_links, preserve_uid, file_struct::rdev, remote_version, strlcpy(), file_struct::sum, to_wire_mode(), file_struct::uid, write_buf(), write_byte(), write_int(), and write_longint(). Referenced by send_file_list(), and send_file_name().
00338 { 00339 unsigned char flags; 00340 static time_t last_time; 00341 static mode_t last_mode; 00342 static DEV64_T last_rdev; 00343 static uid_t last_uid; 00344 static gid_t last_gid; 00345 static char lastname[MAXPATHLEN]; 00346 char *fname; 00347 int l1, l2; 00348 00349 if (f == -1) 00350 return; 00351 00352 if (!file) { 00353 write_byte(f, 0); 00354 return; 00355 } 00356 00357 io_write_phase = "send_file_entry"; 00358 00359 fname = f_name(file); 00360 00361 flags = base_flags; 00362 00363 if (file->mode == last_mode) 00364 flags |= SAME_MODE; 00365 if (file->rdev == last_rdev) 00366 flags |= SAME_RDEV; 00367 if (file->uid == last_uid) 00368 flags |= SAME_UID; 00369 if (file->gid == last_gid) 00370 flags |= SAME_GID; 00371 if (file->modtime == last_time) 00372 flags |= SAME_TIME; 00373 00374 for (l1 = 0; 00375 lastname[l1] && (fname[l1] == lastname[l1]) && (l1 < 255); 00376 l1++); 00377 l2 = strlen(fname) - l1; 00378 00379 if (l1 > 0) 00380 flags |= SAME_NAME; 00381 if (l2 > 255) 00382 flags |= LONG_NAME; 00383 00384 /* we must make sure we don't send a zero flags byte or the other 00385 end will terminate the flist transfer */ 00386 if (flags == 0 && !S_ISDIR(file->mode)) 00387 flags |= FLAG_DELETE; 00388 if (flags == 0) 00389 flags |= LONG_NAME; 00390 00391 write_byte(f, flags); 00392 if (flags & SAME_NAME) 00393 write_byte(f, l1); 00394 if (flags & LONG_NAME) 00395 write_int(f, l2); 00396 else 00397 write_byte(f, l2); 00398 write_buf(f, fname + l1, l2); 00399 00400 write_longint(f, file->length); 00401 if (!(flags & SAME_TIME)) 00402 write_int(f, (int) file->modtime); 00403 if (!(flags & SAME_MODE)) 00404 write_int(f, to_wire_mode(file->mode)); 00405 if (preserve_uid && !(flags & SAME_UID)) { 00406 add_uid(file->uid); 00407 write_int(f, (int) file->uid); 00408 } 00409 if (preserve_gid && !(flags & SAME_GID)) { 00410 add_gid(file->gid); 00411 write_int(f, (int) file->gid); 00412 } 00413 if (preserve_devices && IS_DEVICE(file->mode) 00414 && !(flags & SAME_RDEV)) 00415 write_int(f, (int) file->rdev); 00416 00417 #if SUPPORT_LINKS 00418 if (preserve_links && S_ISLNK(file->mode)) { 00419 write_int(f, strlen(file->link)); 00420 write_buf(f, file->link, strlen(file->link)); 00421 } 00422 #endif 00423 00424 #if SUPPORT_HARD_LINKS 00425 if (preserve_hard_links && S_ISREG(file->mode)) { 00426 if (remote_version < 26) { 00427 /* 32-bit dev_t and ino_t */ 00428 write_int(f, (int) file->dev); 00429 write_int(f, (int) file->inode); 00430 } else { 00431 /* 64-bit dev_t and ino_t */ 00432 write_longint(f, file->dev); 00433 write_longint(f, file->inode); 00434 } 00435 } 00436 #endif 00437 00438 if (always_checksum) { 00439 if (remote_version < 21) { 00440 write_buf(f, file->sum, 2); 00441 } else { 00442 write_buf(f, file->sum, MD4_SUM_LENGTH); 00443 } 00444 } 00445 00446 last_mode = file->mode; 00447 last_rdev = file->rdev; 00448 last_uid = file->uid; 00449 last_gid = file->gid; 00450 last_time = file->modtime; 00451 00452 strlcpy(lastname, fname, MAXPATHLEN); 00453 lastname[MAXPATHLEN - 1] = 0; 00454 00455 io_write_phase = "unknown"; 00456 } |
|
Definition at line 460 of file flist.c. References file_struct::basename, clean_fname(), file_struct::dev, file_struct::dirname, FERROR, file_struct::flags, from_wire_mode(), file_struct::gid, file_struct::inode, file_struct::length, file_struct::link, file_struct::mode, file_struct::modtime, orig_umask, out_of_memory(), overflow(), preserve_devices, preserve_hard_links, preserve_links, preserve_perms, file_struct::rdev, read_buf(), read_byte(), read_int(), read_longint(), read_sbuf(), remote_version, rprintf(), sanitize_path(), strdup(), strlcpy(), file_struct::sum, and file_struct::uid. Referenced by recv_file_list().
00462 { 00463 static time_t last_time; 00464 static mode_t last_mode; 00465 static DEV64_T last_rdev; 00466 static uid_t last_uid; 00467 static gid_t last_gid; 00468 static char lastname[MAXPATHLEN]; 00469 char thisname[MAXPATHLEN]; 00470 unsigned int l1 = 0, l2 = 0; 00471 char *p; 00472 struct file_struct *file; 00473 00474 if (flags & SAME_NAME) 00475 l1 = read_byte(f); 00476 00477 if (flags & LONG_NAME) 00478 l2 = read_int(f); 00479 else 00480 l2 = read_byte(f); 00481 00482 file = (struct file_struct *) malloc(sizeof(*file)); 00483 if (!file) 00484 out_of_memory("receive_file_entry"); 00485 memset((char *) file, 0, sizeof(*file)); 00486 (*fptr) = file; 00487 00488 if (l2 >= MAXPATHLEN - l1) { 00489 rprintf(FERROR, 00490 "overflow: flags=0x%x l1=%d l2=%d lastname=%s\n", 00491 flags, l1, l2, lastname); 00492 overflow("receive_file_entry"); 00493 } 00494 00495 strlcpy(thisname, lastname, l1 + 1); 00496 read_sbuf(f, &thisname[l1], l2); 00497 thisname[l1 + l2] = 0; 00498 00499 strlcpy(lastname, thisname, MAXPATHLEN); 00500 lastname[MAXPATHLEN - 1] = 0; 00501 00502 clean_fname(thisname); 00503 00504 if (sanitize_paths) { 00505 sanitize_path(thisname, NULL); 00506 } 00507 00508 if ((p = strrchr(thisname, '/'))) { 00509 static char *lastdir; 00510 *p = 0; 00511 if (lastdir && strcmp(thisname, lastdir) == 0) { 00512 file->dirname = lastdir; 00513 } else { 00514 file->dirname = strdup(thisname); 00515 lastdir = file->dirname; 00516 } 00517 file->basename = strdup(p + 1); 00518 } else { 00519 file->dirname = NULL; 00520 file->basename = strdup(thisname); 00521 } 00522 00523 if (!file->basename) 00524 out_of_memory("receive_file_entry 1"); 00525 00526 00527 file->flags = flags; 00528 file->length = read_longint(f); 00529 file->modtime = 00530 (flags & SAME_TIME) ? last_time : (time_t) read_int(f); 00531 file->mode = 00532 (flags & SAME_MODE) ? last_mode : from_wire_mode(read_int(f)); 00533 if (preserve_uid) 00534 file->uid = 00535 (flags & SAME_UID) ? last_uid : (uid_t) read_int(f); 00536 if (preserve_gid) 00537 file->gid = 00538 (flags & SAME_GID) ? last_gid : (gid_t) read_int(f); 00539 if (preserve_devices && IS_DEVICE(file->mode)) 00540 file->rdev = 00541 (flags & SAME_RDEV) ? last_rdev : (dev_t) read_int(f); 00542 00543 if (preserve_links && S_ISLNK(file->mode)) { 00544 int l = read_int(f); 00545 if (l < 0) { 00546 rprintf(FERROR, "overflow: l=%d\n", l); 00547 overflow("receive_file_entry"); 00548 } 00549 file->link = (char *) malloc(l + 1); 00550 if (!file->link) 00551 out_of_memory("receive_file_entry 2"); 00552 read_sbuf(f, file->link, l); 00553 if (sanitize_paths) { 00554 sanitize_path(file->link, file->dirname); 00555 } 00556 } 00557 #if SUPPORT_HARD_LINKS 00558 if (preserve_hard_links && S_ISREG(file->mode)) { 00559 if (remote_version < 26) { 00560 file->dev = read_int(f); 00561 file->inode = read_int(f); 00562 } else { 00563 file->dev = read_longint(f); 00564 file->inode = read_longint(f); 00565 } 00566 } 00567 #endif 00568 00569 if (always_checksum) { 00570 file->sum = (char *) malloc(MD4_SUM_LENGTH); 00571 if (!file->sum) 00572 out_of_memory("md4 sum"); 00573 if (remote_version < 21) { 00574 read_buf(f, file->sum, 2); 00575 } else { 00576 read_buf(f, file->sum, MD4_SUM_LENGTH); 00577 } 00578 } 00579 00580 last_mode = file->mode; 00581 last_rdev = file->rdev; 00582 last_uid = file->uid; 00583 last_gid = file->gid; 00584 last_time = file->modtime; 00585 00586 if (!preserve_perms) { 00587 extern int orig_umask; 00588 /* set an appropriate set of permissions based on original 00589 permissions and umask. This emulates what GNU cp does */ 00590 file->mode &= ~orig_umask; 00591 } 00592 } |
|
Definition at line 598 of file flist.c. References filesystem_dev, and link_stat(). Referenced by make_file().
00599 { 00600 STRUCT_STAT st2; 00601 char *p = strrchr(fname, '/'); 00602 00603 /* skip all but directories */ 00604 if (!S_ISDIR(st->st_mode)) 00605 return 1; 00606 00607 /* if its not a subdirectory then allow */ 00608 if (!p) 00609 return 0; 00610 00611 *p = 0; 00612 if (link_stat(fname, &st2)) { 00613 *p = '/'; 00614 return 0; 00615 } 00616 *p = '/'; 00617 00618 return (st2.st_dev != filesystem_dev); 00619 } |
|
Create a file_struct for a named file by reading its stat() information and performing extensive checks against global options.
Definition at line 640 of file flist.c. References file_struct::basedir, file_struct::basename, check_exclude_file(), clean_fname(), copy_links, file_struct::dev, file_struct::dirname, FERROR, file_checksum(), filesystem_dev, FINFO, flist_dir, file_struct::gid, file_struct::inode, io_error, file_struct::length, file_struct::link, file_struct::mode, file_struct::modtime, one_file_system, out_of_memory(), file_struct::rdev, readlink_stat(), recurse, rprintf(), sanitize_path(), skip_filesystem(), strdup(), strlcpy(), file_struct::sum, stats::total_size, file_struct::uid, and verbose. Referenced by keep_backup(), and send_file_name().
00642 { 00643 struct file_struct *file; 00644 STRUCT_STAT st; 00645 char sum[SUM_LENGTH]; 00646 char *p; 00647 char cleaned_name[MAXPATHLEN]; 00648 char linkbuf[MAXPATHLEN]; 00649 extern int module_id; 00650 00651 strlcpy(cleaned_name, fname, MAXPATHLEN); 00652 cleaned_name[MAXPATHLEN - 1] = 0; 00653 clean_fname(cleaned_name); 00654 if (sanitize_paths) { 00655 sanitize_path(cleaned_name, NULL); 00656 } 00657 fname = cleaned_name; 00658 00659 memset(sum, 0, SUM_LENGTH); 00660 00661 if (readlink_stat(fname, &st, linkbuf) != 0) { 00662 int save_errno = errno; 00663 if ((errno == ENOENT) && copy_links && !noexcludes) { 00664 /* symlink pointing nowhere, see if excluded */ 00665 memset((char *) &st, 0, sizeof(st)); 00666 if (check_exclude_file(f, fname, &st)) { 00667 /* file is excluded anyway, ignore silently */ 00668 return NULL; 00669 } 00670 } 00671 io_error = 1; 00672 rprintf(FERROR, "readlink %s: %s\n", 00673 fname, strerror(save_errno)); 00674 return NULL; 00675 } 00676 00677 /* we use noexcludes from backup.c */ 00678 if (noexcludes) 00679 goto skip_excludes; 00680 00681 if (S_ISDIR(st.st_mode) && !recurse) { 00682 rprintf(FINFO, "skipping directory %s\n", fname); 00683 return NULL; 00684 } 00685 00686 if (one_file_system && st.st_dev != filesystem_dev) { 00687 if (skip_filesystem(fname, &st)) 00688 return NULL; 00689 } 00690 00691 if (check_exclude_file(f, fname, &st)) 00692 return NULL; 00693 00694 00695 if (lp_ignore_nonreadable(module_id) && access(fname, R_OK) != 0) 00696 return NULL; 00697 00698 skip_excludes: 00699 00700 if (verbose > 2) 00701 rprintf(FINFO, "make_file(%d,%s)\n", f, fname); 00702 00703 file = (struct file_struct *) malloc(sizeof(*file)); 00704 if (!file) 00705 out_of_memory("make_file"); 00706 memset((char *) file, 0, sizeof(*file)); 00707 00708 if ((p = strrchr(fname, '/'))) { 00709 static char *lastdir; 00710 *p = 0; 00711 if (lastdir && strcmp(fname, lastdir) == 0) { 00712 file->dirname = lastdir; 00713 } else { 00714 file->dirname = strdup(fname); 00715 lastdir = file->dirname; 00716 } 00717 file->basename = STRDUP(ap, p + 1); 00718 *p = '/'; 00719 } else { 00720 file->dirname = NULL; 00721 file->basename = STRDUP(ap, fname); 00722 } 00723 00724 file->modtime = st.st_mtime; 00725 file->length = st.st_size; 00726 file->mode = st.st_mode; 00727 file->uid = st.st_uid; 00728 file->gid = st.st_gid; 00729 file->dev = st.st_dev; 00730 file->inode = st.st_ino; 00731 #ifdef HAVE_STRUCT_STAT_ST_RDEV 00732 file->rdev = st.st_rdev; 00733 #endif 00734 00735 #if SUPPORT_LINKS 00736 if (S_ISLNK(st.st_mode)) { 00737 file->link = STRDUP(ap, linkbuf); 00738 } 00739 #endif 00740 00741 if (always_checksum) { 00742 file->sum = (char *) MALLOC(ap, MD4_SUM_LENGTH); 00743 if (!file->sum) 00744 out_of_memory("md4 sum"); 00745 /* drat. we have to provide a null checksum for non-regular 00746 files in order to be compatible with earlier versions 00747 of rsync */ 00748 if (S_ISREG(st.st_mode)) { 00749 file_checksum(fname, file->sum, st.st_size); 00750 } else { 00751 memset(file->sum, 0, MD4_SUM_LENGTH); 00752 } 00753 } 00754 00755 if (flist_dir) { 00756 static char *lastdir; 00757 if (lastdir && strcmp(lastdir, flist_dir) == 0) { 00758 file->basedir = lastdir; 00759 } else { 00760 file->basedir = strdup(flist_dir); 00761 lastdir = file->basedir; 00762 } 00763 } else { 00764 file->basedir = NULL; 00765 } 00766 00767 if (!S_ISDIR(st.st_mode)) 00768 stats.total_size += st.st_size; 00769 00770 return file; 00771 } |
|
Definition at line 775 of file flist.c. References file_struct::basename, file_list::count, f_name(), file_list::files, file_struct::flags, flist_expand(), make_file(), maybe_emit_filelist_progress(), file_struct::mode, send_directory(), send_file_entry(), and file_list::string_area. Referenced by send_directory(), and send_file_list().
00777 { 00778 struct file_struct *file; 00779 00780 file = make_file(f, fname, &flist->string_area, 0); 00781 00782 if (!file) 00783 return; 00784 00785 maybe_emit_filelist_progress(flist); 00786 00787 flist_expand(flist); 00788 00789 if (write_batch) /* dw */ 00790 file->flags = FLAG_DELETE; 00791 00792 if (strcmp(file->basename, "")) { 00793 flist->files[flist->count++] = file; 00794 send_file_entry(file, f, base_flags); 00795 } 00796 00797 if (S_ISDIR(file->mode) && recursive) { 00798 struct exclude_struct **last_exclude_list = 00799 local_exclude_list; 00800 send_directory(f, flist, f_name(file)); 00801 local_exclude_list = last_exclude_list; 00802 return; 00803 } 00804 } |
|
I think f==-1 means that the list should just be built in memory and not transmitted. But who can tell? -- mbp Definition at line 875 of file flist.c. References clean_flist(), copy_links, copy_unsafe_links, file_list::count, FERROR, file_list::files, FINFO, finish_filelist_progress(), flist_dir, flist_new(), stats::flist_size, io_end_buffering(), io_error, io_start_buffering(), link_stat(), stats::num_files, pop_dir(), push_dir(), recurse, relative_paths, remote_version, rprintf(), send_file_entry(), send_file_name(), send_uid_list(), set_filesystem(), show_filelist_p(), start_filelist_progress(), strlcat(), strlcpy(), topsrcname, stats::total_written, verbose, write_batch_flist_info(), and write_int(). Referenced by client_run(), delete_files(), and do_server_sender().
00876 { 00877 int i, l; 00878 STRUCT_STAT st; 00879 char *p, *dir, *olddir; 00880 char lastpath[MAXPATHLEN] = ""; 00881 struct file_list *flist; 00882 int64 start_write; 00883 00884 if (show_filelist_p() && f != -1) 00885 start_filelist_progress("building file list"); 00886 00887 start_write = stats.total_written; 00888 00889 flist = flist_new(); 00890 00891 if (f != -1) { 00892 io_start_buffering(f); 00893 } 00894 00895 for (i = 0; i < argc; i++) { 00896 char *fname = topsrcname; 00897 00898 strlcpy(fname, argv[i], MAXPATHLEN); 00899 00900 l = strlen(fname); 00901 if (l != 1 && fname[l - 1] == '/') { 00902 if ((l == 2) && (fname[0] == '.')) { 00903 /* Turn ./ into just . rather than ./. 00904 This was put in to avoid a problem with 00905 rsync -aR --delete from ./ 00906 The send_file_name() below of ./ was 00907 mysteriously preventing deletes */ 00908 fname[1] = 0; 00909 } else { 00910 strlcat(fname, ".", MAXPATHLEN); 00911 } 00912 } 00913 00914 if (link_stat(fname, &st) != 0) { 00915 if (f != -1) { 00916 io_error = 1; 00917 rprintf(FERROR, "link_stat %s : %s\n", 00918 fname, strerror(errno)); 00919 } 00920 continue; 00921 } 00922 00923 if (S_ISDIR(st.st_mode) && !recurse) { 00924 rprintf(FINFO, "skipping directory %s\n", fname); 00925 continue; 00926 } 00927 00928 dir = NULL; 00929 olddir = NULL; 00930 00931 if (!relative_paths) { 00932 p = strrchr(fname, '/'); 00933 if (p) { 00934 *p = 0; 00935 if (p == fname) 00936 dir = "/"; 00937 else 00938 dir = fname; 00939 fname = p + 1; 00940 } 00941 } else if (f != -1 && (p = strrchr(fname, '/'))) { 00942 /* this ensures we send the intermediate directories, 00943 thus getting their permissions right */ 00944 *p = 0; 00945 if (strcmp(lastpath, fname)) { 00946 strlcpy(lastpath, fname, sizeof(lastpath)); 00947 *p = '/'; 00948 for (p = fname + 1; (p = strchr(p, '/')); 00949 p++) { 00950 int copy_links_saved = copy_links; 00951 int recurse_saved = recurse; 00952 *p = 0; 00953 copy_links = copy_unsafe_links; 00954 /* set recurse to 1 to prevent make_file 00955 from ignoring directory, but still 00956 turn off the recursive parameter to 00957 send_file_name */ 00958 recurse = 1; 00959 send_file_name(f, flist, fname, 0, 00960 0); 00961 copy_links = copy_links_saved; 00962 recurse = recurse_saved; 00963 *p = '/'; 00964 } 00965 } else { 00966 *p = '/'; 00967 } 00968 } 00969 00970 if (!*fname) 00971 fname = "."; 00972 00973 if (dir && *dir) { 00974 olddir = push_dir(dir, 1); 00975 00976 if (!olddir) { 00977 io_error = 1; 00978 rprintf(FERROR, "push_dir %s : %s\n", 00979 dir, strerror(errno)); 00980 continue; 00981 } 00982 00983 flist_dir = dir; 00984 } 00985 00986 if (one_file_system) 00987 set_filesystem(fname); 00988 00989 send_file_name(f, flist, fname, recurse, FLAG_DELETE); 00990 00991 if (olddir != NULL) { 00992 flist_dir = NULL; 00993 if (pop_dir(olddir) != 0) { 00994 rprintf(FERROR, "pop_dir %s : %s\n", 00995 dir, strerror(errno)); 00996 exit_cleanup(RERR_FILESELECT); 00997 } 00998 } 00999 } 01000 01001 topsrcname[0] = '\0'; 01002 01003 if (f != -1) { 01004 send_file_entry(NULL, f, 0); 01005 } 01006 01007 if (show_filelist_p() && f != -1) { 01008 finish_filelist_progress(flist); 01009 } 01010 01011 clean_flist(flist, 0); 01012 01013 /* now send the uid/gid list. This was introduced in protocol 01014 version 15 */ 01015 if (f != -1 && remote_version >= 15) { 01016 send_uid_list(f); 01017 } 01018 01019 /* if protocol version is >= 17 then send the io_error flag */ 01020 if (f != -1 && remote_version >= 17) { 01021 extern int module_id; 01022 write_int(f, lp_ignore_errors(module_id) ? 0 : io_error); 01023 } 01024 01025 if (f != -1) { 01026 io_end_buffering(); 01027 stats.flist_size = stats.total_written - start_write; 01028 stats.num_files = flist->count; 01029 if (write_batch) /* dw */ 01030 write_batch_flist_info(flist->count, flist->files); 01031 } 01032 01033 if (verbose > 2) 01034 rprintf(FINFO, "send_file_list done\n"); 01035 01036 return flist; 01037 } |
|
Definition at line 1040 of file flist.c. References clean_flist(), file_list::count, f_name(), file_list::files, FINFO, finish_filelist_progress(), flist_expand(), stats::flist_size, ignore_errors, io_error, file_struct::length, list_file_entry(), file_list::malloced, maybe_emit_filelist_progress(), file_struct::mode, stats::num_files, out_of_memory(), read_batch, read_byte(), read_int(), receive_file_entry(), recv_uid_list(), relative_paths, remote_version, rprintf(), show_filelist_p(), start_filelist_progress(), stats::total_read, stats::total_size, and verbose. Referenced by client_run(), and do_server_recv().
01041 { 01042 struct file_list *flist; 01043 unsigned char flags; 01044 int64 start_read; 01045 extern int list_only; 01046 01047 if (show_filelist_p()) 01048 start_filelist_progress("receiving file list"); 01049 01050 start_read = stats.total_read; 01051 01052 flist = (struct file_list *) malloc(sizeof(flist[0])); 01053 if (!flist) 01054 goto oom; 01055 01056 flist->count = 0; 01057 flist->malloced = 1000; 01058 flist->files = 01059 (struct file_struct **) malloc(sizeof(flist->files[0]) * 01060 flist->malloced); 01061 if (!flist->files) 01062 goto oom; 01063 01064 01065 for (flags = read_byte(f); flags; flags = read_byte(f)) { 01066 int i = flist->count; 01067 01068 flist_expand(flist); 01069 01070 receive_file_entry(&flist->files[i], flags, f); 01071 01072 if (S_ISREG(flist->files[i]->mode)) 01073 stats.total_size += flist->files[i]->length; 01074 01075 flist->count++; 01076 01077 maybe_emit_filelist_progress(flist); 01078 01079 if (verbose > 2) 01080 rprintf(FINFO, "recv_file_name(%s)\n", 01081 f_name(flist->files[i])); 01082 } 01083 01084 01085 if (verbose > 2) 01086 rprintf(FINFO, "received %d names\n", flist->count); 01087 01088 clean_flist(flist, relative_paths); 01089 01090 if (show_filelist_p()) { 01091 finish_filelist_progress(flist); 01092 } 01093 01094 /* now recv the uid/gid list. This was introduced in protocol version 15 */ 01095 if (f != -1 && remote_version >= 15) { 01096 recv_uid_list(f, flist); 01097 } 01098 01099 /* if protocol version is >= 17 then recv the io_error flag */ 01100 if (f != -1 && remote_version >= 17 && !read_batch) { /* dw-added readbatch */ 01101 extern int module_id; 01102 extern int ignore_errors; 01103 if (lp_ignore_errors(module_id) || ignore_errors) { 01104 read_int(f); 01105 } else { 01106 io_error |= read_int(f); 01107 } 01108 } 01109 01110 if (list_only) { 01111 int i; 01112 for (i = 0; i < flist->count; i++) { 01113 list_file_entry(flist->files[i]); 01114 } 01115 } 01116 01117 01118 if (verbose > 2) 01119 rprintf(FINFO, "recv_file_list done\n"); 01120 01121 stats.flist_size = stats.total_read - start_read; 01122 stats.num_files = flist->count; 01123 01124 return flist; 01125 01126 oom: 01127 out_of_memory("recv_file_list"); 01128 return NULL; /* not reached */ 01129 } |
|
Definition at line 1136 of file flist.c. References f_name(), and u_strcmp(). Referenced by clean_flist(), flist_find(), and hlink_compare().
01137 { 01138 if (!(*f1)->basename && !(*f2)->basename) 01139 return 0; 01140 if (!(*f1)->basename) 01141 return -1; 01142 if (!(*f2)->basename) 01143 return 1; 01144 if ((*f1)->dirname == (*f2)->dirname) 01145 return u_strcmp((*f1)->basename, (*f2)->basename); 01146 return u_strcmp(f_name(*f1), f_name(*f2)); 01147 } |
|
Definition at line 1150 of file flist.c. References file_list::count, file_compare(), file_list::files, and flist_up(). Referenced by delete_files().
01151 { 01152 int low = 0, high = flist->count - 1; 01153 01154 if (flist->count <= 0) 01155 return -1; 01156 01157 while (low != high) { 01158 int mid = (low + high) / 2; 01159 int ret = 01160 file_compare(&flist->files[flist_up(flist, mid)], &f); 01161 if (ret == 0) 01162 return flist_up(flist, mid); 01163 if (ret > 0) { 01164 high = mid; 01165 } else { 01166 low = mid + 1; 01167 } 01168 } 01169 01170 if (file_compare(&flist->files[flist_up(flist, low)], &f) == 0) 01171 return flist_up(flist, low); 01172 return -1; 01173 } |
|
Definition at line 1179 of file flist.c. References file_struct::basename, file_struct::link, and file_struct::sum. Referenced by clean_flist(), flist_free(), and keep_backup().
|
|
Definition at line 1196 of file flist.c. References file_list::count, file_list::files, file_list::malloced, out_of_memory(), file_list::string_area, and string_area_new(). Referenced by send_file_list().
01197 { 01198 struct file_list *flist; 01199 01200 flist = (struct file_list *) malloc(sizeof(flist[0])); 01201 if (!flist) 01202 out_of_memory("send_file_list"); 01203 01204 flist->count = 0; 01205 flist->malloced = 0; 01206 flist->files = NULL; 01207 01208 #if ARENA_SIZE > 0 01209 flist->string_area = string_area_new(0); 01210 #else 01211 flist->string_area = NULL; 01212 #endif 01213 return flist; 01214 } |
|
Definition at line 1219 of file flist.c. References file_list::count, file_list::files, free_file(), file_list::string_area, and string_area_free(). Referenced by delete_files().
01220 { 01221 int i; 01222 for (i = 1; i < flist->count; i++) { 01223 if (!flist->string_area) 01224 free_file(flist->files[i]); 01225 free(flist->files[i]); 01226 } 01227 /* FIXME: I don't think we generally need to blank the flist 01228 * since it's about to be freed. This will just cause more 01229 * memory traffic. If you want a freed-memory debugger, you 01230 * know where to get it. */ 01231 memset((char *) flist->files, 0, 01232 sizeof(flist->files[0]) * flist->count); 01233 free(flist->files); 01234 if (flist->string_area) 01235 string_area_free(flist->string_area); 01236 memset((char *) flist, 0, sizeof(*flist)); 01237 free(flist); 01238 } |
|
Definition at line 1320 of file flist.c. References file_struct::basename, file_struct::dirname, and strlcpy(). Referenced by add_delete_entry(), check_hard_link(), clean_flist(), delete_already_done(), delete_files(), delete_one(), file_compare(), hard_link_one(), keep_backup(), list_file_entry(), log_formatted(), recv_file_list(), recv_files(), recv_generator(), send_file_entry(), send_file_name(), and send_files().
01321 { 01322 static char names[10][MAXPATHLEN]; 01323 static int n; 01324 char *p = names[n]; 01325 01326 if (!f || !f->basename) 01327 return NULL; 01328 01329 n = (n + 1) % 10; 01330 01331 if (f->dirname) { 01332 int off; 01333 01334 off = strlcpy(p, f->dirname, MAXPATHLEN); 01335 off += strlcpy(p + off, "/", MAXPATHLEN - off); 01336 off += strlcpy(p + off, f->basename, MAXPATHLEN - off); 01337 } else { 01338 strlcpy(p, f->basename, MAXPATHLEN); 01339 } 01340 01341 return p; 01342 } |
|
|
|
Definition at line 36 of file flist.c. Referenced by clean_flist(), flist_expand(), make_file(), recv_file_list(), send_file_list(), show_filelist_p(), and start_filelist_progress(). |
|
Definition at line 37 of file flist.c. Referenced by maybe_emit_filelist_progress(), parse_arguments(), and start_filelist_progress(). |
|
Definition at line 38 of file flist.c. Referenced by clean_flist(), and show_filelist_p(). |
|
|
|
|
|
Definition at line 43 of file flist.c. Referenced by make_file(), send_directory(), send_file_list(), and show_filelist_p(). |
|
Definition at line 45 of file flist.c. Referenced by make_file(). |
|
|
|
Definition at line 47 of file flist.c. Referenced by list_file_entry(), receive_file_entry(), and send_file_entry(). |
|
Definition at line 48 of file flist.c. Referenced by receive_file_entry(), and send_file_entry(). |
|
Definition at line 49 of file flist.c. Referenced by receive_file_entry(). |
|
Definition at line 50 of file flist.c. Referenced by receive_file_entry(), and send_file_entry(). |
|
Definition at line 51 of file flist.c. Referenced by send_file_entry(). |
|
Definition at line 52 of file flist.c. Referenced by send_file_entry(). |
|
|
|
Definition at line 54 of file flist.c. Referenced by recv_file_list(), and send_file_list(). |
|
Definition at line 55 of file flist.c. Referenced by make_file(), and send_file_list(). |
|
Definition at line 56 of file flist.c. Referenced by readlink_stat(), and send_file_list(). |
|
Definition at line 57 of file flist.c. Referenced by receive_file_entry(), recv_file_list(), send_file_entry(), and send_file_list(). |
|
Definition at line 58 of file flist.c. Referenced by make_file(), recv_file_list(), send_directory(), and send_file_list(). |
|
Definition at line 59 of file flist.c. Referenced by glob_expand_one(). |
|
Definition at line 61 of file flist.c. Referenced by parse_arguments(), and recv_file_list(). |
|
Definition at line 62 of file flist.c. Referenced by parse_arguments(). |
|
Definition at line 64 of file flist.c. Referenced by readlink_stat(), and send_file_list(). |
|
|
|
|
|
Definition at line 267 of file flist.c. Referenced by make_file(), set_filesystem(), and skip_filesystem(). |
|
Definition at line 297 of file flist.c. Referenced by make_file(), and send_file_list(). |