mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
- make status, statusSys properties and
ZipArchive::getStatusString() method available after archive is closed
This commit is contained in:
parent
32c2ae2939
commit
6f53605275
6 changed files with 84 additions and 40 deletions
|
@ -304,7 +304,7 @@ static int php_zip_add_file(ze_zip_object *obj, const char *filename, size_t fil
|
|||
if (!zs) {
|
||||
return -1;
|
||||
}
|
||||
// Replace
|
||||
/* Replace */
|
||||
if (replace >= 0) {
|
||||
if (zip_file_replace(obj->za, replace, zs, flags) < 0) {
|
||||
zip_source_free(zs);
|
||||
|
@ -313,7 +313,7 @@ static int php_zip_add_file(ze_zip_object *obj, const char *filename, size_t fil
|
|||
zip_error_clear(obj->za);
|
||||
return 1;
|
||||
}
|
||||
// Add
|
||||
/* Add */
|
||||
obj->last_id = zip_file_add(obj->za, entry_name, zs, flags);
|
||||
if (obj->last_id < 0) {
|
||||
zip_source_free(zs);
|
||||
|
@ -436,18 +436,21 @@ static int php_zip_parse_options(zval *options, zend_long *remove_all_path,
|
|||
|
||||
static zend_long php_zip_status(ze_zip_object *obj) /* {{{ */
|
||||
{
|
||||
int zep = obj->err_zip; /* saved err if closed */
|
||||
|
||||
if (obj->za) {
|
||||
#if LIBZIP_VERSION_MAJOR < 1
|
||||
int zep, syp;
|
||||
int syp;
|
||||
|
||||
zip_error_get(obj->za, &zep, &syp);
|
||||
zip_error_get(obj->za, &zep, &syp);
|
||||
#else
|
||||
int zep;
|
||||
zip_error_t *err;
|
||||
zip_error_t *err;
|
||||
|
||||
err = zip_get_error(obj->za);
|
||||
zep = zip_error_code_zip(err);
|
||||
zip_error_fini(err);
|
||||
err = zip_get_error(obj->za);
|
||||
zep = zip_error_code_zip(err);
|
||||
zip_error_fini(err);
|
||||
#endif
|
||||
}
|
||||
return zep;
|
||||
}
|
||||
/* }}} */
|
||||
|
@ -460,26 +463,32 @@ static zend_long php_zip_last_id(ze_zip_object *obj) /* {{{ */
|
|||
|
||||
static zend_long php_zip_status_sys(ze_zip_object *obj) /* {{{ */
|
||||
{
|
||||
int syp = obj->err_sys; /* saved err if closed */
|
||||
|
||||
if (obj->za) {
|
||||
#if LIBZIP_VERSION_MAJOR < 1
|
||||
int zep, syp;
|
||||
int zep;
|
||||
|
||||
zip_error_get(obj->za, &zep, &syp);
|
||||
zip_error_get(obj->za, &zep, &syp);
|
||||
#else
|
||||
int syp;
|
||||
zip_error_t *err;
|
||||
zip_error_t *err;
|
||||
|
||||
err = zip_get_error(obj->za);
|
||||
syp = zip_error_code_system(err);
|
||||
zip_error_fini(err);
|
||||
err = zip_get_error(obj->za);
|
||||
syp = zip_error_code_system(err);
|
||||
zip_error_fini(err);
|
||||
#endif
|
||||
}
|
||||
return syp;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static zend_long php_zip_get_num_files(ze_zip_object *obj) /* {{{ */
|
||||
{
|
||||
zip_int64_t num = zip_get_num_entries(obj->za, 0);
|
||||
return MIN(num, ZEND_LONG_MAX);
|
||||
if (obj->za) {
|
||||
zip_int64_t num = zip_get_num_entries(obj->za, 0);
|
||||
return MIN(num, ZEND_LONG_MAX);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
@ -803,12 +812,10 @@ static zval *php_zip_property_reader(ze_zip_object *obj, zip_prop_handler *hnd,
|
|||
zend_long retint = 0;
|
||||
int len = 0;
|
||||
|
||||
if (obj && obj->za != NULL) {
|
||||
if (hnd->read_const_char_func) {
|
||||
retchar = hnd->read_const_char_func(obj, &len);
|
||||
} else if (hnd->read_int_func) {
|
||||
retint = hnd->read_int_func(obj);
|
||||
}
|
||||
if (hnd->read_const_char_func) {
|
||||
retchar = hnd->read_const_char_func(obj, &len);
|
||||
} else if (hnd->read_int_func) {
|
||||
retint = hnd->read_int_func(obj);
|
||||
}
|
||||
|
||||
switch (hnd->type) {
|
||||
|
@ -1488,7 +1495,23 @@ static ZIPARCHIVE_METHOD(close)
|
|||
|
||||
ze_obj = Z_ZIP_P(self);
|
||||
|
||||
if ((err = zip_close(intern))) {
|
||||
err = zip_close(intern);
|
||||
|
||||
/* Save error for property reader */
|
||||
#if LIBZIP_VERSION_MAJOR < 1
|
||||
zip_error_get(obj->za, &ze_obj->err_zip, &ze_obj->err_sys);
|
||||
#else
|
||||
{
|
||||
zip_error_t *ziperr;
|
||||
|
||||
ziperr = zip_get_error(intern);
|
||||
ze_obj->err_zip = zip_error_code_zip(ziperr);
|
||||
ze_obj->err_sys = zip_error_code_system(ziperr);
|
||||
zip_error_fini(ziperr);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err) {
|
||||
#if LIBZIP_VERSION_MAJOR == 1 && LIBZIP_VERSION_MINOR == 3 && LIBZIP_VERSION_MICRO == 1
|
||||
php_error_docref(NULL, E_WARNING, "zip_close have failed");
|
||||
#else
|
||||
|
@ -1533,30 +1556,42 @@ static ZIPARCHIVE_METHOD(count)
|
|||
* Returns the status error message, system and/or zip messages */
|
||||
static ZIPARCHIVE_METHOD(getStatusString)
|
||||
{
|
||||
struct zip *intern;
|
||||
zval *self = ZEND_THIS;
|
||||
#if LIBZIP_VERSION_MAJOR < 1
|
||||
int zep, syp, len;
|
||||
char error_string[128];
|
||||
#else
|
||||
zip_error_t *err;
|
||||
#endif
|
||||
ze_zip_object *ze_obj;
|
||||
|
||||
if (zend_parse_parameters_none() == FAILURE) {
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
ZIP_FROM_OBJECT(intern, self);
|
||||
ze_obj = Z_ZIP_P(self); /* not ZIP_FROM_OBJECT as we can use saved error after close */
|
||||
|
||||
#if LIBZIP_VERSION_MAJOR < 1
|
||||
zip_error_get(intern, &zep, &syp);
|
||||
|
||||
len = zip_error_to_str(error_string, 128, zep, syp);
|
||||
if (ze_obj->za) {
|
||||
zip_error_get(ze_obj->za, &zep, &syp);
|
||||
len = zip_error_to_str(error_string, 128, zep, syp);
|
||||
} else {
|
||||
len = zip_error_to_str(error_string, 128, ze_obj->err_zip, ze_obj->err_sys);
|
||||
}
|
||||
RETVAL_STRINGL(error_string, len);
|
||||
#else
|
||||
err = zip_get_error(intern);
|
||||
RETVAL_STRING(zip_error_strerror(err));
|
||||
zip_error_fini(err);
|
||||
if (ze_obj->za) {
|
||||
zip_error_t *err;
|
||||
|
||||
err = zip_get_error(ze_obj->za);
|
||||
RETVAL_STRING(zip_error_strerror(err));
|
||||
zip_error_fini(err);
|
||||
} else {
|
||||
zip_error_t err;
|
||||
|
||||
zip_error_init_with_code(&err, ze_obj->err_zip);
|
||||
err.sys_err = ze_obj->err_sys; /* missing setter */
|
||||
RETVAL_STRING(zip_error_strerror(&err));
|
||||
zip_error_fini(&err);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/* }}} */
|
||||
|
@ -3159,7 +3194,7 @@ static PHP_MINIT_FUNCTION(zip)
|
|||
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_OS_2", ZIP_OPSYS_OS_2);
|
||||
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_MACINTOSH", ZIP_OPSYS_MACINTOSH);
|
||||
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_Z_SYSTEM", ZIP_OPSYS_Z_SYSTEM);
|
||||
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_Z_CPM", ZIP_OPSYS_CPM); // typo kept for BC
|
||||
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_Z_CPM", ZIP_OPSYS_CPM); /* typo kept for BC */
|
||||
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_CPM", ZIP_OPSYS_CPM);
|
||||
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_WINDOWS_NTFS", ZIP_OPSYS_WINDOWS_NTFS);
|
||||
REGISTER_ZIP_CLASS_CONST_LONG("OPSYS_MVS", ZIP_OPSYS_MVS);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue