diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2018-01-14 17:18:19 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-01-16 13:12:07 -0800 |
commit | 59f9d2dd60f97c55c92c3273903f64048a27e513 (patch) | |
tree | 091d123595e4d233083f892ab5c20f85c2705cbb | |
parent | 7db2d08cdccc39ea3d9a1da2da30e54f92b8fd12 (diff) | |
download | git-59f9d2dd60f97c55c92c3273903f64048a27e513.tar.gz |
read-cache.c: move tempfile creation/cleanup out of write_shared_index
For one thing, we have more consistent cleanup procedure now and always
keep errno intact.
The real purpose is the ability to break out of write_locked_index()
early when mks_tempfile() fails in the next patch. It's more awkward to
do it if this mks_tempfile() is still inside write_shared_index().
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | read-cache.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/read-cache.c b/read-cache.c index 536086e1fe..c568643f55 100644 --- a/read-cache.c +++ b/read-cache.c @@ -2472,31 +2472,18 @@ static int clean_shared_index_files(const char *current_hex) } static int write_shared_index(struct index_state *istate, - struct lock_file *lock, unsigned flags) + struct tempfile **temp) { - struct tempfile *real_temp; - struct tempfile **temp = &real_temp; struct split_index *si = istate->split_index; int ret; - real_temp = mks_tempfile(git_path("sharedindex_XXXXXX")); - if (!real_temp) { - hashclr(si->base_sha1); - return do_write_locked_index(istate, lock, flags); - } - temp = &real_temp; move_cache_to_base_index(istate); ret = do_write_index(si->base, *temp, 1); - if (ret) { - delete_tempfile(temp); + if (ret) return ret; - } ret = adjust_shared_perm(get_tempfile_path(*temp)); if (ret) { - int save_errno = errno; error("cannot fix permission bits on %s", get_tempfile_path(*temp)); - delete_tempfile(temp); - errno = save_errno; return ret; } ret = rename_tempfile(temp, @@ -2567,7 +2554,21 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock, new_shared_index = istate->cache_changed & SPLIT_INDEX_ORDERED; if (new_shared_index) { - ret = write_shared_index(istate, lock, flags); + struct tempfile *temp; + int saved_errno; + + temp = mks_tempfile(git_path("sharedindex_XXXXXX")); + if (!temp) { + hashclr(si->base_sha1); + ret = do_write_locked_index(istate, lock, flags); + } else + ret = write_shared_index(istate, &temp); + + saved_errno = errno; + if (is_tempfile_active(temp)) + delete_tempfile(&temp); + errno = saved_errno; + if (ret) goto out; } |