1
0
Fork 0

fix spurious unzip errors (#2867)

This commit is contained in:
Jan 2017-07-25 22:17:37 +02:00 committed by Frank Celler
parent 42aa279e99
commit af36f6e7b6
2 changed files with 24 additions and 18 deletions

View File

@ -95,12 +95,11 @@ static int ExtractCurrentFile(unzFile uf, void* buffer, size_t const bufferSize,
int res =
TRI_CreateRecursiveDirectory(fullPath, systemError, errorMessage);
if (res != TRI_ERROR_NO_ERROR) {
TRI_Free(TRI_CORE_MEM_ZONE, fullPath);
if (res != TRI_ERROR_NO_ERROR) {
return res;
}
TRI_Free(TRI_CORE_MEM_ZONE, fullPath);
}
}
@ -143,13 +142,12 @@ static int ExtractCurrentFile(unzFile uf, void* buffer, size_t const bufferSize,
char* d = TRI_Concatenate2File(outPath, filenameInZip);
int res = TRI_CreateRecursiveDirectory(d, systemError, errorMessage);
if (res != TRI_ERROR_NO_ERROR) {
TRI_Free(TRI_CORE_MEM_ZONE, d);
if (res != TRI_ERROR_NO_ERROR) {
return res;
}
TRI_Free(TRI_CORE_MEM_ZONE, d);
*(filenameWithoutPath - 1) = c;
// try again
@ -161,21 +159,20 @@ static int ExtractCurrentFile(unzFile uf, void* buffer, size_t const bufferSize,
char* dir = TRI_Dirname(d);
int res = TRI_CreateRecursiveDirectory(dir, systemError, errorMessage);
if (res != TRI_ERROR_NO_ERROR) {
TRI_Free(TRI_CORE_MEM_ZONE, d);
TRI_Free(TRI_CORE_MEM_ZONE, dir);
if (res != TRI_ERROR_NO_ERROR) {
return res;
}
TRI_Free(TRI_CORE_MEM_ZONE, d);
TRI_Free(TRI_CORE_MEM_ZONE, dir);
// try again
fout = fopen(fullPath, "wb");
}
if (fout == NULL) {
errorMessage = std::string("failed to open file for writing: ") +
fullPath + " - " + strerror(errno);
errorMessage = std::string("failed to open file '") +
fullPath + "' for writing: " + strerror(errno);
TRI_Free(TRI_CORE_MEM_ZONE, fullPath);
return TRI_ERROR_CANNOT_WRITE_FILE;
}
@ -184,8 +181,7 @@ static int ExtractCurrentFile(unzFile uf, void* buffer, size_t const bufferSize,
int result = unzReadCurrentFile(uf, buffer, (unsigned int)bufferSize);
if (result < 0) {
errorMessage = std::string("failed to write file ") + fullPath + " - " +
strerror(errno);
errorMessage = std::string("failed to read from zip file: ") + strerror(errno);
fclose(fout);
TRI_Free(TRI_CORE_MEM_ZONE, fullPath);
return TRI_ERROR_CANNOT_WRITE_FILE;
@ -209,7 +205,10 @@ static int ExtractCurrentFile(unzFile uf, void* buffer, size_t const bufferSize,
fclose(fout);
}
unzCloseCurrentFile(uf);
int ret = unzCloseCurrentFile(uf);
if (ret < 0) {
return TRI_ERROR_CANNOT_WRITE_FILE;
}
return TRI_ERROR_NO_ERROR;
}
@ -433,6 +432,7 @@ int TRI_Adler32(char const* filename, uint32_t& checksum) {
int TRI_UnzipFile(char const* filename, char const* outPath,
bool skipPaths, bool overwrite,
char const* password, std::string& errorMessage) {
#ifdef USEWIN32IOAPI
zlib_filefunc64_def ffunc;
#endif

View File

@ -760,12 +760,13 @@ extern int ZEXPORT unzClose(unzFile file) {
unz64_s* s;
if (file == NULL) return UNZ_PARAMERROR;
s = (unz64_s*)file;
int ret = UNZ_OK;
if (s->pfile_in_zip_read != NULL) unzCloseCurrentFile(file);
if (s->pfile_in_zip_read != NULL) ret = unzCloseCurrentFile(file);
ZCLOSE64(s->z_filefunc, s->filestream);
TRYFREE(s);
return UNZ_OK;
return ret;
}
/*
@ -1390,7 +1391,12 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int* method, int* level,
s = (unz64_s*)file;
if (!s->current_file_ok) return UNZ_PARAMERROR;
if (s->pfile_in_zip_read != NULL) unzCloseCurrentFile(file);
if (s->pfile_in_zip_read != NULL) {
int ret = unzCloseCurrentFile(file);
if (ret != UNZ_OK) {
return ret;
}
}
if (unz64local_CheckCurrentFileCoherencyHeader(
s, &iSizeVar, &offset_local_extrafield, &size_local_extrafield) !=