diff options
Diffstat (limited to 'archival/ar.c')
-rw-r--r-- | archival/ar.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/archival/ar.c b/archival/ar.c index 2886d155b..ea36bda88 100644 --- a/archival/ar.c +++ b/archival/ar.c | |||
@@ -163,6 +163,7 @@ static int write_ar_archive(archive_handle_t *handle) | |||
163 | { | 163 | { |
164 | struct stat st; | 164 | struct stat st; |
165 | archive_handle_t *out_handle; | 165 | archive_handle_t *out_handle; |
166 | char *temp_fn = NULL; | ||
166 | 167 | ||
167 | xfstat(handle->src_fd, &st, handle->ar__name); | 168 | xfstat(handle->src_fd, &st, handle->ar__name); |
168 | 169 | ||
@@ -171,8 +172,14 @@ static int write_ar_archive(archive_handle_t *handle) | |||
171 | */ | 172 | */ |
172 | if (st.st_size != 0) { | 173 | if (st.st_size != 0) { |
173 | out_handle = init_handle(); | 174 | out_handle = init_handle(); |
175 | #if !ENABLE_PLATFORM_MINGW32 | ||
174 | xunlink(handle->ar__name); | 176 | xunlink(handle->ar__name); |
175 | out_handle->src_fd = xopen(handle->ar__name, O_WRONLY | O_CREAT | O_TRUNC); | 177 | out_handle->src_fd = xopen(handle->ar__name, O_WRONLY | O_CREAT | O_TRUNC); |
178 | #else | ||
179 | /* can't unlink open file, create temporary output file */ | ||
180 | temp_fn = xasprintf("%sXXXXXX", handle->ar__name); | ||
181 | out_handle->src_fd = xmkstemp(temp_fn); | ||
182 | #endif | ||
176 | out_handle->accept = handle->accept; | 183 | out_handle->accept = handle->accept; |
177 | } else { | 184 | } else { |
178 | out_handle = handle; | 185 | out_handle = handle; |
@@ -194,12 +201,19 @@ static int write_ar_archive(archive_handle_t *handle) | |||
194 | continue; | 201 | continue; |
195 | 202 | ||
196 | /* optional, since we exit right after we return */ | 203 | /* optional, since we exit right after we return */ |
197 | if (ENABLE_FEATURE_CLEAN_UP) { | 204 | if (ENABLE_FEATURE_CLEAN_UP || ENABLE_PLATFORM_MINGW32) { |
198 | close(handle->src_fd); | 205 | close(handle->src_fd); |
199 | if (out_handle->src_fd != handle->src_fd) | 206 | if (out_handle->src_fd != handle->src_fd) |
200 | close(out_handle->src_fd); | 207 | close(out_handle->src_fd); |
201 | } | 208 | } |
202 | 209 | ||
210 | #if ENABLE_PLATFORM_MINGW32 | ||
211 | if ( temp_fn != NULL ) { | ||
212 | xrename(temp_fn, handle->ar__name); | ||
213 | free(temp_fn); | ||
214 | } | ||
215 | #endif | ||
216 | |||
203 | return EXIT_SUCCESS; | 217 | return EXIT_SUCCESS; |
204 | } | 218 | } |
205 | #endif /* FEATURE_AR_CREATE */ | 219 | #endif /* FEATURE_AR_CREATE */ |