Only called if FLAG_HLINKED is set and FLAG_HLINK_FIRST is not. Returns: * 0 = process the file, 1 = skip the file, -1 = error occurred. */
| 284 | /* Only called if FLAG_HLINKED is set and FLAG_HLINK_FIRST is not. Returns: |
| 285 | * 0 = process the file, 1 = skip the file, -1 = error occurred. */ |
| 286 | int hard_link_check(struct file_struct *file, int ndx, char *fname, |
| 287 | int statret, stat_x *sxp, int itemizing, |
| 288 | enum logcode code) |
| 289 | { |
| 290 | STRUCT_STAT prev_st; |
| 291 | char namebuf[MAXPATHLEN], altbuf[MAXPATHLEN]; |
| 292 | char *realname, *prev_name; |
| 293 | struct file_list *flist; |
| 294 | int gnum = inc_recurse ? F_HL_GNUM(file) : -1; |
| 295 | int prev_ndx; |
| 296 | |
| 297 | prev_name = realname = check_prior(file, gnum, &prev_ndx, &flist); |
| 298 | |
| 299 | if (!prev_name) { |
| 300 | struct file_struct *prev_file; |
| 301 | |
| 302 | if (!flist) { |
| 303 | /* The previous file was skipped, so this one is |
| 304 | * treated as if it were the first in its group. */ |
| 305 | if (DEBUG_GTE(HLINK, 2)) { |
| 306 | rprintf(FINFO, "hlink for %d (%s,%d): virtual first\n", |
| 307 | ndx, f_name(file, NULL), gnum); |
| 308 | } |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | prev_file = flist->files[prev_ndx - flist->ndx_start]; |
| 313 | |
| 314 | /* Is the previous link not complete yet? */ |
| 315 | if (!(prev_file->flags & FLAG_HLINK_DONE)) { |
| 316 | /* Is the previous link being transferred? */ |
| 317 | if (prev_file->flags & FLAG_FILE_SENT) { |
| 318 | /* Add ourselves to the list of files that will |
| 319 | * be updated when the transfer completes, and |
| 320 | * mark ourself as waiting for the transfer. */ |
| 321 | F_HL_PREV(file) = F_HL_PREV(prev_file); |
| 322 | F_HL_PREV(prev_file) = ndx; |
| 323 | file->flags |= FLAG_FILE_SENT; |
| 324 | cur_flist->in_progress++; |
| 325 | if (DEBUG_GTE(HLINK, 2)) { |
| 326 | rprintf(FINFO, "hlink for %d (%s,%d): waiting for %d\n", |
| 327 | ndx, f_name(file, NULL), gnum, F_HL_PREV(file)); |
| 328 | } |
| 329 | return 1; |
| 330 | } |
| 331 | if (DEBUG_GTE(HLINK, 2)) { |
| 332 | rprintf(FINFO, "hlink for %d (%s,%d): looking for a leader\n", |
| 333 | ndx, f_name(file, NULL), gnum); |
| 334 | } |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | /* There is a finished file to link with! */ |
| 339 | if (!(prev_file->flags & FLAG_HLINK_FIRST)) { |
| 340 | /* The previous previous is FIRST when prev is not. */ |
| 341 | prev_name = realname = check_prior(prev_file, gnum, &prev_ndx, &flist); |
| 342 | /* Update our previous pointer to point to the FIRST. */ |
| 343 | F_HL_PREV(file) = prev_ndx; |
no test coverage detected