Thread (67 messages) 67 messages, 7 authors, 2016-06-15
STALE3633d

[PATCH 26/32] update-index --split-index: do not split if $GIT_DIR is read only

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 23:00:52
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
 read-cache.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index a6c9407..f9fc3a5 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;
 	}
-- 
1.9.1.346.ga2b5940
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help