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 e49d5cb2b..a850868f6 100644 --- a/archival/ar.c +++ b/archival/ar.c | |||
@@ -165,6 +165,7 @@ static int write_ar_archive(archive_handle_t *handle) | |||
165 | { | 165 | { |
166 | struct stat st; | 166 | struct stat st; |
167 | archive_handle_t *out_handle; | 167 | archive_handle_t *out_handle; |
168 | char *temp_fn = NULL; | ||
168 | 169 | ||
169 | xfstat(handle->src_fd, &st, handle->ar__name); | 170 | xfstat(handle->src_fd, &st, handle->ar__name); |
170 | 171 | ||
@@ -173,8 +174,14 @@ static int write_ar_archive(archive_handle_t *handle) | |||
173 | */ | 174 | */ |
174 | if (st.st_size != 0) { | 175 | if (st.st_size != 0) { |
175 | out_handle = init_handle(); | 176 | out_handle = init_handle(); |
177 | #if !ENABLE_PLATFORM_MINGW32 | ||
176 | xunlink(handle->ar__name); | 178 | xunlink(handle->ar__name); |
177 | out_handle->src_fd = xopen(handle->ar__name, O_WRONLY | O_CREAT | O_TRUNC); | 179 | out_handle->src_fd = xopen(handle->ar__name, O_WRONLY | O_CREAT | O_TRUNC); |
180 | #else | ||
181 | /* can't unlink open file, create temporary output file */ | ||
182 | temp_fn = xasprintf("%sXXXXXX", handle->ar__name); | ||
183 | out_handle->src_fd = xmkstemp(temp_fn); | ||
184 | #endif | ||
178 | out_handle->accept = handle->accept; | 185 | out_handle->accept = handle->accept; |
179 | } else { | 186 | } else { |
180 | out_handle = handle; | 187 | out_handle = handle; |
@@ -196,12 +203,19 @@ static int write_ar_archive(archive_handle_t *handle) | |||
196 | continue; | 203 | continue; |
197 | 204 | ||
198 | /* optional, since we exit right after we return */ | 205 | /* optional, since we exit right after we return */ |
199 | if (ENABLE_FEATURE_CLEAN_UP) { | 206 | if (ENABLE_FEATURE_CLEAN_UP || ENABLE_PLATFORM_MINGW32) { |
200 | close(handle->src_fd); | 207 | close(handle->src_fd); |
201 | if (out_handle->src_fd != handle->src_fd) | 208 | if (out_handle->src_fd != handle->src_fd) |
202 | close(out_handle->src_fd); | 209 | close(out_handle->src_fd); |
203 | } | 210 | } |
204 | 211 | ||
212 | #if ENABLE_PLATFORM_MINGW32 | ||
213 | if ( temp_fn != NULL ) { | ||
214 | xrename(temp_fn, handle->ar__name); | ||
215 | free(temp_fn); | ||
216 | } | ||
217 | #endif | ||
218 | |||
205 | return EXIT_SUCCESS; | 219 | return EXIT_SUCCESS; |
206 | } | 220 | } |
207 | #endif /* FEATURE_AR_CREATE */ | 221 | #endif /* FEATURE_AR_CREATE */ |