tempfile: factor out deactivation
[gitweb.git] / diff.c
diff --git a/diff.c b/diff.c
index a74cc0848820d2eede6e0936cc511112d05bbd4c..20f68ec3892cb51d87fdae629361e6cc1f80e948 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -21,6 +21,7 @@
 #include "string-list.h"
 #include "argv-array.h"
 #include "graph.h"
+#include "packfile.h"
 
 #ifdef NO_FAST_WORKING_DIRECTORY
 #define FAST_WORKING_DIRECTORY 0
@@ -3737,9 +3738,9 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
                blob = buf.buf;
                size = buf.len;
        }
-       if (write_in_full(fd, blob, size) != size)
+       if (write_in_full(fd, blob, size) != size ||
+           close_tempfile_gently(&temp->tempfile))
                die_errno("unable to write temp-file");
-       close_tempfile(&temp->tempfile);
        temp->name = get_tempfile_path(&temp->tempfile);
        oid_to_hex_r(temp->hex, oid);
        xsnprintf(temp->mode, sizeof(temp->mode), "%06o", mode);