Fixed symbolic links don't extract on macOS. #620

This commit is contained in:
Nathan Moinvaziri 2022-11-29 16:51:20 -08:00
parent 4c44bd1e66
commit a4b0c789f9
2 changed files with 25 additions and 5 deletions

View File

@ -792,13 +792,13 @@ static int32_t mz_zip_entry_write_header(void *stream, uint8_t local, mz_zip_fil
const char *backslash = NULL;
const char *next = filename;
int32_t left = filename_length;
/* Ensure all slashes are written as forward slashes according to 4.4.17.1 */
while ((err == MZ_OK) && (backslash = strrchr(next, '\\')) != NULL) {
int32_t part_length = (int32_t)(backslash - next);
if (mz_stream_write(stream, next, part_length) != part_length ||
mz_stream_write(stream, "/", 1) != 1)
mz_stream_write(stream, "/", 1) != 1)
err = MZ_WRITE_ERROR;
left -= part_length + 1;
@ -2308,8 +2308,6 @@ int32_t mz_zip_entry_is_symlink(void *handle) {
return MZ_PARAM_ERROR;
if (mz_zip_attrib_is_symlink(zip->file_info.external_fa, zip->file_info.version_madeby) != MZ_OK)
return MZ_EXIST_ERROR;
if (zip->file_info.linkname == NULL || *zip->file_info.linkname == 0)
return MZ_EXIST_ERROR;
return MZ_OK;
}

View File

@ -738,7 +738,29 @@ int32_t mz_zip_reader_entry_save_file(void *handle, const char *path) {
/* If it is a symbolic link then create symbolic link instead of writing file */
if (mz_zip_entry_is_symlink(reader->zip_handle) == MZ_OK) {
mz_os_make_symlink(pathwfs, reader->file_info->linkname);
if (reader->file_info->linkname != NULL && *reader->file_info->linkname != 0) {
/* Create symbolic link from UNIX1 extrafield */
err = mz_os_make_symlink(pathwfs, reader->file_info->linkname);
} else {
/* Create symbolic link from zip entry contents */
mz_stream_mem_create(&stream);
mz_stream_mem_set_buffer_limit(stream, reader->file_info->uncompressed_size);
err = mz_stream_mem_open(stream, NULL, MZ_OPEN_MODE_CREATE);
if (err == MZ_OK)
err = mz_zip_reader_entry_save(handle, stream, mz_stream_write);
if (err == MZ_OK) {
const char *linkname = NULL;
if (mz_stream_mem_get_buffer(stream, (const void **)&linkname) == MZ_OK)
err = mz_os_make_symlink(pathwfs, linkname);
}
mz_stream_mem_close(stream);
mz_stream_mem_delete(&stream);
}
/* Don't check return value because we aren't validating symbolic link target */
return err;
}