* 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). */
| 611 | * can have problems on various filesystems (FAT, NFS, Coda). |
| 612 | */ |
| 613 | static 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 |
no test coverage detected