zipruby 0.2.5 → 0.2.6
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 +17 -2
- data/ext/foo.txt +315 -0
- data/ext/{libzip.vcproj.IBM-94B792EFFD1.sugawara.user → libzip.vcproj.IBM-62EEBFAE94C.sugawara.user} +2 -2
- data/ext/zipruby.h +1 -1
- data/ext/zipruby_archive.c +240 -42
- data/ext/zipruby_archive.c.r112 +978 -0
- data/ext/zipruby_archive.h +4 -1
- data/zipruby.c +240 -42
- metadata +6 -4
data/README.txt
CHANGED
@@ -116,10 +116,17 @@ https://rubyforge.org/frs/?group_id=6124
|
|
116
116
|
open('bar.txt') do |f|
|
117
117
|
ar.replace_filep(1, f)
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
|
+
# if commit changes
|
121
|
+
# ar.commit
|
122
|
+
|
120
123
|
# replace file in zip archive with buffer
|
121
124
|
ar.replace_buffer(2, 'Hello, world!')
|
122
|
-
|
125
|
+
# or
|
126
|
+
# ar.replace_buffer('entry name', 'Hello, world!')
|
127
|
+
# if ignore case distinctions
|
128
|
+
# ar.replace_buffer('entry name', 'Hello, world!', Zip::FL_NOCASE)
|
129
|
+
|
123
130
|
# add or replace file in zip archive
|
124
131
|
ar.add_or_replace_file(3, 'foo.txt')
|
125
132
|
end
|
@@ -146,9 +153,17 @@ https://rubyforge.org/frs/?group_id=6124
|
|
146
153
|
|
147
154
|
# encrypt
|
148
155
|
Zip::Archive.encrypt('filename.zip', 'password')
|
156
|
+
# or
|
157
|
+
# Zip::Archive.encrypt('filename.zip') do |ar|
|
158
|
+
# ar.encrypt('filename.zip', 'password')
|
159
|
+
# end
|
149
160
|
|
150
161
|
# decrypt
|
151
162
|
Zip::Archive.decrypt('filename.zip', 'password')
|
163
|
+
# or
|
164
|
+
# Zip::Archive.decrypt('filename.zip') do |ar|
|
165
|
+
# ar.decrypt('filename.zip', 'password')
|
166
|
+
# end
|
152
167
|
|
153
168
|
== License
|
154
169
|
Copyright (c) 2008 SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
|
data/ext/foo.txt
ADDED
@@ -0,0 +1,315 @@
|
|
1
|
+
--- zipruby_archive.c.r112 2008-07-13 16:12:21.234375000 +0900
|
2
|
+
+++ zipruby_archive.c 2008-07-13 16:09:45.640625000 +0900
|
3
|
+
@@ -21,15 +21,15 @@ static VALUE zipruby_archive_add_buffer(
|
4
|
+
static VALUE zipruby_archive_add_file(int argc, VALUE *argv, VALUE self);
|
5
|
+
static VALUE zipruby_archive_add_filep(int argc, VALUE *argv, VALUE self);
|
6
|
+
static VALUE zipruby_archive_add_function(int argc, VALUE *argv, VALUE self);
|
7
|
+
-static VALUE zipruby_archive_replace_buffer(VALUE self, VALUE index, VALUE source);
|
8
|
+
-static VALUE zipruby_archive_replace_file(VALUE self, VALUE index, VALUE fname);
|
9
|
+
+static VALUE zipruby_archive_replace_buffer(int argc, VALUE *argv, VALUE self);
|
10
|
+
+static VALUE zipruby_archive_replace_file(int argc, VALUE* argv, VALUE self);
|
11
|
+
static VALUE zipruby_archive_replace_filep(VALUE self, VALUE index, VALUE file);
|
12
|
+
static VALUE zipruby_archive_replace_function(int argc, VALUE *argv, VALUE self);
|
13
|
+
-static VALUE zipruby_archive_add_or_replace_buffer(VALUE self, VALUE name, VALUE source);
|
14
|
+
+static VALUE zipruby_archive_add_or_replace_buffer(int argc, VALUE *argv, VALUE self);
|
15
|
+
static VALUE zipruby_archive_add_or_replace_file(int argc, VALUE *argv, VALUE self);
|
16
|
+
static VALUE zipruby_archive_add_or_replace_filep(int argc, VALUE *argv, VALUE self);
|
17
|
+
static VALUE zipruby_archive_add_or_replace_function(int argc, VALUE *argv, VALUE self);
|
18
|
+
-static VALUE zipruby_archive_update(VALUE self, VALUE srcarchive);
|
19
|
+
+static VALUE zipruby_archive_update(int argc, VALUE *argv, VALUE self);
|
20
|
+
static VALUE zipruby_archive_get_comment(int argc, VALUE *argv, VALUE self);
|
21
|
+
static VALUE zipruby_archive_set_comment(VALUE self, VALUE comment);
|
22
|
+
static VALUE zipruby_archive_locate_name(int argc, VALUE *argv, VALUE self);
|
23
|
+
@@ -65,15 +65,15 @@ void Init_zipruby_archive() {
|
24
|
+
rb_define_method(Archive, "add_file", zipruby_archive_add_file, -1);
|
25
|
+
rb_define_method(Archive, "add_filep", zipruby_archive_add_filep, -1);
|
26
|
+
rb_define_method(Archive, "add", zipruby_archive_add_function, -1);
|
27
|
+
- rb_define_method(Archive, "replace_buffer", zipruby_archive_replace_buffer, 2);
|
28
|
+
- rb_define_method(Archive, "replace_file", zipruby_archive_replace_file, 2);
|
29
|
+
+ rb_define_method(Archive, "replace_buffer", zipruby_archive_replace_buffer, -1);
|
30
|
+
+ rb_define_method(Archive, "replace_file", zipruby_archive_replace_file, -1);
|
31
|
+
rb_define_method(Archive, "replace_filep", zipruby_archive_replace_filep, 2);
|
32
|
+
rb_define_method(Archive, "replace", zipruby_archive_replace_function, -1);
|
33
|
+
- rb_define_method(Archive, "add_or_replace_buffer", zipruby_archive_add_or_replace_buffer, 2);
|
34
|
+
+ rb_define_method(Archive, "add_or_replace_buffer", zipruby_archive_add_or_replace_buffer, -1);
|
35
|
+
rb_define_method(Archive, "add_or_replace_file", zipruby_archive_add_or_replace_file, -1);
|
36
|
+
rb_define_method(Archive, "add_or_replace_filep", zipruby_archive_add_or_replace_filep, -1);
|
37
|
+
rb_define_method(Archive, "add_or_replace", zipruby_archive_add_or_replace_function, -1);
|
38
|
+
- rb_define_method(Archive, "update", zipruby_archive_update, 1);
|
39
|
+
+ rb_define_method(Archive, "update", zipruby_archive_update, -1);
|
40
|
+
rb_define_method(Archive, "<<", zipruby_archive_add_filep, -1);
|
41
|
+
rb_define_method(Archive, "get_comment", zipruby_archive_get_comment, -1);
|
42
|
+
rb_define_method(Archive, "comment", zipruby_archive_get_comment, -1);
|
43
|
+
@@ -320,24 +320,31 @@ static VALUE zipruby_archive_add_buffer(
|
44
|
+
}
|
45
|
+
|
46
|
+
/* */
|
47
|
+
-static VALUE zipruby_archive_replace_buffer(VALUE self, VALUE index, VALUE source) {
|
48
|
+
+static VALUE zipruby_archive_replace_buffer(int argc, VALUE *argv, VALUE self) {
|
49
|
+
struct zipruby_archive *p_archive;
|
50
|
+
struct zip_source *zsource;
|
51
|
+
- int i_index;
|
52
|
+
+ VALUE index, source, flags;
|
53
|
+
+ int i_index, i_flags = 0;
|
54
|
+
char *data;
|
55
|
+
off_t len;
|
56
|
+
|
57
|
+
+ rb_scan_args(argc, argv, "21", &index, &source, &flags);
|
58
|
+
+
|
59
|
+
if (!rb_obj_is_instance_of(index, rb_cString) && !rb_obj_is_instance_of(index, rb_cFixnum)) {
|
60
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or String)", rb_class2name(CLASS_OF(index)));
|
61
|
+
}
|
62
|
+
|
63
|
+
+ if (!NIL_P(flags)) {
|
64
|
+
+ i_flags = NUM2INT(flags);
|
65
|
+
+ }
|
66
|
+
+
|
67
|
+
Check_Type(source, T_STRING);
|
68
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
69
|
+
Check_Archive(p_archive);
|
70
|
+
|
71
|
+
if (rb_obj_is_instance_of(index, rb_cFixnum)) {
|
72
|
+
i_index = NUM2INT(index);
|
73
|
+
- } else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index), ZIP_FL_NOCASE)) == -1) {
|
74
|
+
+ } else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index), i_flags)) == -1) {
|
75
|
+
rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", StringValuePtr(index));
|
76
|
+
}
|
77
|
+
|
78
|
+
@@ -365,18 +372,26 @@ static VALUE zipruby_archive_replace_buf
|
79
|
+
}
|
80
|
+
|
81
|
+
/* */
|
82
|
+
-static VALUE zipruby_archive_add_or_replace_buffer(VALUE self, VALUE name, VALUE source) {
|
83
|
+
+static VALUE zipruby_archive_add_or_replace_buffer(int argc, VALUE *argv, VALUE self) {
|
84
|
+
struct zipruby_archive *p_archive;
|
85
|
+
- int index;
|
86
|
+
+ VALUE name, source, flags;
|
87
|
+
+ int index, i_flags = 0;
|
88
|
+
+
|
89
|
+
+ rb_scan_args(argc, argv, "21", &name, &source, &flags);
|
90
|
+
+
|
91
|
+
+ if (!NIL_P(flags)) {
|
92
|
+
+ i_flags = NUM2INT(flags);
|
93
|
+
+ }
|
94
|
+
|
95
|
+
Check_Type(name, T_STRING);
|
96
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
97
|
+
Check_Archive(p_archive);
|
98
|
+
|
99
|
+
- index = zip_name_locate(p_archive->archive, StringValuePtr(name), ZIP_FL_NOCASE);
|
100
|
+
+ index = zip_name_locate(p_archive->archive, StringValuePtr(name), i_flags);
|
101
|
+
|
102
|
+
if (index >= 0) {
|
103
|
+
- return zipruby_archive_replace_buffer(self, INT2NUM(index), source);
|
104
|
+
+ VALUE _args[] = { INT2NUM(index), source };
|
105
|
+
+ return zipruby_archive_replace_buffer(2, _args, self);
|
106
|
+
} else {
|
107
|
+
return zipruby_archive_add_buffer(self, name, source);
|
108
|
+
}
|
109
|
+
@@ -420,22 +435,29 @@ static VALUE zipruby_archive_add_file(in
|
110
|
+
}
|
111
|
+
|
112
|
+
/* */
|
113
|
+
-static VALUE zipruby_archive_replace_file(VALUE self, VALUE index, VALUE fname) {
|
114
|
+
+static VALUE zipruby_archive_replace_file(int argc, VALUE* argv, VALUE self) {
|
115
|
+
struct zipruby_archive *p_archive;
|
116
|
+
struct zip_source *zsource;
|
117
|
+
- int i_index;
|
118
|
+
+ VALUE index, fname, flags;
|
119
|
+
+ int i_index, i_flags = 0;
|
120
|
+
+
|
121
|
+
+ rb_scan_args(argc, argv, "21", &index, &fname, &flags);
|
122
|
+
|
123
|
+
if (!rb_obj_is_instance_of(index, rb_cString) && !rb_obj_is_instance_of(index, rb_cFixnum)) {
|
124
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or String)", rb_class2name(CLASS_OF(index)));
|
125
|
+
}
|
126
|
+
|
127
|
+
+ if (!NIL_P(flags)) {
|
128
|
+
+ i_flags = NUM2INT(flags);
|
129
|
+
+ }
|
130
|
+
+
|
131
|
+
Check_Type(fname, T_STRING);
|
132
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
133
|
+
Check_Archive(p_archive);
|
134
|
+
|
135
|
+
if (rb_obj_is_instance_of(index, rb_cFixnum)) {
|
136
|
+
i_index = NUM2INT(index);
|
137
|
+
- } else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index), ZIP_FL_NOCASE)) == -1) {
|
138
|
+
+ } else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index), i_flags)) == -1) {
|
139
|
+
rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", StringValuePtr(index));
|
140
|
+
}
|
141
|
+
|
142
|
+
@@ -455,11 +477,16 @@ static VALUE zipruby_archive_replace_fil
|
143
|
+
|
144
|
+
/* */
|
145
|
+
static VALUE zipruby_archive_add_or_replace_file(int argc, VALUE *argv, VALUE self) {
|
146
|
+
- VALUE name, fname;
|
147
|
+
+ VALUE name, fname, flags;
|
148
|
+
struct zipruby_archive *p_archive;
|
149
|
+
- int index;
|
150
|
+
+ int index, i_flags = 0;
|
151
|
+
|
152
|
+
- rb_scan_args(argc, argv, "11", &name, &fname);
|
153
|
+
+ rb_scan_args(argc, argv, "12", &name, &fname, &flags);
|
154
|
+
+
|
155
|
+
+ if (NIL_P(flags) && FIXNUM_P(fname)) {
|
156
|
+
+ flags = fname;
|
157
|
+
+ fname = Qnil;
|
158
|
+
+ }
|
159
|
+
|
160
|
+
if (NIL_P(fname)) {
|
161
|
+
fname = name;
|
162
|
+
@@ -472,16 +499,22 @@ static VALUE zipruby_archive_add_or_repl
|
163
|
+
name = rb_funcall(rb_cFile, rb_intern("basename"), 1, fname);
|
164
|
+
}
|
165
|
+
|
166
|
+
+ if (!NIL_P(flags)) {
|
167
|
+
+ i_flags = NUM2INT(flags);
|
168
|
+
+ }
|
169
|
+
+
|
170
|
+
Check_Type(name, T_STRING);
|
171
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
172
|
+
Check_Archive(p_archive);
|
173
|
+
|
174
|
+
- index = zip_name_locate(p_archive->archive, StringValuePtr(name), ZIP_FL_NOCASE);
|
175
|
+
+ index = zip_name_locate(p_archive->archive, StringValuePtr(name), i_flags);
|
176
|
+
|
177
|
+
if (index >= 0) {
|
178
|
+
- return zipruby_archive_replace_file(self, INT2NUM(index), fname);
|
179
|
+
+ VALUE _args[] = { INT2NUM(index), fname };
|
180
|
+
+ return zipruby_archive_replace_file(2, _args, self);
|
181
|
+
} else {
|
182
|
+
- return zipruby_archive_add_file(argc, argv, self);
|
183
|
+
+ VALUE _args[] = { name, fname };
|
184
|
+
+ return zipruby_archive_add_file(2, _args, self);
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
@@ -510,20 +543,28 @@ static VALUE zipruby_archive_add_filep(i
|
189
|
+
/* */
|
190
|
+
static VALUE zipruby_archive_replace_filep(VALUE self, VALUE index, VALUE file) {
|
191
|
+
VALUE source;
|
192
|
+
+ VALUE _args[2];
|
193
|
+
|
194
|
+
Check_Type(file, T_FILE);
|
195
|
+
source = rb_funcall(file, rb_intern("read"), 0);
|
196
|
+
|
197
|
+
- return zipruby_archive_replace_buffer(self, index, source);
|
198
|
+
+ _args[0] = index;
|
199
|
+
+ _args[1] = source;
|
200
|
+
+ return zipruby_archive_replace_buffer(2, _args, self);
|
201
|
+
}
|
202
|
+
|
203
|
+
/* */
|
204
|
+
static VALUE zipruby_archive_add_or_replace_filep(int argc, VALUE *argv, VALUE self) {
|
205
|
+
- VALUE name, file;
|
206
|
+
+ VALUE name, file, flags;
|
207
|
+
struct zipruby_archive *p_archive;
|
208
|
+
- int index;
|
209
|
+
+ int index, i_flags = 0;
|
210
|
+
|
211
|
+
- rb_scan_args(argc, argv, "11", &name, &file);
|
212
|
+
+ rb_scan_args(argc, argv, "12", &name, &file, &flags);
|
213
|
+
+
|
214
|
+
+ if (NIL_P(flags) && FIXNUM_P(file)) {
|
215
|
+
+ flags = file;
|
216
|
+
+ file = Qnil;
|
217
|
+
+ }
|
218
|
+
|
219
|
+
if (NIL_P(file)) {
|
220
|
+
file = name;
|
221
|
+
@@ -536,16 +577,21 @@ static VALUE zipruby_archive_add_or_repl
|
222
|
+
name = rb_funcall(rb_cFile, rb_intern("basename"), 1, rb_funcall(file, rb_intern("path"), 0));
|
223
|
+
}
|
224
|
+
|
225
|
+
+ if (!NIL_P(flags)) {
|
226
|
+
+ i_flags = NUM2INT(flags);
|
227
|
+
+ }
|
228
|
+
+
|
229
|
+
Check_Type(name, T_STRING);
|
230
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
231
|
+
Check_Archive(p_archive);
|
232
|
+
|
233
|
+
- index = zip_name_locate(p_archive->archive, StringValuePtr(name), ZIP_FL_NOCASE);
|
234
|
+
+ index = zip_name_locate(p_archive->archive, StringValuePtr(name), i_flags);
|
235
|
+
|
236
|
+
if (index >= 0) {
|
237
|
+
return zipruby_archive_replace_filep(self, INT2NUM(index), file);
|
238
|
+
} else {
|
239
|
+
- return zipruby_archive_add_filep(argc, argv, self);
|
240
|
+
+ VALUE _args[] = { name, file };
|
241
|
+
+ return zipruby_archive_add_filep(2, _args, self);
|
242
|
+
}
|
243
|
+
}
|
244
|
+
|
245
|
+
@@ -638,34 +684,52 @@ static VALUE zipruby_archive_replace_fun
|
246
|
+
|
247
|
+
/* */
|
248
|
+
static VALUE zipruby_archive_add_or_replace_function(int argc, VALUE *argv, VALUE self) {
|
249
|
+
- VALUE name, mtime;
|
250
|
+
+ VALUE name, mtime, flags;
|
251
|
+
struct zipruby_archive *p_archive;
|
252
|
+
- int index;
|
253
|
+
+ int index, i_flags = 0;
|
254
|
+
+
|
255
|
+
+ rb_scan_args(argc, argv, "12", &name, &mtime, &flags);
|
256
|
+
+
|
257
|
+
+ if (NIL_P(flags) && FIXNUM_P(mtime)) {
|
258
|
+
+ flags = mtime;
|
259
|
+
+ mtime = Qnil;
|
260
|
+
+ }
|
261
|
+
+
|
262
|
+
+ if (!NIL_P(flags)) {
|
263
|
+
+ i_flags = NUM2INT(flags);
|
264
|
+
+ }
|
265
|
+
|
266
|
+
- rb_scan_args(argc, argv, "11", &name, &mtime);
|
267
|
+
Check_Type(name, T_STRING);
|
268
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
269
|
+
Check_Archive(p_archive);
|
270
|
+
|
271
|
+
- index = zip_name_locate(p_archive->archive, StringValuePtr(name), ZIP_FL_NOCASE);
|
272
|
+
+ index = zip_name_locate(p_archive->archive, StringValuePtr(name), i_flags);
|
273
|
+
|
274
|
+
if (index >= 0) {
|
275
|
+
- VALUE args[] = { INT2NUM(index), mtime };
|
276
|
+
- return zipruby_archive_replace_function(2, args, self);
|
277
|
+
+ VALUE _args[] = { INT2NUM(index), mtime };
|
278
|
+
+ return zipruby_archive_replace_function(2, _args, self);
|
279
|
+
} else {
|
280
|
+
- return zipruby_archive_add_function(argc, argv, self);
|
281
|
+
+ VALUE _args[] = { name, mtime };
|
282
|
+
+ return zipruby_archive_add_function(2, _args, self);
|
283
|
+
}
|
284
|
+
}
|
285
|
+
|
286
|
+
/* */
|
287
|
+
-static VALUE zipruby_archive_update(VALUE self, VALUE srcarchive) {
|
288
|
+
+static VALUE zipruby_archive_update(int argc, VALUE *argv, VALUE self) {
|
289
|
+
struct zipruby_archive *p_archive, *p_srcarchive;
|
290
|
+
- int i, num_files;
|
291
|
+
+ VALUE srcarchive, flags;
|
292
|
+
+ int i, num_files, i_flags = 0;
|
293
|
+
+
|
294
|
+
+ rb_scan_args(argc, argv, "11", &srcarchive, &flags);
|
295
|
+
|
296
|
+
if (!rb_obj_is_instance_of(srcarchive, Archive)) {
|
297
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected Zip::Archive)", rb_class2name(CLASS_OF(srcarchive)));
|
298
|
+
}
|
299
|
+
|
300
|
+
+ if (!NIL_P(flags)) {
|
301
|
+
+ i_flags = NUM2INT(flags);
|
302
|
+
+ }
|
303
|
+
+
|
304
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
305
|
+
Check_Archive(p_archive);
|
306
|
+
Data_Get_Struct(srcarchive, struct zipruby_archive, p_srcarchive);
|
307
|
+
@@ -735,7 +799,7 @@ static VALUE zipruby_archive_update(VALU
|
308
|
+
rb_raise(Error, "Update archive failed: %s", zip_strerror(p_srcarchive->archive));
|
309
|
+
}
|
310
|
+
|
311
|
+
- index = zip_name_locate(p_archive->archive, name, ZIP_FL_NOCASE);
|
312
|
+
+ index = zip_name_locate(p_archive->archive, name, i_flags);
|
313
|
+
|
314
|
+
if (index >= 0) {
|
315
|
+
if (zip_replace(p_archive->archive, i, zsource) == -1) {
|
data/ext/{libzip.vcproj.IBM-94B792EFFD1.sugawara.user → libzip.vcproj.IBM-62EEBFAE94C.sugawara.user}
RENAMED
@@ -2,7 +2,7 @@
|
|
2
2
|
<VisualStudioUserFile
|
3
3
|
ProjectType="Visual C++"
|
4
4
|
Version="9.00"
|
5
|
-
ShowAllFiles="
|
5
|
+
ShowAllFiles="true"
|
6
6
|
>
|
7
7
|
<Configurations>
|
8
8
|
<Configuration
|
@@ -15,7 +15,7 @@
|
|
15
15
|
Attach="false"
|
16
16
|
DebuggerType="3"
|
17
17
|
Remote="1"
|
18
|
-
RemoteMachine="IBM-
|
18
|
+
RemoteMachine="IBM-62EEBFAE94C"
|
19
19
|
RemoteCommand=""
|
20
20
|
HttpUrl=""
|
21
21
|
PDBPath=""
|
data/ext/zipruby.h
CHANGED
data/ext/zipruby_archive.c
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
#include "rubyio.h"
|
9
9
|
|
10
10
|
static VALUE zipruby_archive_alloc(VALUE klass);
|
11
|
+
static void zipruby_archive_mark(struct zipruby_archive *p);
|
11
12
|
static void zipruby_archive_free(struct zipruby_archive *p);
|
12
13
|
static VALUE zipruby_archive_s_open(int argc, VALUE *argv, VALUE self);
|
13
14
|
static VALUE zipruby_archive_s_decrypt(VALUE self, VALUE path, VALUE password);
|
@@ -21,15 +22,15 @@ static VALUE zipruby_archive_add_buffer(VALUE self, VALUE name, VALUE source);
|
|
21
22
|
static VALUE zipruby_archive_add_file(int argc, VALUE *argv, VALUE self);
|
22
23
|
static VALUE zipruby_archive_add_filep(int argc, VALUE *argv, VALUE self);
|
23
24
|
static VALUE zipruby_archive_add_function(int argc, VALUE *argv, VALUE self);
|
24
|
-
static VALUE zipruby_archive_replace_buffer(
|
25
|
-
static VALUE zipruby_archive_replace_file(
|
25
|
+
static VALUE zipruby_archive_replace_buffer(int argc, VALUE *argv, VALUE self);
|
26
|
+
static VALUE zipruby_archive_replace_file(int argc, VALUE* argv, VALUE self);
|
26
27
|
static VALUE zipruby_archive_replace_filep(VALUE self, VALUE index, VALUE file);
|
27
28
|
static VALUE zipruby_archive_replace_function(int argc, VALUE *argv, VALUE self);
|
28
|
-
static VALUE zipruby_archive_add_or_replace_buffer(
|
29
|
+
static VALUE zipruby_archive_add_or_replace_buffer(int argc, VALUE *argv, VALUE self);
|
29
30
|
static VALUE zipruby_archive_add_or_replace_file(int argc, VALUE *argv, VALUE self);
|
30
31
|
static VALUE zipruby_archive_add_or_replace_filep(int argc, VALUE *argv, VALUE self);
|
31
32
|
static VALUE zipruby_archive_add_or_replace_function(int argc, VALUE *argv, VALUE self);
|
32
|
-
static VALUE zipruby_archive_update(VALUE
|
33
|
+
static VALUE zipruby_archive_update(int argc, VALUE *argv, VALUE self);
|
33
34
|
static VALUE zipruby_archive_get_comment(int argc, VALUE *argv, VALUE self);
|
34
35
|
static VALUE zipruby_archive_set_comment(VALUE self, VALUE comment);
|
35
36
|
static VALUE zipruby_archive_locate_name(int argc, VALUE *argv, VALUE self);
|
@@ -42,6 +43,10 @@ static VALUE zipruby_archive_funchange_all(VALUE self);
|
|
42
43
|
static VALUE zipruby_archive_unchange(VALUE self);
|
43
44
|
static VALUE zipruby_archive_revert(VALUE self);
|
44
45
|
static VALUE zipruby_archive_each(VALUE self);
|
46
|
+
static VALUE zipruby_archive_commit(VALUE self);
|
47
|
+
static VALUE zipruby_archive_is_open(VALUE self);
|
48
|
+
static VALUE zipruby_archive_decrypt(VALUE self, VALUE password);
|
49
|
+
static VALUE zipruby_archive_encrypt(VALUE self, VALUE password);
|
45
50
|
|
46
51
|
extern VALUE Zip;
|
47
52
|
VALUE Archive;
|
@@ -65,15 +70,15 @@ void Init_zipruby_archive() {
|
|
65
70
|
rb_define_method(Archive, "add_file", zipruby_archive_add_file, -1);
|
66
71
|
rb_define_method(Archive, "add_filep", zipruby_archive_add_filep, -1);
|
67
72
|
rb_define_method(Archive, "add", zipruby_archive_add_function, -1);
|
68
|
-
rb_define_method(Archive, "replace_buffer", zipruby_archive_replace_buffer,
|
69
|
-
rb_define_method(Archive, "replace_file", zipruby_archive_replace_file,
|
73
|
+
rb_define_method(Archive, "replace_buffer", zipruby_archive_replace_buffer, -1);
|
74
|
+
rb_define_method(Archive, "replace_file", zipruby_archive_replace_file, -1);
|
70
75
|
rb_define_method(Archive, "replace_filep", zipruby_archive_replace_filep, 2);
|
71
76
|
rb_define_method(Archive, "replace", zipruby_archive_replace_function, -1);
|
72
|
-
rb_define_method(Archive, "add_or_replace_buffer", zipruby_archive_add_or_replace_buffer,
|
77
|
+
rb_define_method(Archive, "add_or_replace_buffer", zipruby_archive_add_or_replace_buffer, -1);
|
73
78
|
rb_define_method(Archive, "add_or_replace_file", zipruby_archive_add_or_replace_file, -1);
|
74
79
|
rb_define_method(Archive, "add_or_replace_filep", zipruby_archive_add_or_replace_filep, -1);
|
75
80
|
rb_define_method(Archive, "add_or_replace", zipruby_archive_add_or_replace_function, -1);
|
76
|
-
rb_define_method(Archive, "update", zipruby_archive_update, 1);
|
81
|
+
rb_define_method(Archive, "update", zipruby_archive_update, -1);
|
77
82
|
rb_define_method(Archive, "<<", zipruby_archive_add_filep, -1);
|
78
83
|
rb_define_method(Archive, "get_comment", zipruby_archive_get_comment, -1);
|
79
84
|
rb_define_method(Archive, "comment", zipruby_archive_get_comment, -1);
|
@@ -89,14 +94,24 @@ void Init_zipruby_archive() {
|
|
89
94
|
rb_define_method(Archive, "frevert", zipruby_archive_unchange, 1);
|
90
95
|
rb_define_method(Archive, "revert", zipruby_archive_revert, 0);
|
91
96
|
rb_define_method(Archive, "each", zipruby_archive_each, 0);
|
97
|
+
rb_define_method(Archive, "commit", zipruby_archive_commit, 0);
|
98
|
+
rb_define_method(Archive, "open?", zipruby_archive_is_open, 0);
|
99
|
+
rb_define_method(Archive, "decrypt", zipruby_archive_decrypt, 1);
|
100
|
+
rb_define_method(Archive, "encrypt", zipruby_archive_encrypt, 1);
|
92
101
|
}
|
93
102
|
|
94
103
|
static VALUE zipruby_archive_alloc(VALUE klass) {
|
95
104
|
struct zipruby_archive *p = ALLOC(struct zipruby_archive);
|
96
105
|
|
97
106
|
p->archive = NULL;
|
107
|
+
p->path = Qnil;
|
108
|
+
p->flags = 0;
|
98
109
|
|
99
|
-
return Data_Wrap_Struct(klass,
|
110
|
+
return Data_Wrap_Struct(klass, zipruby_archive_mark, zipruby_archive_free, p);
|
111
|
+
}
|
112
|
+
|
113
|
+
static void zipruby_archive_mark(struct zipruby_archive *p) {
|
114
|
+
rb_gc_mark(p->path);
|
100
115
|
}
|
101
116
|
|
102
117
|
static void zipruby_archive_free(struct zipruby_archive *p) {
|
@@ -127,6 +142,9 @@ static VALUE zipruby_archive_s_open(int argc, VALUE *argv, VALUE self) {
|
|
127
142
|
rb_raise(Error, "Open archive failed - %s: %s", StringValuePtr(path), errstr);
|
128
143
|
}
|
129
144
|
|
145
|
+
p_archive->path = path;
|
146
|
+
p_archive->flags = i_flags;
|
147
|
+
|
130
148
|
if (rb_block_given_p()) {
|
131
149
|
VALUE retval;
|
132
150
|
int status;
|
@@ -200,6 +218,10 @@ static VALUE zipruby_archive_s_encrypt(VALUE self, VALUE path, VALUE password) {
|
|
200
218
|
static VALUE zipruby_archive_close(VALUE self) {
|
201
219
|
struct zipruby_archive *p_archive;
|
202
220
|
|
221
|
+
if (!zipruby_archive_is_open(self)) {
|
222
|
+
return Qfalse;
|
223
|
+
}
|
224
|
+
|
203
225
|
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
204
226
|
Check_Archive(p_archive);
|
205
227
|
|
@@ -210,8 +232,10 @@ static VALUE zipruby_archive_close(VALUE self) {
|
|
210
232
|
}
|
211
233
|
|
212
234
|
p_archive->archive = NULL;
|
235
|
+
p_archive->path = Qnil;
|
236
|
+
p_archive->flags = 0;
|
213
237
|
|
214
|
-
return
|
238
|
+
return Qtrue;
|
215
239
|
}
|
216
240
|
|
217
241
|
/* */
|
@@ -320,24 +344,31 @@ static VALUE zipruby_archive_add_buffer(VALUE self, VALUE name, VALUE source) {
|
|
320
344
|
}
|
321
345
|
|
322
346
|
/* */
|
323
|
-
static VALUE zipruby_archive_replace_buffer(
|
347
|
+
static VALUE zipruby_archive_replace_buffer(int argc, VALUE *argv, VALUE self) {
|
324
348
|
struct zipruby_archive *p_archive;
|
325
349
|
struct zip_source *zsource;
|
326
|
-
|
350
|
+
VALUE index, source, flags;
|
351
|
+
int i_index, i_flags = 0;
|
327
352
|
char *data;
|
328
353
|
off_t len;
|
329
354
|
|
355
|
+
rb_scan_args(argc, argv, "21", &index, &source, &flags);
|
356
|
+
|
330
357
|
if (!rb_obj_is_instance_of(index, rb_cString) && !rb_obj_is_instance_of(index, rb_cFixnum)) {
|
331
358
|
rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or String)", rb_class2name(CLASS_OF(index)));
|
332
359
|
}
|
333
360
|
|
361
|
+
if (!NIL_P(flags)) {
|
362
|
+
i_flags = NUM2INT(flags);
|
363
|
+
}
|
364
|
+
|
334
365
|
Check_Type(source, T_STRING);
|
335
366
|
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
336
367
|
Check_Archive(p_archive);
|
337
368
|
|
338
369
|
if (rb_obj_is_instance_of(index, rb_cFixnum)) {
|
339
370
|
i_index = NUM2INT(index);
|
340
|
-
} else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index),
|
371
|
+
} else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index), i_flags)) == -1) {
|
341
372
|
rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", StringValuePtr(index));
|
342
373
|
}
|
343
374
|
|
@@ -365,18 +396,26 @@ static VALUE zipruby_archive_replace_buffer(VALUE self, VALUE index, VALUE sourc
|
|
365
396
|
}
|
366
397
|
|
367
398
|
/* */
|
368
|
-
static VALUE zipruby_archive_add_or_replace_buffer(
|
399
|
+
static VALUE zipruby_archive_add_or_replace_buffer(int argc, VALUE *argv, VALUE self) {
|
369
400
|
struct zipruby_archive *p_archive;
|
370
|
-
|
401
|
+
VALUE name, source, flags;
|
402
|
+
int index, i_flags = 0;
|
403
|
+
|
404
|
+
rb_scan_args(argc, argv, "21", &name, &source, &flags);
|
405
|
+
|
406
|
+
if (!NIL_P(flags)) {
|
407
|
+
i_flags = NUM2INT(flags);
|
408
|
+
}
|
371
409
|
|
372
410
|
Check_Type(name, T_STRING);
|
373
411
|
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
374
412
|
Check_Archive(p_archive);
|
375
413
|
|
376
|
-
index = zip_name_locate(p_archive->archive, StringValuePtr(name),
|
414
|
+
index = zip_name_locate(p_archive->archive, StringValuePtr(name), i_flags);
|
377
415
|
|
378
416
|
if (index >= 0) {
|
379
|
-
|
417
|
+
VALUE _args[] = { INT2NUM(index), source };
|
418
|
+
return zipruby_archive_replace_buffer(2, _args, self);
|
380
419
|
} else {
|
381
420
|
return zipruby_archive_add_buffer(self, name, source);
|
382
421
|
}
|
@@ -420,22 +459,29 @@ static VALUE zipruby_archive_add_file(int argc, VALUE *argv, VALUE self) {
|
|
420
459
|
}
|
421
460
|
|
422
461
|
/* */
|
423
|
-
static VALUE zipruby_archive_replace_file(
|
462
|
+
static VALUE zipruby_archive_replace_file(int argc, VALUE* argv, VALUE self) {
|
424
463
|
struct zipruby_archive *p_archive;
|
425
464
|
struct zip_source *zsource;
|
426
|
-
|
465
|
+
VALUE index, fname, flags;
|
466
|
+
int i_index, i_flags = 0;
|
467
|
+
|
468
|
+
rb_scan_args(argc, argv, "21", &index, &fname, &flags);
|
427
469
|
|
428
470
|
if (!rb_obj_is_instance_of(index, rb_cString) && !rb_obj_is_instance_of(index, rb_cFixnum)) {
|
429
471
|
rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or String)", rb_class2name(CLASS_OF(index)));
|
430
472
|
}
|
431
473
|
|
474
|
+
if (!NIL_P(flags)) {
|
475
|
+
i_flags = NUM2INT(flags);
|
476
|
+
}
|
477
|
+
|
432
478
|
Check_Type(fname, T_STRING);
|
433
479
|
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
434
480
|
Check_Archive(p_archive);
|
435
481
|
|
436
482
|
if (rb_obj_is_instance_of(index, rb_cFixnum)) {
|
437
483
|
i_index = NUM2INT(index);
|
438
|
-
} else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index),
|
484
|
+
} else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index), i_flags)) == -1) {
|
439
485
|
rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", StringValuePtr(index));
|
440
486
|
}
|
441
487
|
|
@@ -455,11 +501,16 @@ static VALUE zipruby_archive_replace_file(VALUE self, VALUE index, VALUE fname)
|
|
455
501
|
|
456
502
|
/* */
|
457
503
|
static VALUE zipruby_archive_add_or_replace_file(int argc, VALUE *argv, VALUE self) {
|
458
|
-
VALUE name, fname;
|
504
|
+
VALUE name, fname, flags;
|
459
505
|
struct zipruby_archive *p_archive;
|
460
|
-
int index;
|
506
|
+
int index, i_flags = 0;
|
461
507
|
|
462
|
-
rb_scan_args(argc, argv, "
|
508
|
+
rb_scan_args(argc, argv, "12", &name, &fname, &flags);
|
509
|
+
|
510
|
+
if (NIL_P(flags) && FIXNUM_P(fname)) {
|
511
|
+
flags = fname;
|
512
|
+
fname = Qnil;
|
513
|
+
}
|
463
514
|
|
464
515
|
if (NIL_P(fname)) {
|
465
516
|
fname = name;
|
@@ -472,16 +523,22 @@ static VALUE zipruby_archive_add_or_replace_file(int argc, VALUE *argv, VALUE se
|
|
472
523
|
name = rb_funcall(rb_cFile, rb_intern("basename"), 1, fname);
|
473
524
|
}
|
474
525
|
|
526
|
+
if (!NIL_P(flags)) {
|
527
|
+
i_flags = NUM2INT(flags);
|
528
|
+
}
|
529
|
+
|
475
530
|
Check_Type(name, T_STRING);
|
476
531
|
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
477
532
|
Check_Archive(p_archive);
|
478
533
|
|
479
|
-
index = zip_name_locate(p_archive->archive, StringValuePtr(name),
|
534
|
+
index = zip_name_locate(p_archive->archive, StringValuePtr(name), i_flags);
|
480
535
|
|
481
536
|
if (index >= 0) {
|
482
|
-
|
537
|
+
VALUE _args[] = { INT2NUM(index), fname };
|
538
|
+
return zipruby_archive_replace_file(2, _args, self);
|
483
539
|
} else {
|
484
|
-
|
540
|
+
VALUE _args[] = { name, fname };
|
541
|
+
return zipruby_archive_add_file(2, _args, self);
|
485
542
|
}
|
486
543
|
}
|
487
544
|
|
@@ -510,20 +567,28 @@ static VALUE zipruby_archive_add_filep(int argc, VALUE *argv, VALUE self) {
|
|
510
567
|
/* */
|
511
568
|
static VALUE zipruby_archive_replace_filep(VALUE self, VALUE index, VALUE file) {
|
512
569
|
VALUE source;
|
570
|
+
VALUE _args[2];
|
513
571
|
|
514
572
|
Check_Type(file, T_FILE);
|
515
573
|
source = rb_funcall(file, rb_intern("read"), 0);
|
516
574
|
|
517
|
-
|
575
|
+
_args[0] = index;
|
576
|
+
_args[1] = source;
|
577
|
+
return zipruby_archive_replace_buffer(2, _args, self);
|
518
578
|
}
|
519
579
|
|
520
580
|
/* */
|
521
581
|
static VALUE zipruby_archive_add_or_replace_filep(int argc, VALUE *argv, VALUE self) {
|
522
|
-
VALUE name, file;
|
582
|
+
VALUE name, file, flags;
|
523
583
|
struct zipruby_archive *p_archive;
|
524
|
-
int index;
|
584
|
+
int index, i_flags = 0;
|
525
585
|
|
526
|
-
rb_scan_args(argc, argv, "
|
586
|
+
rb_scan_args(argc, argv, "12", &name, &file, &flags);
|
587
|
+
|
588
|
+
if (NIL_P(flags) && FIXNUM_P(file)) {
|
589
|
+
flags = file;
|
590
|
+
file = Qnil;
|
591
|
+
}
|
527
592
|
|
528
593
|
if (NIL_P(file)) {
|
529
594
|
file = name;
|
@@ -536,16 +601,21 @@ static VALUE zipruby_archive_add_or_replace_filep(int argc, VALUE *argv, VALUE s
|
|
536
601
|
name = rb_funcall(rb_cFile, rb_intern("basename"), 1, rb_funcall(file, rb_intern("path"), 0));
|
537
602
|
}
|
538
603
|
|
604
|
+
if (!NIL_P(flags)) {
|
605
|
+
i_flags = NUM2INT(flags);
|
606
|
+
}
|
607
|
+
|
539
608
|
Check_Type(name, T_STRING);
|
540
609
|
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
541
610
|
Check_Archive(p_archive);
|
542
611
|
|
543
|
-
index = zip_name_locate(p_archive->archive, StringValuePtr(name),
|
612
|
+
index = zip_name_locate(p_archive->archive, StringValuePtr(name), i_flags);
|
544
613
|
|
545
614
|
if (index >= 0) {
|
546
615
|
return zipruby_archive_replace_filep(self, INT2NUM(index), file);
|
547
616
|
} else {
|
548
|
-
|
617
|
+
VALUE _args[] = { name, file };
|
618
|
+
return zipruby_archive_add_filep(2, _args, self);
|
549
619
|
}
|
550
620
|
}
|
551
621
|
|
@@ -638,34 +708,52 @@ static VALUE zipruby_archive_replace_function(int argc, VALUE *argv, VALUE self)
|
|
638
708
|
|
639
709
|
/* */
|
640
710
|
static VALUE zipruby_archive_add_or_replace_function(int argc, VALUE *argv, VALUE self) {
|
641
|
-
VALUE name, mtime;
|
711
|
+
VALUE name, mtime, flags;
|
642
712
|
struct zipruby_archive *p_archive;
|
643
|
-
int index;
|
713
|
+
int index, i_flags = 0;
|
714
|
+
|
715
|
+
rb_scan_args(argc, argv, "12", &name, &mtime, &flags);
|
716
|
+
|
717
|
+
if (NIL_P(flags) && FIXNUM_P(mtime)) {
|
718
|
+
flags = mtime;
|
719
|
+
mtime = Qnil;
|
720
|
+
}
|
721
|
+
|
722
|
+
if (!NIL_P(flags)) {
|
723
|
+
i_flags = NUM2INT(flags);
|
724
|
+
}
|
644
725
|
|
645
|
-
rb_scan_args(argc, argv, "11", &name, &mtime);
|
646
726
|
Check_Type(name, T_STRING);
|
647
727
|
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
648
728
|
Check_Archive(p_archive);
|
649
729
|
|
650
|
-
index = zip_name_locate(p_archive->archive, StringValuePtr(name),
|
730
|
+
index = zip_name_locate(p_archive->archive, StringValuePtr(name), i_flags);
|
651
731
|
|
652
732
|
if (index >= 0) {
|
653
|
-
VALUE
|
654
|
-
return zipruby_archive_replace_function(2,
|
733
|
+
VALUE _args[] = { INT2NUM(index), mtime };
|
734
|
+
return zipruby_archive_replace_function(2, _args, self);
|
655
735
|
} else {
|
656
|
-
|
736
|
+
VALUE _args[] = { name, mtime };
|
737
|
+
return zipruby_archive_add_function(2, _args, self);
|
657
738
|
}
|
658
739
|
}
|
659
740
|
|
660
741
|
/* */
|
661
|
-
static VALUE zipruby_archive_update(VALUE
|
742
|
+
static VALUE zipruby_archive_update(int argc, VALUE *argv, VALUE self) {
|
662
743
|
struct zipruby_archive *p_archive, *p_srcarchive;
|
663
|
-
|
744
|
+
VALUE srcarchive, flags;
|
745
|
+
int i, num_files, i_flags = 0;
|
746
|
+
|
747
|
+
rb_scan_args(argc, argv, "11", &srcarchive, &flags);
|
664
748
|
|
665
749
|
if (!rb_obj_is_instance_of(srcarchive, Archive)) {
|
666
750
|
rb_raise(rb_eTypeError, "wrong argument type %s (expected Zip::Archive)", rb_class2name(CLASS_OF(srcarchive)));
|
667
751
|
}
|
668
752
|
|
753
|
+
if (!NIL_P(flags)) {
|
754
|
+
i_flags = NUM2INT(flags);
|
755
|
+
}
|
756
|
+
|
669
757
|
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
670
758
|
Check_Archive(p_archive);
|
671
759
|
Data_Get_Struct(srcarchive, struct zipruby_archive, p_srcarchive);
|
@@ -735,7 +823,7 @@ static VALUE zipruby_archive_update(VALUE self, VALUE srcarchive) {
|
|
735
823
|
rb_raise(Error, "Update archive failed: %s", zip_strerror(p_srcarchive->archive));
|
736
824
|
}
|
737
825
|
|
738
|
-
index = zip_name_locate(p_archive->archive, name,
|
826
|
+
index = zip_name_locate(p_archive->archive, name, i_flags);
|
739
827
|
|
740
828
|
if (index >= 0) {
|
741
829
|
if (zip_replace(p_archive->archive, i, zsource) == -1) {
|
@@ -976,3 +1064,113 @@ static VALUE zipruby_archive_each(VALUE self) {
|
|
976
1064
|
|
977
1065
|
return Qnil;
|
978
1066
|
}
|
1067
|
+
|
1068
|
+
/* */
|
1069
|
+
static VALUE zipruby_archive_commit(VALUE self) {
|
1070
|
+
struct zipruby_archive *p_archive;
|
1071
|
+
int errorp;
|
1072
|
+
|
1073
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
1074
|
+
Check_Archive(p_archive);
|
1075
|
+
|
1076
|
+
if (zip_close(p_archive->archive) == -1) {
|
1077
|
+
zip_unchange_all(p_archive->archive);
|
1078
|
+
zip_unchange_archive(p_archive->archive);
|
1079
|
+
rb_raise(Error, "Commit archive failed: %s", zip_strerror(p_archive->archive));
|
1080
|
+
}
|
1081
|
+
|
1082
|
+
p_archive->archive = NULL;
|
1083
|
+
p_archive->flags = (p_archive->flags & ~(ZIP_CREATE | ZIP_EXCL));
|
1084
|
+
|
1085
|
+
if ((p_archive->archive = zip_open(StringValuePtr(p_archive->path), p_archive->flags, &errorp)) == NULL) {
|
1086
|
+
char errstr[ERRSTR_BUFSIZE];
|
1087
|
+
zip_error_to_str(errstr, ERRSTR_BUFSIZE, errorp, errno);
|
1088
|
+
rb_raise(Error, "Commit archive failed: %s", errstr);
|
1089
|
+
}
|
1090
|
+
|
1091
|
+
return Qnil;
|
1092
|
+
}
|
1093
|
+
|
1094
|
+
/* */
|
1095
|
+
static VALUE zipruby_archive_is_open(VALUE self) {
|
1096
|
+
struct zipruby_archive *p_archive;
|
1097
|
+
|
1098
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
1099
|
+
return (p_archive->archive != NULL) ? Qtrue : Qfalse;
|
1100
|
+
}
|
1101
|
+
|
1102
|
+
/* */
|
1103
|
+
static VALUE zipruby_archive_decrypt(VALUE self, VALUE password) {
|
1104
|
+
struct zipruby_archive *p_archive;
|
1105
|
+
long pwdlen;
|
1106
|
+
int errorp;
|
1107
|
+
|
1108
|
+
Check_Type(password, T_STRING);
|
1109
|
+
pwdlen = RSTRING(password)->len;
|
1110
|
+
|
1111
|
+
if (pwdlen < 1) {
|
1112
|
+
rb_raise(Error, "Decrypt archive failed: Password is empty");
|
1113
|
+
} else if (pwdlen > 0xff) {
|
1114
|
+
rb_raise(Error, "Decrypt archive failed: Password is too long");
|
1115
|
+
}
|
1116
|
+
|
1117
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
1118
|
+
Check_Archive(p_archive);
|
1119
|
+
|
1120
|
+
if (zip_close(p_archive->archive) == -1) {
|
1121
|
+
zip_unchange_all(p_archive->archive);
|
1122
|
+
zip_unchange_archive(p_archive->archive);
|
1123
|
+
rb_raise(Error, "Decrypt archive failed: %s", zip_strerror(p_archive->archive));
|
1124
|
+
}
|
1125
|
+
|
1126
|
+
p_archive->archive = NULL;
|
1127
|
+
p_archive->flags = (p_archive->flags & ~(ZIP_CREATE | ZIP_EXCL));
|
1128
|
+
|
1129
|
+
zipruby_archive_s_decrypt(Archive, p_archive->path, password);
|
1130
|
+
|
1131
|
+
if ((p_archive->archive = zip_open(StringValuePtr(p_archive->path), p_archive->flags, &errorp)) == NULL) {
|
1132
|
+
char errstr[ERRSTR_BUFSIZE];
|
1133
|
+
zip_error_to_str(errstr, ERRSTR_BUFSIZE, errorp, errno);
|
1134
|
+
rb_raise(Error, "Decrypt archive failed: %s", errstr);
|
1135
|
+
}
|
1136
|
+
|
1137
|
+
return Qnil;
|
1138
|
+
}
|
1139
|
+
|
1140
|
+
/* */
|
1141
|
+
static VALUE zipruby_archive_encrypt(VALUE self, VALUE password) {
|
1142
|
+
struct zipruby_archive *p_archive;
|
1143
|
+
long pwdlen;
|
1144
|
+
int errorp;
|
1145
|
+
|
1146
|
+
Check_Type(password, T_STRING);
|
1147
|
+
pwdlen = RSTRING(password)->len;
|
1148
|
+
|
1149
|
+
if (pwdlen < 1) {
|
1150
|
+
rb_raise(Error, "Encrypt archive failed: Password is empty");
|
1151
|
+
} else if (pwdlen > 0xff) {
|
1152
|
+
rb_raise(Error, "Encrypt archive failed: Password is too long");
|
1153
|
+
}
|
1154
|
+
|
1155
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
1156
|
+
Check_Archive(p_archive);
|
1157
|
+
|
1158
|
+
if (zip_close(p_archive->archive) == -1) {
|
1159
|
+
zip_unchange_all(p_archive->archive);
|
1160
|
+
zip_unchange_archive(p_archive->archive);
|
1161
|
+
rb_raise(Error, "Encrypt archive failed: %s", zip_strerror(p_archive->archive));
|
1162
|
+
}
|
1163
|
+
|
1164
|
+
p_archive->archive = NULL;
|
1165
|
+
p_archive->flags = (p_archive->flags & ~(ZIP_CREATE | ZIP_EXCL));
|
1166
|
+
|
1167
|
+
zipruby_archive_s_encrypt(Archive, p_archive->path, password);
|
1168
|
+
|
1169
|
+
if ((p_archive->archive = zip_open(StringValuePtr(p_archive->path), p_archive->flags, &errorp)) == NULL) {
|
1170
|
+
char errstr[ERRSTR_BUFSIZE];
|
1171
|
+
zip_error_to_str(errstr, ERRSTR_BUFSIZE, errorp, errno);
|
1172
|
+
rb_raise(Error, "Encrypt archive failed: %s", errstr);
|
1173
|
+
}
|
1174
|
+
|
1175
|
+
return Qnil;
|
1176
|
+
}
|