MCPcopy Index your code
hub / github.com/git/git / finalize_object_file_flags

Function finalize_object_file_flags

object-file.c:408–472  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

406}
407
408int finalize_object_file_flags(struct repository *repo,
409 const char *tmpfile, const char *filename,
410 enum finalize_object_file_flags flags)
411{
412 unsigned retries = 0;
413 int ret;
414
415retry:
416 ret = 0;
417
418 if (object_creation_mode == OBJECT_CREATION_USES_RENAMES)
419 goto try_rename;
420 else if (link(tmpfile, filename))
421 ret = errno;
422 else
423 unlink_or_warn(tmpfile);
424
425 /*
426 * Coda hack - coda doesn't like cross-directory links,
427 * so we fall back to a rename, which will mean that it
428 * won't be able to check collisions, but that's not a
429 * big deal.
430 *
431 * The same holds for FAT formatted media.
432 *
433 * When this succeeds, we just return. We have nothing
434 * left to unlink.
435 */
436 if (ret && ret != EEXIST) {
437 struct stat st;
438
439 try_rename:
440 if (!stat(filename, &st))
441 ret = EEXIST;
442 else if (!rename(tmpfile, filename))
443 goto out;
444 else
445 ret = errno;
446 }
447 if (ret) {
448 if (ret != EEXIST) {
449 int saved_errno = errno;
450 unlink_or_warn(tmpfile);
451 errno = saved_errno;
452 return error_errno(_("unable to write file %s"), filename);
453 }
454 if (!(flags & FOF_SKIP_COLLISION_CHECK)) {
455 ret = check_collision(tmpfile, filename);
456 if (ret == CHECK_COLLISION_DEST_VANISHED) {
457 if (retries++ > 5)
458 return error(_("unable to write repeatedly vanishing file %s"),
459 filename);
460 goto retry;
461 }
462 else if (ret)
463 return -1;
464 }
465 unlink_or_warn(tmpfile);

Callers 3

finalize_object_fileFunction · 0.70
write_loose_objectFunction · 0.70

Calls 7

linkFunction · 0.85
unlink_or_warnFunction · 0.85
error_errnoFunction · 0.85
check_collisionFunction · 0.85
errorFunction · 0.85
adjust_shared_permFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected