From: Anatol Belski Date: Wed, 19 Aug 2015 13:19:44 +0000 (+0200) Subject: fix occasional fail in zip_close when target arc exists X-Git-Tag: php-7.0.0RC2~2^2~111^2~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed78d59a1dc9d84cf6ce77fbad94ab7e2f860cb5;p=php fix occasional fail in zip_close when target arc exists --- diff --git a/ext/zip/lib/zip_source_filep.c b/ext/zip/lib/zip_source_filep.c index e541305d7f..f99da2294f 100644 --- a/ext/zip/lib/zip_source_filep.c +++ b/ext/zip/lib/zip_source_filep.c @@ -43,6 +43,7 @@ #ifdef _WIN32 /* WIN32 needs for _O_BINARY */ #include +#include #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 */