|
5 | 5 | */
|
6 | 6 | #define NO_THE_INDEX_COMPATIBILITY_MACROS
|
7 | 7 | #include "cache.h"
|
| 8 | +#include "tempfile.h" |
8 | 9 | #include "lockfile.h"
|
9 | 10 | #include "cache-tree.h"
|
10 | 11 | #include "refs.h"
|
@@ -2136,54 +2137,27 @@ static int write_split_index(struct index_state *istate,
|
2136 | 2137 | return ret;
|
2137 | 2138 | }
|
2138 | 2139 |
|
2139 |
| -static char *temporary_sharedindex; |
2140 |
| - |
2141 |
| -static void remove_temporary_sharedindex(void) |
2142 |
| -{ |
2143 |
| - if (temporary_sharedindex) { |
2144 |
| - unlink_or_warn(temporary_sharedindex); |
2145 |
| - free(temporary_sharedindex); |
2146 |
| - temporary_sharedindex = NULL; |
2147 |
| - } |
2148 |
| -} |
2149 |
| - |
2150 |
| -static void remove_temporary_sharedindex_on_signal(int signo) |
2151 |
| -{ |
2152 |
| - remove_temporary_sharedindex(); |
2153 |
| - sigchain_pop(signo); |
2154 |
| - raise(signo); |
2155 |
| -} |
| 2140 | +static struct tempfile temporary_sharedindex; |
2156 | 2141 |
|
2157 | 2142 | static int write_shared_index(struct index_state *istate,
|
2158 | 2143 | struct lock_file *lock, unsigned flags)
|
2159 | 2144 | {
|
2160 | 2145 | struct split_index *si = istate->split_index;
|
2161 |
| - static int installed_handler; |
2162 | 2146 | int fd, ret;
|
2163 | 2147 |
|
2164 |
| - temporary_sharedindex = git_pathdup("sharedindex_XXXXXX"); |
2165 |
| - fd = mkstemp(temporary_sharedindex); |
| 2148 | + fd = mks_tempfile(&temporary_sharedindex, git_path("sharedindex_XXXXXX")); |
2166 | 2149 | if (fd < 0) {
|
2167 |
| - free(temporary_sharedindex); |
2168 |
| - temporary_sharedindex = NULL; |
2169 | 2150 | hashclr(si->base_sha1);
|
2170 | 2151 | return do_write_locked_index(istate, lock, flags);
|
2171 | 2152 | }
|
2172 |
| - if (!installed_handler) { |
2173 |
| - atexit(remove_temporary_sharedindex); |
2174 |
| - sigchain_push_common(remove_temporary_sharedindex_on_signal); |
2175 |
| - } |
2176 | 2153 | move_cache_to_base_index(istate);
|
2177 | 2154 | ret = do_write_index(si->base, fd, 1);
|
2178 |
| - close(fd); |
2179 | 2155 | if (ret) {
|
2180 |
| - remove_temporary_sharedindex(); |
| 2156 | + delete_tempfile(&temporary_sharedindex); |
2181 | 2157 | return ret;
|
2182 | 2158 | }
|
2183 |
| - ret = rename(temporary_sharedindex, |
2184 |
| - git_path("sharedindex.%s", sha1_to_hex(si->base->sha1))); |
2185 |
| - free(temporary_sharedindex); |
2186 |
| - temporary_sharedindex = NULL; |
| 2159 | + ret = rename_tempfile(&temporary_sharedindex, |
| 2160 | + git_path("sharedindex.%s", sha1_to_hex(si->base->sha1))); |
2187 | 2161 | if (!ret)
|
2188 | 2162 | hashcpy(si->base_sha1, si->base->sha1);
|
2189 | 2163 | return ret;
|
|
0 commit comments