zipruby 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of zipruby might be problematic. Click here for more details.
- data/README.txt +131 -0
- data/ext/extconf.rb +1 -1
- data/ext/libzip.mswin32.patch +113 -0
- data/ext/libzip.vcproj +308 -0
- data/ext/libzip.vcproj.IBM-94B792EFFD1.sugawara.user +37 -0
- data/ext/mkstemp.c +143 -0
- data/ext/zip.h +211 -0
- data/ext/zip_add.c +52 -0
- data/ext/zip_add_dir.c +83 -0
- data/ext/zip_close.c +566 -0
- data/ext/zip_delete.c +61 -0
- data/ext/zip_dirent.c +531 -0
- data/ext/zip_entry_free.c +55 -0
- data/ext/zip_entry_new.c +81 -0
- data/ext/zip_err_str.c +72 -0
- data/ext/zip_error.c +104 -0
- data/ext/zip_error_clear.c +47 -0
- data/ext/zip_error_get.c +47 -0
- data/ext/zip_error_get_sys_type.c +50 -0
- data/ext/zip_error_strerror.c +93 -0
- data/ext/zip_error_to_str.c +77 -0
- data/ext/zip_fclose.c +74 -0
- data/ext/zip_file_error_clear.c +47 -0
- data/ext/zip_file_error_get.c +47 -0
- data/ext/zip_file_get_offset.c +77 -0
- data/ext/zip_file_strerror.c +47 -0
- data/ext/zip_fopen.c +52 -0
- data/ext/zip_fopen_index.c +219 -0
- data/ext/zip_fread.c +125 -0
- data/ext/zip_free.c +83 -0
- data/ext/zip_get_archive_comment.c +63 -0
- data/ext/zip_get_file_comment.c +61 -0
- data/ext/zip_get_name.c +74 -0
- data/ext/zip_get_num_files.c +50 -0
- data/ext/zip_memdup.c +58 -0
- data/ext/zip_name_locate.c +95 -0
- data/ext/zip_new.c +71 -0
- data/ext/zip_open.c +520 -0
- data/ext/zip_rename.c +52 -0
- data/ext/zip_replace.c +81 -0
- data/ext/zip_set_archive_comment.c +68 -0
- data/ext/zip_set_file_comment.c +69 -0
- data/ext/zip_set_name.c +77 -0
- data/ext/zip_source_buffer.c +160 -0
- data/ext/zip_source_file.c +71 -0
- data/ext/zip_source_filep.c +176 -0
- data/ext/zip_source_free.c +54 -0
- data/ext/zip_source_function.c +62 -0
- data/ext/zip_source_zip.c +189 -0
- data/ext/zip_stat.c +52 -0
- data/ext/zip_stat_index.c +93 -0
- data/ext/zip_stat_init.c +53 -0
- data/ext/zip_strerror.c +47 -0
- data/ext/zip_unchange.c +84 -0
- data/ext/zip_unchange_all.c +56 -0
- data/ext/zip_unchange_archive.c +52 -0
- data/ext/zip_unchange_data.c +53 -0
- data/ext/zipint.h +240 -0
- data/ext/zipruby.h +1 -1
- metadata +63 -5
@@ -0,0 +1,189 @@
|
|
1
|
+
/*
|
2
|
+
$NiH: zip_source_zip.c,v 1.6 2005/06/09 19:57:10 dillo Exp $
|
3
|
+
|
4
|
+
zip_source_zip.c -- create data source from zip file
|
5
|
+
Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner
|
6
|
+
|
7
|
+
This file is part of libzip, a library to manipulate ZIP archives.
|
8
|
+
The authors can be contacted at <nih@giga.or.at>
|
9
|
+
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
11
|
+
modification, are permitted provided that the following conditions
|
12
|
+
are met:
|
13
|
+
1. Redistributions of source code must retain the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer.
|
15
|
+
2. Redistributions in binary form must reproduce the above copyright
|
16
|
+
notice, this list of conditions and the following disclaimer in
|
17
|
+
the documentation and/or other materials provided with the
|
18
|
+
distribution.
|
19
|
+
3. The names of the authors may not be used to endorse or promote
|
20
|
+
products derived from this software without specific prior
|
21
|
+
written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
24
|
+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
27
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
28
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
29
|
+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
31
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
32
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
33
|
+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
#include <stdlib.h>
|
39
|
+
#include <string.h>
|
40
|
+
|
41
|
+
#include "zip.h"
|
42
|
+
#include "zipint.h"
|
43
|
+
|
44
|
+
struct read_zip {
|
45
|
+
struct zip_file *zf;
|
46
|
+
struct zip_stat st;
|
47
|
+
off_t off, len;
|
48
|
+
};
|
49
|
+
|
50
|
+
static ssize_t read_zip(void *st, void *data, size_t len,
|
51
|
+
enum zip_source_cmd cmd);
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
struct zip_source *
|
56
|
+
zip_source_zip(struct zip *za, struct zip *srcza, int srcidx, int flags,
|
57
|
+
off_t start, off_t len)
|
58
|
+
{
|
59
|
+
struct zip_error error;
|
60
|
+
struct zip_source *zs;
|
61
|
+
struct read_zip *p;
|
62
|
+
|
63
|
+
if (za == NULL)
|
64
|
+
return NULL;
|
65
|
+
|
66
|
+
if (srcza == NULL || start < 0 || len < -1 || srcidx < 0 || srcidx >= srcza->nentry) {
|
67
|
+
_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
|
68
|
+
return NULL;
|
69
|
+
}
|
70
|
+
|
71
|
+
if ((flags & ZIP_FL_UNCHANGED) == 0
|
72
|
+
&& ZIP_ENTRY_DATA_CHANGED(srcza->entry+srcidx)) {
|
73
|
+
_zip_error_set(&za->error, ZIP_ER_CHANGED, 0);
|
74
|
+
return NULL;
|
75
|
+
}
|
76
|
+
|
77
|
+
if (len == 0)
|
78
|
+
len = -1;
|
79
|
+
|
80
|
+
if (start == 0 && len == -1)
|
81
|
+
flags |= ZIP_FL_COMPRESSED;
|
82
|
+
else
|
83
|
+
flags &= ~ZIP_FL_COMPRESSED;
|
84
|
+
|
85
|
+
if ((p=(struct read_zip *)malloc(sizeof(*p))) == NULL) {
|
86
|
+
_zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
|
87
|
+
return NULL;
|
88
|
+
}
|
89
|
+
|
90
|
+
_zip_error_copy(&error, &srcza->error);
|
91
|
+
|
92
|
+
if (zip_stat_index(srcza, srcidx, flags, &p->st) < 0
|
93
|
+
|| (p->zf=zip_fopen_index(srcza, srcidx, flags)) == NULL) {
|
94
|
+
free(p);
|
95
|
+
_zip_error_copy(&za->error, &srcza->error);
|
96
|
+
_zip_error_copy(&srcza->error, &error);
|
97
|
+
|
98
|
+
return NULL;
|
99
|
+
}
|
100
|
+
p->off = start;
|
101
|
+
p->len = len;
|
102
|
+
|
103
|
+
if ((flags & ZIP_FL_COMPRESSED) == 0) {
|
104
|
+
p->st.size = p->st.comp_size = len;
|
105
|
+
p->st.comp_method = ZIP_CM_STORE;
|
106
|
+
p->st.crc = 0;
|
107
|
+
}
|
108
|
+
|
109
|
+
if ((zs=zip_source_function(za, read_zip, p)) == NULL) {
|
110
|
+
free(p);
|
111
|
+
return NULL;
|
112
|
+
}
|
113
|
+
|
114
|
+
return zs;
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
static ssize_t
|
120
|
+
read_zip(void *state, void *data, size_t len, enum zip_source_cmd cmd)
|
121
|
+
{
|
122
|
+
struct read_zip *z;
|
123
|
+
char b[8192], *buf;
|
124
|
+
int i, n;
|
125
|
+
|
126
|
+
z = (struct read_zip *)state;
|
127
|
+
buf = (char *)data;
|
128
|
+
|
129
|
+
switch (cmd) {
|
130
|
+
case ZIP_SOURCE_OPEN:
|
131
|
+
for (n=0; n<z->off; n+= i) {
|
132
|
+
i = (z->off-n > sizeof(b) ? sizeof(b) : z->off-n);
|
133
|
+
if ((i=zip_fread(z->zf, b, i)) < 0) {
|
134
|
+
zip_fclose(z->zf);
|
135
|
+
z->zf = NULL;
|
136
|
+
return -1;
|
137
|
+
}
|
138
|
+
}
|
139
|
+
return 0;
|
140
|
+
|
141
|
+
case ZIP_SOURCE_READ:
|
142
|
+
if (z->len != -1)
|
143
|
+
n = len > z->len ? z->len : len;
|
144
|
+
else
|
145
|
+
n = len;
|
146
|
+
|
147
|
+
|
148
|
+
if ((i=zip_fread(z->zf, buf, n)) < 0)
|
149
|
+
return -1;
|
150
|
+
|
151
|
+
if (z->len != -1)
|
152
|
+
z->len -= i;
|
153
|
+
|
154
|
+
return i;
|
155
|
+
|
156
|
+
case ZIP_SOURCE_CLOSE:
|
157
|
+
return 0;
|
158
|
+
|
159
|
+
case ZIP_SOURCE_STAT:
|
160
|
+
if (len < sizeof(z->st))
|
161
|
+
return -1;
|
162
|
+
len = sizeof(z->st);
|
163
|
+
|
164
|
+
memcpy(data, &z->st, len);
|
165
|
+
return len;
|
166
|
+
|
167
|
+
case ZIP_SOURCE_ERROR:
|
168
|
+
{
|
169
|
+
int *e;
|
170
|
+
|
171
|
+
if (len < sizeof(int)*2)
|
172
|
+
return -1;
|
173
|
+
|
174
|
+
e = (int *)data;
|
175
|
+
zip_file_error_get(z->zf, e, e+1);
|
176
|
+
}
|
177
|
+
return sizeof(int)*2;
|
178
|
+
|
179
|
+
case ZIP_SOURCE_FREE:
|
180
|
+
zip_fclose(z->zf);
|
181
|
+
free(z);
|
182
|
+
return 0;
|
183
|
+
|
184
|
+
default:
|
185
|
+
;
|
186
|
+
}
|
187
|
+
|
188
|
+
return -1;
|
189
|
+
}
|
data/ext/zip_stat.c
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
/*
|
2
|
+
$NiH: zip_stat.c,v 1.2 2004/04/14 14:01:28 dillo Exp $
|
3
|
+
|
4
|
+
zip_stat.c -- get information about file by name
|
5
|
+
Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
|
6
|
+
|
7
|
+
This file is part of libzip, a library to manipulate ZIP archives.
|
8
|
+
The authors can be contacted at <nih@giga.or.at>
|
9
|
+
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
11
|
+
modification, are permitted provided that the following conditions
|
12
|
+
are met:
|
13
|
+
1. Redistributions of source code must retain the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer.
|
15
|
+
2. Redistributions in binary form must reproduce the above copyright
|
16
|
+
notice, this list of conditions and the following disclaimer in
|
17
|
+
the documentation and/or other materials provided with the
|
18
|
+
distribution.
|
19
|
+
3. The names of the authors may not be used to endorse or promote
|
20
|
+
products derived from this software without specific prior
|
21
|
+
written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
24
|
+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
27
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
28
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
29
|
+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
31
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
32
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
33
|
+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
#include "zip.h"
|
39
|
+
#include "zipint.h"
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
int
|
44
|
+
zip_stat(struct zip *za, const char *fname, int flags, struct zip_stat *st)
|
45
|
+
{
|
46
|
+
int idx;
|
47
|
+
|
48
|
+
if ((idx=zip_name_locate(za, fname, flags)) < 0)
|
49
|
+
return -1;
|
50
|
+
|
51
|
+
return zip_stat_index(za, idx, flags, st);
|
52
|
+
}
|
@@ -0,0 +1,93 @@
|
|
1
|
+
/*
|
2
|
+
$NiH: zip_stat_index.c,v 1.10 2006/04/24 14:04:19 dillo Exp $
|
3
|
+
|
4
|
+
zip_stat_index.c -- get information about file by index
|
5
|
+
Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner
|
6
|
+
|
7
|
+
This file is part of libzip, a library to manipulate ZIP archives.
|
8
|
+
The authors can be contacted at <nih@giga.or.at>
|
9
|
+
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
11
|
+
modification, are permitted provided that the following conditions
|
12
|
+
are met:
|
13
|
+
1. Redistributions of source code must retain the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer.
|
15
|
+
2. Redistributions in binary form must reproduce the above copyright
|
16
|
+
notice, this list of conditions and the following disclaimer in
|
17
|
+
the documentation and/or other materials provided with the
|
18
|
+
distribution.
|
19
|
+
3. The names of the authors may not be used to endorse or promote
|
20
|
+
products derived from this software without specific prior
|
21
|
+
written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
24
|
+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
27
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
28
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
29
|
+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
31
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
32
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
33
|
+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
#include "zip.h"
|
39
|
+
#include "zipint.h"
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
int
|
44
|
+
zip_stat_index(struct zip *za, int index, int flags, struct zip_stat *st)
|
45
|
+
{
|
46
|
+
const char *name;
|
47
|
+
|
48
|
+
if (index < 0 || index >= za->nentry) {
|
49
|
+
_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
|
50
|
+
return -1;
|
51
|
+
}
|
52
|
+
|
53
|
+
if ((name=zip_get_name(za, index, flags)) == NULL)
|
54
|
+
return -1;
|
55
|
+
|
56
|
+
|
57
|
+
if ((flags & ZIP_FL_UNCHANGED) == 0
|
58
|
+
&& ZIP_ENTRY_DATA_CHANGED(za->entry+index)) {
|
59
|
+
if (za->entry[index].source->f(za->entry[index].source->ud,
|
60
|
+
st, sizeof(*st), ZIP_SOURCE_STAT) < 0) {
|
61
|
+
_zip_error_set(&za->error, ZIP_ER_CHANGED, 0);
|
62
|
+
return -1;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
else {
|
66
|
+
if (za->cdir == NULL || index >= za->cdir->nentry) {
|
67
|
+
_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
|
68
|
+
return -1;
|
69
|
+
}
|
70
|
+
|
71
|
+
st->crc = za->cdir->entry[index].crc;
|
72
|
+
st->size = za->cdir->entry[index].uncomp_size;
|
73
|
+
st->mtime = za->cdir->entry[index].last_mod;
|
74
|
+
st->comp_size = za->cdir->entry[index].comp_size;
|
75
|
+
st->comp_method = za->cdir->entry[index].comp_method;
|
76
|
+
if (za->cdir->entry[index].bitflags & ZIP_GPBF_ENCRYPTED) {
|
77
|
+
if (za->cdir->entry[index].bitflags & ZIP_GPBF_STRONG_ENCRYPTION) {
|
78
|
+
/* XXX */
|
79
|
+
st->encryption_method = ZIP_EM_UNKNOWN;
|
80
|
+
}
|
81
|
+
else
|
82
|
+
st->encryption_method = ZIP_EM_TRAD_PKWARE;
|
83
|
+
}
|
84
|
+
else
|
85
|
+
st->encryption_method = ZIP_EM_NONE;
|
86
|
+
/* st->bitflags = za->cdir->entry[index].bitflags; */
|
87
|
+
}
|
88
|
+
|
89
|
+
st->index = index;
|
90
|
+
st->name = name;
|
91
|
+
|
92
|
+
return 0;
|
93
|
+
}
|
data/ext/zip_stat_init.c
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
/*
|
2
|
+
$NiH$
|
3
|
+
|
4
|
+
zip_stat_init.c -- initialize struct zip_stat.
|
5
|
+
Copyright (C) 2006 Dieter Baron and Thomas Klausner
|
6
|
+
|
7
|
+
This file is part of libzip, a library to manipulate ZIP archives.
|
8
|
+
The authors can be contacted at <nih@giga.or.at>
|
9
|
+
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
11
|
+
modification, are permitted provided that the following conditions
|
12
|
+
are met:
|
13
|
+
1. Redistributions of source code must retain the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer.
|
15
|
+
2. Redistributions in binary form must reproduce the above copyright
|
16
|
+
notice, this list of conditions and the following disclaimer in
|
17
|
+
the documentation and/or other materials provided with the
|
18
|
+
distribution.
|
19
|
+
3. The names of the authors may not be used to endorse or promote
|
20
|
+
products derived from this software without specific prior
|
21
|
+
written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
24
|
+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
27
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
28
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
29
|
+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
31
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
32
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
33
|
+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
#include "zipint.h"
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
void
|
43
|
+
zip_stat_init(struct zip_stat *st)
|
44
|
+
{
|
45
|
+
st->name = NULL;
|
46
|
+
st->index = -1;
|
47
|
+
st->crc = 0;
|
48
|
+
st->mtime = (time_t)-1;
|
49
|
+
st->size = -1;
|
50
|
+
st->comp_size = -1;
|
51
|
+
st->comp_method = ZIP_CM_STORE;
|
52
|
+
st->encryption_method = ZIP_EM_NONE;
|
53
|
+
}
|
data/ext/zip_strerror.c
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
/*
|
2
|
+
$NiH$
|
3
|
+
|
4
|
+
zip_sterror.c -- get string representation of zip error
|
5
|
+
Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
|
6
|
+
|
7
|
+
This file is part of libzip, a library to manipulate ZIP archives.
|
8
|
+
The authors can be contacted at <nih@giga.or.at>
|
9
|
+
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
11
|
+
modification, are permitted provided that the following conditions
|
12
|
+
are met:
|
13
|
+
1. Redistributions of source code must retain the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer.
|
15
|
+
2. Redistributions in binary form must reproduce the above copyright
|
16
|
+
notice, this list of conditions and the following disclaimer in
|
17
|
+
the documentation and/or other materials provided with the
|
18
|
+
distribution.
|
19
|
+
3. The names of the authors may not be used to endorse or promote
|
20
|
+
products derived from this software without specific prior
|
21
|
+
written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
24
|
+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
27
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
28
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
29
|
+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
31
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
32
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
33
|
+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
#include "zip.h"
|
39
|
+
#include "zipint.h"
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
const char *
|
44
|
+
zip_strerror(struct zip *za)
|
45
|
+
{
|
46
|
+
return _zip_error_strerror(&za->error);
|
47
|
+
}
|
data/ext/zip_unchange.c
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
/*
|
2
|
+
$NiH: zip_unchange.c,v 1.18 2006/04/09 19:05:47 wiz Exp $
|
3
|
+
|
4
|
+
zip_unchange.c -- undo changes to file in zip archive
|
5
|
+
Copyright (C) 1999, 2004, 2006 Dieter Baron and Thomas Klausner
|
6
|
+
|
7
|
+
This file is part of libzip, a library to manipulate ZIP archives.
|
8
|
+
The authors can be contacted at <nih@giga.or.at>
|
9
|
+
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
11
|
+
modification, are permitted provided that the following conditions
|
12
|
+
are met:
|
13
|
+
1. Redistributions of source code must retain the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer.
|
15
|
+
2. Redistributions in binary form must reproduce the above copyright
|
16
|
+
notice, this list of conditions and the following disclaimer in
|
17
|
+
the documentation and/or other materials provided with the
|
18
|
+
distribution.
|
19
|
+
3. The names of the authors may not be used to endorse or promote
|
20
|
+
products derived from this software without specific prior
|
21
|
+
written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
24
|
+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
27
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
28
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
29
|
+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
31
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
32
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
33
|
+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
#include <stdlib.h>
|
39
|
+
#include "zip.h"
|
40
|
+
#include "zipint.h"
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
int
|
45
|
+
zip_unchange(struct zip *za, int idx)
|
46
|
+
{
|
47
|
+
return _zip_unchange(za, idx, 0);
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
int
|
53
|
+
_zip_unchange(struct zip *za, int idx, int allow_duplicates)
|
54
|
+
{
|
55
|
+
int i;
|
56
|
+
|
57
|
+
if (idx < 0 || idx >= za->nentry) {
|
58
|
+
_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
|
59
|
+
return -1;
|
60
|
+
}
|
61
|
+
|
62
|
+
if (za->entry[idx].ch_filename) {
|
63
|
+
if (!allow_duplicates) {
|
64
|
+
i = _zip_name_locate(za,
|
65
|
+
_zip_get_name(za, idx, ZIP_FL_UNCHANGED, NULL),
|
66
|
+
0, NULL);
|
67
|
+
if (i != -1 && i != idx) {
|
68
|
+
_zip_error_set(&za->error, ZIP_ER_EXISTS, 0);
|
69
|
+
return -1;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
free(za->entry[idx].ch_filename);
|
74
|
+
za->entry[idx].ch_filename = NULL;
|
75
|
+
}
|
76
|
+
|
77
|
+
free(za->entry[idx].ch_comment);
|
78
|
+
za->entry[idx].ch_comment = NULL;
|
79
|
+
za->entry[idx].ch_comment_len = -1;
|
80
|
+
|
81
|
+
_zip_unchange_data(za->entry+idx);
|
82
|
+
|
83
|
+
return 0;
|
84
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
/*
|
2
|
+
$NiH: zip_unchange_all.c,v 1.9 2006/04/23 00:40:48 wiz Exp $
|
3
|
+
|
4
|
+
zip_unchange.c -- undo changes to all files in zip archive
|
5
|
+
Copyright (C) 1999, 2006 Dieter Baron and Thomas Klausner
|
6
|
+
|
7
|
+
This file is part of libzip, a library to manipulate ZIP archives.
|
8
|
+
The authors can be contacted at <nih@giga.or.at>
|
9
|
+
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
11
|
+
modification, are permitted provided that the following conditions
|
12
|
+
are met:
|
13
|
+
1. Redistributions of source code must retain the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer.
|
15
|
+
2. Redistributions in binary form must reproduce the above copyright
|
16
|
+
notice, this list of conditions and the following disclaimer in
|
17
|
+
the documentation and/or other materials provided with the
|
18
|
+
distribution.
|
19
|
+
3. The names of the authors may not be used to endorse or promote
|
20
|
+
products derived from this software without specific prior
|
21
|
+
written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
24
|
+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
27
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
28
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
29
|
+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
31
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
32
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
33
|
+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
#include <stdlib.h>
|
39
|
+
#include "zip.h"
|
40
|
+
#include "zipint.h"
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
int
|
45
|
+
zip_unchange_all(struct zip *za)
|
46
|
+
{
|
47
|
+
int ret, i;
|
48
|
+
|
49
|
+
ret = 0;
|
50
|
+
for (i=0; i<za->nentry; i++)
|
51
|
+
ret |= _zip_unchange(za, i, 1);
|
52
|
+
|
53
|
+
ret |= zip_unchange_archive(za);
|
54
|
+
|
55
|
+
return ret;
|
56
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
/*
|
2
|
+
$NiH: zip_unchange_all.c,v 1.9 2006/04/23 00:40:48 wiz Exp $
|
3
|
+
|
4
|
+
zip_unchange_archive.c -- undo global changes to ZIP archive
|
5
|
+
Copyright (C) 2006 Dieter Baron and Thomas Klausner
|
6
|
+
|
7
|
+
This file is part of libzip, a library to manipulate ZIP archives.
|
8
|
+
The authors can be contacted at <nih@giga.or.at>
|
9
|
+
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
11
|
+
modification, are permitted provided that the following conditions
|
12
|
+
are met:
|
13
|
+
1. Redistributions of source code must retain the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer.
|
15
|
+
2. Redistributions in binary form must reproduce the above copyright
|
16
|
+
notice, this list of conditions and the following disclaimer in
|
17
|
+
the documentation and/or other materials provided with the
|
18
|
+
distribution.
|
19
|
+
3. The names of the authors may not be used to endorse or promote
|
20
|
+
products derived from this software without specific prior
|
21
|
+
written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
24
|
+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
27
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
28
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
29
|
+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
31
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
32
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
33
|
+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
#include <stdlib.h>
|
39
|
+
#include "zip.h"
|
40
|
+
#include "zipint.h"
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
int
|
45
|
+
zip_unchange_archive(struct zip *za)
|
46
|
+
{
|
47
|
+
free(za->ch_comment);
|
48
|
+
za->ch_comment = NULL;
|
49
|
+
za->ch_comment_len = -1;
|
50
|
+
|
51
|
+
return 0;
|
52
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/*
|
2
|
+
$NiH: zip_unchange_data.c,v 1.14 2004/11/30 23:02:47 wiz Exp $
|
3
|
+
|
4
|
+
zip_unchange_data.c -- undo helper function
|
5
|
+
Copyright (C) 1999, 2004 Dieter Baron and Thomas Klausner
|
6
|
+
|
7
|
+
This file is part of libzip, a library to manipulate ZIP archives.
|
8
|
+
The authors can be contacted at <nih@giga.or.at>
|
9
|
+
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
11
|
+
modification, are permitted provided that the following conditions
|
12
|
+
are met:
|
13
|
+
1. Redistributions of source code must retain the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer.
|
15
|
+
2. Redistributions in binary form must reproduce the above copyright
|
16
|
+
notice, this list of conditions and the following disclaimer in
|
17
|
+
the documentation and/or other materials provided with the
|
18
|
+
distribution.
|
19
|
+
3. The names of the authors may not be used to endorse or promote
|
20
|
+
products derived from this software without specific prior
|
21
|
+
written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
24
|
+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
27
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
28
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
29
|
+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
31
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
32
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
33
|
+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
#include <stdlib.h>
|
39
|
+
|
40
|
+
#include "zipint.h"
|
41
|
+
|
42
|
+
void
|
43
|
+
_zip_unchange_data(struct zip_entry *ze)
|
44
|
+
{
|
45
|
+
if (ze->source) {
|
46
|
+
(void)ze->source->f(ze->source->ud, NULL, 0, ZIP_SOURCE_FREE);
|
47
|
+
free(ze->source);
|
48
|
+
ze->source = NULL;
|
49
|
+
}
|
50
|
+
|
51
|
+
ze->state = ze->ch_filename ? ZIP_ST_RENAMED : ZIP_ST_UNCHANGED;
|
52
|
+
}
|
53
|
+
|