Create a file_struct for a named file by reading its stat() information * and performing extensive checks against global options. * * Returns a pointer to the new file struct, or NULL if there was an error * or this file should be excluded. * * Note: Any error (here or in send_file_name) that results in the omission of * an existent source file from the file list should set * "io_error |=
| 1256 | * "io_error |= IOERR_GENERAL" to avoid deletion of the file from the |
| 1257 | * destination if --delete is on. */ |
| 1258 | struct file_struct *make_file(const char *fname, struct file_list *flist, |
| 1259 | STRUCT_STAT *stp, int flags, int filter_level) |
| 1260 | { |
| 1261 | static char *lastdir; |
| 1262 | static int lastdir_len = -1; |
| 1263 | struct file_struct *file; |
| 1264 | char thisname[MAXPATHLEN]; |
| 1265 | char linkname[MAXPATHLEN]; |
| 1266 | int alloc_len, basename_len, linkname_len; |
| 1267 | int extra_len = file_extra_cnt * EXTRA_LEN; |
| 1268 | const char *basename; |
| 1269 | alloc_pool_t *pool; |
| 1270 | STRUCT_STAT st = {0}; |
| 1271 | char *bp; |
| 1272 | |
| 1273 | if (strlcpy(thisname, fname, sizeof thisname) >= sizeof thisname) { |
| 1274 | io_error |= IOERR_GENERAL; |
| 1275 | rprintf(FERROR_XFER, "skipping overly long name: %s\n", fname); |
| 1276 | return NULL; |
| 1277 | } |
| 1278 | clean_fname(thisname, 0); |
| 1279 | if (sanitize_paths) |
| 1280 | sanitize_path(thisname, thisname, "", 0, SP_DEFAULT); |
| 1281 | |
| 1282 | if (stp && (S_ISDIR(stp->st_mode) || IS_MISSING_FILE(*stp))) { |
| 1283 | /* This is needed to handle a "symlink/." with a --relative |
| 1284 | * dir, or a request to delete a specific file. */ |
| 1285 | st = *stp; |
| 1286 | *linkname = '\0'; /* make IBM code checker happy */ |
| 1287 | } else if (readlink_stat(thisname, &st, linkname) != 0) { |
| 1288 | int save_errno = errno; |
| 1289 | /* See if file is excluded before reporting an error. */ |
| 1290 | if (filter_level != NO_FILTERS |
| 1291 | && (is_excluded(thisname, 0, filter_level) |
| 1292 | || is_excluded(thisname, 1, filter_level))) { |
| 1293 | if (ignore_perishable && save_errno != ENOENT) |
| 1294 | non_perishable_cnt++; |
| 1295 | return NULL; |
| 1296 | } |
| 1297 | if (save_errno == ENOENT) { |
| 1298 | #ifdef SUPPORT_LINKS |
| 1299 | /* When our options tell us to follow a symlink that |
| 1300 | * points nowhere, tell the user about the symlink |
| 1301 | * instead of giving a "vanished" message. We only |
| 1302 | * dereference a symlink if one of the --copy*links |
| 1303 | * options was specified, so there's no need for the |
| 1304 | * extra lstat() if one of these options isn't on. */ |
| 1305 | if ((copy_links || copy_unsafe_links || copy_dirlinks) |
| 1306 | && x_lstat(thisname, &st, NULL) == 0 |
| 1307 | && S_ISLNK(st.st_mode)) { |
| 1308 | io_error |= IOERR_GENERAL; |
| 1309 | rprintf(FERROR_XFER, "symlink has no referent: %s\n", |
| 1310 | full_fname(thisname)); |
| 1311 | } else |
| 1312 | #endif |
| 1313 | { |
| 1314 | enum logcode c = am_daemon && protocol_version < 28 |
| 1315 | ? FERROR : FWARNING; |
no test coverage detected