Exemplo n.º 1
0
void
_zip_entry_finalize(struct zip_entry *e)
{
    _zip_unchange_data(e);
    _zip_dirent_free(e->orig);
    _zip_dirent_free(e->changes);
}
Exemplo n.º 2
0
int
_zip_unchange(struct zip *za, zip_uint64_t idx, int allow_duplicates)
{
    zip_int64_t i;

    if (idx >= za->nentry) {
        _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
        return -1;
    }

    if (!allow_duplicates && za->entry[idx].changes && (za->entry[idx].changes->changed & ZIP_DIRENT_FILENAME)) {
        i = _zip_name_locate(za, _zip_get_name(za, idx, ZIP_FL_UNCHANGED, NULL), 0, NULL);
        if (i >= 0 && (zip_uint64_t)i != idx) {
            _zip_error_set(&za->error, ZIP_ER_EXISTS, 0);
            return -1;
        }
    }

    _zip_dirent_free(za->entry[idx].changes);
    za->entry[idx].changes = NULL;

    _zip_unchange_data(za->entry+idx);

    return 0;
}
zip_int64_t
_zip_replace(struct zip *za, zip_uint64_t idx, const char *name,
	     struct zip_source *source)
{
    zip_uint64_t za_nentry_prev;
    if (ZIP_IS_RDONLY(za)) {
	_zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
	return -1;
    }

    za_nentry_prev = za->nentry;
    if (idx == ZIP_UINT64_MAX) {
	if (_zip_entry_new(za) == NULL)
	    return -1;
	
	idx = za->nentry - 1;
	za->entry[idx].changes.valid |= ZIP_DIRENT_COMP_METHOD;
	za->entry[idx].changes.comp_method = ZIP_CM_DEFLATE; /* XXX: default */
    }
    
    if (name && _zip_set_name(za, idx, name) != 0) {
	za->nentry = za_nentry_prev;
	return -1;
    }

    /* does not change any name related data, so we can do it here;
     * needed for a double add of the same file name */
    _zip_unchange_data(za->entry+idx);

    za->entry[idx].state = ((za->cdir == NULL || idx >= (zip_uint64_t)za->cdir->nentry)
			    ? ZIP_ST_ADDED : ZIP_ST_REPLACED);
    za->entry[idx].source = source;

    return idx;
}
Exemplo n.º 4
0
int
_zip_unchange(struct zip *za, int idx, int allow_duplicates)
{
    int i;
    
    if (idx < 0 || idx >= za->nentry) {
	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
	return -1;
    }

    if (za->entry[idx].ch_filename) {
	if (!allow_duplicates) {
	    i = _zip_name_locate(za,
			 _zip_get_name(za, idx, ZIP_FL_UNCHANGED, NULL),
				 0, NULL);
	    if (i != -1 && i != idx) {
		_zip_error_set(&za->error, ZIP_ER_EXISTS, 0);
		return -1;
	    }
	}

	free(za->entry[idx].ch_filename);
	za->entry[idx].ch_filename = NULL;
    }

    free(za->entry[idx].ch_comment);
    za->entry[idx].ch_comment = NULL;
    za->entry[idx].ch_comment_len = -1;

    _zip_unchange_data(za->entry+idx);

    return 0;
}
Exemplo n.º 5
0
void
_zip_entry_free(struct zip_entry *ze)
{
    free(ze->ch_filename);
    ze->ch_filename = NULL;

    _zip_unchange_data(ze);
}
Exemplo n.º 6
0
void
_zip_entry_free(struct zip_entry *ze)
{
    free(ze->ch_filename);
    ze->ch_filename = NULL;
    free(ze->ch_comment);
    ze->ch_comment = NULL;
    ze->ch_comment_len = -1;

    _zip_unchange_data(ze);
}
Exemplo n.º 7
0
zip_int64_t
_zip_file_replace(struct zip *za, zip_uint64_t idx, const char *name, struct zip_source *source, zip_flags_t flags)
{
    zip_uint64_t za_nentry_prev;
    
    if (ZIP_IS_RDONLY(za)) {
	_zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
	return -1;
    }

    za_nentry_prev = za->nentry;
    if (idx == ZIP_UINT64_MAX) {
	zip_int64_t i = -1;
	
	if (flags & ZIP_FL_OVERWRITE)
	    i = _zip_name_locate(za, name, flags, NULL);

	if (i == -1) {
	    /* create and use new entry, used by zip_add */
	    if ((i=_zip_add_entry(za)) < 0)
		return -1;
	}
	idx = (zip_uint64_t)i;
    }
    
    if (name && _zip_set_name(za, idx, name, flags) != 0) {
	if (za->nentry != za_nentry_prev) {
	    _zip_entry_finalize(za->entry+idx);
	    za->nentry = za_nentry_prev;
	}
	return -1;
    }

    /* does not change any name related data, so we can do it here;
     * needed for a double add of the same file name */
    _zip_unchange_data(za->entry+idx);

    if (za->entry[idx].orig != NULL && (za->entry[idx].changes == NULL || (za->entry[idx].changes->changed & ZIP_DIRENT_COMP_METHOD) == 0)) {
        if (za->entry[idx].changes == NULL) {
            if ((za->entry[idx].changes=_zip_dirent_clone(za->entry[idx].orig)) == NULL) {
                _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
                return -1;
            }
        }

        za->entry[idx].changes->comp_method = ZIP_CM_REPLACED_DEFAULT;
        za->entry[idx].changes->changed |= ZIP_DIRENT_COMP_METHOD;
    }
	
    za->entry[idx].source = source;

    return (zip_int64_t)idx;
}