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>
Nguyễn Thái Ngọc Duy committed
Jun 13, 2014 at 19:19 UTC
a0a967568e8de5306d1889583c4dad0ff937f5ef
1 file changed
+10
-3
read-cache.c
+10
-3
@@ -2030,14 +2030,21 @@ static void remove_temporary_sharedindex_on_signal(int signo)
2030
raise(signo);
2031
}
2032
2033
-static int write_shared_index(struct index_state *istate)
2033
+static int write_shared_index(struct index_state *istate,
2034
+ struct lock_file *lock, unsigned flags)
2035
{
2036
struct split_index *si = istate->split_index;
2037
static int installed_handler;
2038
int fd, ret;
2039
2040
temporary_sharedindex = git_pathdup("sharedindex_XXXXXX");
2040
- fd = xmkstemp(temporary_sharedindex);
2041
+ fd = mkstemp(temporary_sharedindex);
2042
+ if (fd < 0) {
2043
+ free(temporary_sharedindex);
2044
+ temporary_sharedindex = NULL;
2045
+ hashclr(si->base_sha1);
2046
+ return do_write_locked_index(istate, lock, flags);
2047
+ }
2048
if (!installed_handler) {
2049
atexit(remove_temporary_sharedindex);
2050
sigchain_push_common(remove_temporary_sharedindex_on_signal);
@@ -2070,7 +2077,7 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
2077
}
2078
2079
if (istate->cache_changed & SPLIT_INDEX_ORDERED) {
2073
- int ret = write_shared_index(istate);
2080
+ int ret = write_shared_index(istate, lock, flags);
2081
if (ret)
2082
return ret;
2083
}