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

Function create_tmpfile

object-file.c:613–641  ·  view source on GitHub ↗

* This creates a temporary file in the same directory as the final * 'filename' * * We want to avoid cross-directory filename renames, because those * can have problems on various filesystems (FAT, NFS, Coda). */

Source from the content-addressed store, hash-verified

611 * can have problems on various filesystems (FAT, NFS, Coda).
612 */
613static int create_tmpfile(struct repository *repo,
614 struct strbuf *tmp, const char *filename)
615{
616 int fd, dirlen = directory_size(filename);
617
618 strbuf_reset(tmp);
619 strbuf_add(tmp, filename, dirlen);
620 strbuf_addstr(tmp, "tmp_obj_XXXXXX");
621 fd = git_mkstemp_mode(tmp->buf, 0444);
622 if (fd < 0 && dirlen && errno == ENOENT) {
623 /*
624 * Make sure the directory exists; note that the contents
625 * of the buffer are undefined after mkstemp returns an
626 * error, so we have to rewrite the whole buffer from
627 * scratch.
628 */
629 strbuf_reset(tmp);
630 strbuf_add(tmp, filename, dirlen - 1);
631 if (mkdir(tmp->buf, 0777) && errno != EEXIST)
632 return -1;
633 if (adjust_shared_perm(repo, tmp->buf))
634 return -1;
635
636 /* Try again */
637 strbuf_addstr(tmp, "/tmp_obj_XXXXXX");
638 fd = git_mkstemp_mode(tmp->buf, 0444);
639 }
640 return fd;
641}
642
643/**
644 * Common steps for loose object writers to start writing loose

Callers 1

Calls 5

directory_sizeFunction · 0.85
strbuf_addFunction · 0.85
strbuf_addstrFunction · 0.85
git_mkstemp_modeFunction · 0.85
adjust_shared_permFunction · 0.85

Tested by

no test coverage detected