Code

Close the index file between writing and committing
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>
Sat, 8 Jul 2006 08:56:28 +0000 (10:56 +0200)
committerJunio C Hamano <junkio@cox.net>
Sat, 8 Jul 2006 10:28:19 +0000 (03:28 -0700)
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
builtin-add.c
builtin-apply.c
builtin-read-tree.c
builtin-rm.c
builtin-update-index.c
builtin-write-tree.c
checkout-index.c

index bfbbb1bf52e10667f94dd574ab32fe070c98c4cb..2d256981733345f4a430e11812b6851f0351aabd 100644 (file)
@@ -181,7 +181,7 @@ int cmd_add(int argc, const char **argv, char **envp)
 
        if (active_cache_changed) {
                if (write_cache(newfd, active_cache, active_nr) ||
-                   commit_lock_file(&lock_file))
+                   close(newfd) || commit_lock_file(&lock_file))
                        die("Unable to write new index file");
        }
 
index e9ead002d38368f6de6ba75f25542fe61258cfb9..c3af48917c9a96ce86442bea737f4a81c7e0fb55 100644 (file)
@@ -2323,7 +2323,7 @@ int cmd_apply(int argc, const char **argv, char **envp)
 
        if (write_index) {
                if (write_cache(newfd, active_cache, active_nr) ||
-                   commit_lock_file(&lock_file))
+                   close(newfd) || commit_lock_file(&lock_file))
                        die("Unable to write new index file");
        }
 
index 9a2099d7307903d62c85f3483a22969ab5094c84..23a8d92a4b77e7436069c976bc5fa0ec162a9324 100644 (file)
@@ -1038,7 +1038,7 @@ int cmd_read_tree(int argc, const char **argv, char **envp)
        }
 
        if (write_cache(newfd, active_cache, active_nr) ||
-           commit_lock_file(&lock_file))
+           close(newfd) || commit_lock_file(&lock_file))
                die("unable to write new index file");
        return 0;
 }
index 4d56a1f07065e6e8ebaa95fdfe843cffb6283af3..875d8252fa72cf7adc1d6bb254ebc3a5995e49dd 100644 (file)
@@ -147,7 +147,7 @@ int cmd_rm(int argc, const char **argv, char **envp)
 
        if (active_cache_changed) {
                if (write_cache(newfd, active_cache, active_nr) ||
-                   commit_lock_file(&lock_file))
+                   close(newfd) || commit_lock_file(&lock_file))
                        die("Unable to write new index file");
        }
 
index ef50243452c2f27572c941a5db9365c785f1fbd5..1a4200d151dd8e876c6f84531422cae50b049aa3 100644 (file)
@@ -648,7 +648,7 @@ int cmd_update_index(int argc, const char **argv, char **envp)
  finish:
        if (active_cache_changed) {
                if (write_cache(newfd, active_cache, active_nr) ||
-                   commit_lock_file(lock_file))
+                   close(newfd) || commit_lock_file(lock_file))
                        die("Unable to write new index file");
        }
 
index 70e9b6fcc6d93e9b869a0a1eac144cbea3ecba3f..449a4d1b575b591aa07a40532649f9ea06eb6890 100644 (file)
@@ -35,7 +35,8 @@ int write_tree(unsigned char *sha1, int missing_ok, const char *prefix)
                                      missing_ok, 0) < 0)
                        die("git-write-tree: error building trees");
                if (0 <= newfd) {
-                       if (!write_cache(newfd, active_cache, active_nr))
+                       if (!write_cache(newfd, active_cache, active_nr)
+                                       && !close(newfd))
                                commit_lock_file(lock_file);
                }
                /* Not being able to write is fine -- we are only interested
index ea40bc29bed17fbd6e3326edaa6fb3c38b742de6..29279555086ce36cdf598e390898a46888543846 100644 (file)
@@ -311,7 +311,7 @@ int main(int argc, char **argv)
 
        if (0 <= newfd &&
            (write_cache(newfd, active_cache, active_nr) ||
-            commit_lock_file(&lock_file)))
+            close(newfd) || commit_lock_file(&lock_file)))
                die("Unable to write new index file");
        return 0;
 }