]> granicus.if.org Git - php/commitdiff
fix occasional fail in zip_close when target arc exists
authorAnatol Belski <ab@php.net>
Wed, 19 Aug 2015 13:19:44 +0000 (15:19 +0200)
committerAnatol Belski <ab@php.net>
Wed, 19 Aug 2015 13:23:21 +0000 (15:23 +0200)
ext/zip/lib/zip_source_filep.c

index e541305d7f555246ba2c603c71a33837e90aff53..f99da2294ff881977f6ca3bfcb04b6b38e503b53 100644 (file)
@@ -43,6 +43,7 @@
 #ifdef _WIN32
 /* WIN32 needs <fcntl.h> for _O_BINARY */
 #include <fcntl.h>
+#include <windows.h>
 #endif
 
 /* Windows sys/types.h does not provide these */
@@ -248,10 +249,17 @@ read_file(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd)
                 zip_error_set(&ctx->error, ZIP_ER_WRITE, errno);
             }
             ctx->fout = NULL;
+#ifdef _WIN32
+            if (!MoveFileEx(ctx->tmpname, ctx->fname, MOVEFILE_REPLACE_EXISTING)) {
+                zip_error_set(&ctx->error, ZIP_ER_RENAME, GetLastError());
+                return -1;
+            }
+#else
             if (rename(ctx->tmpname, ctx->fname) < 0) {
                 zip_error_set(&ctx->error, ZIP_ER_RENAME, errno);
                 return -1;
             }
+#endif
            mask = umask(022);
            umask(mask);
            /* not much we can do if chmod fails except make the whole commit fail */