summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2014-06-13 19:19:45 +0700
committerJunio C Hamano <gitster@pobox.com>2014-06-13 11:49:41 -0700
commita0a967568e8de5306d1889583c4dad0ff937f5ef (patch)
tree789ce1f9f54734f0d0d50ad534c38a1b67bccefe /read-cache.c
parentc18b80a0e86c4529146e3947454159627f1419a7 (diff)
downloadgit-a0a967568e8de5306d1889583c4dad0ff937f5ef.tar.gz
update-index --split-index: do not split if $GIT_DIR is read only
If $GIT_DIR is read only, we can't write $GIT_DIR/sharedindex. This could happen when $GIT_INDEX_FILE is set to somehwere outside $GIT_DIR. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/read-cache.c b/read-cache.c
index 8ecb9599e5..aa848e170f 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2030,14 +2030,21 @@ static void remove_temporary_sharedindex_on_signal(int signo)
raise(signo);
}
-static int write_shared_index(struct index_state *istate)
+static int write_shared_index(struct index_state *istate,
+ struct lock_file *lock, unsigned flags)
{
struct split_index *si = istate->split_index;
static int installed_handler;
int fd, ret;
temporary_sharedindex = git_pathdup("sharedindex_XXXXXX");
- fd = xmkstemp(temporary_sharedindex);
+ fd = mkstemp(temporary_sharedindex);
+ if (fd < 0) {
+ free(temporary_sharedindex);
+ temporary_sharedindex = NULL;
+ hashclr(si->base_sha1);
+ return do_write_locked_index(istate, lock, flags);
+ }
if (!installed_handler) {
atexit(remove_temporary_sharedindex);
sigchain_push_common(remove_temporary_sharedindex_on_signal);
@@ -2070,7 +2077,7 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
}
if (istate->cache_changed & SPLIT_INDEX_ORDERED) {
- int ret = write_shared_index(istate);
+ int ret = write_shared_index(istate, lock, flags);
if (ret)
return ret;
}