Call this with EITHER (1) "file, NULL, 0" to chdir() to the file's * F_PATHNAME(), or (2) "NULL, dir, dirlen" to chdir() to the supplied dir, * with dir == NULL taken to be the starting directory, and dirlen < 0 * indicating that strdup(dir) should be called and then the -dirlen length * value checked to ensure that it is not daemon-excluded. */
| 347 | * indicating that strdup(dir) should be called and then the -dirlen length |
| 348 | * value checked to ensure that it is not daemon-excluded. */ |
| 349 | int change_pathname(struct file_struct *file, const char *dir, int dirlen) |
| 350 | { |
| 351 | if (dirlen < 0) { |
| 352 | char *cpy = strdup(dir); |
| 353 | if (*cpy != '/') |
| 354 | change_dir(orig_dir, CD_SKIP_CHDIR); |
| 355 | if (path_is_daemon_excluded(cpy, 0)) |
| 356 | goto chdir_error; |
| 357 | dir = cpy; |
| 358 | dirlen = -dirlen; |
| 359 | } else { |
| 360 | if (file) { |
| 361 | if (pathname == F_PATHNAME(file)) |
| 362 | return 1; |
| 363 | dir = F_PATHNAME(file); |
| 364 | if (dir) |
| 365 | dirlen = strlen(dir); |
| 366 | } else if (pathname == dir) |
| 367 | return 1; |
| 368 | if (dir && *dir != '/') |
| 369 | change_dir(orig_dir, CD_SKIP_CHDIR); |
| 370 | } |
| 371 | |
| 372 | pathname = dir; |
| 373 | pathname_len = dirlen; |
| 374 | |
| 375 | if (!dir) |
| 376 | dir = orig_dir; |
| 377 | |
| 378 | if (!change_dir(dir, CD_NORMAL)) { |
| 379 | chdir_error: |
| 380 | io_error |= IOERR_GENERAL; |
| 381 | rsyserr(FERROR_XFER, errno, "change_dir %s failed", full_fname(dir)); |
| 382 | if (dir != orig_dir) |
| 383 | change_dir(orig_dir, CD_NORMAL); |
| 384 | pathname = NULL; |
| 385 | pathname_len = 0; |
| 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | return 1; |
| 390 | } |
| 391 | |
| 392 | static void send_file_entry(int f, const char *fname, struct file_struct *file, |
| 393 | #ifdef SUPPORT_LINKS |
no test coverage detected