zipruby 0.2.4-mswin32 → 0.2.5-mswin32

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.

Files changed (3) hide show
  1. data/lib/i386-mswin32/zipruby.so +0 -0
  2. data/zipruby.c +28 -8
  3. metadata +2 -2
Binary file
data/zipruby.c CHANGED
@@ -342,14 +342,24 @@ static VALUE zipruby_archive_add_buffer(VALUE self, VALUE name, VALUE source) {
342
342
  static VALUE zipruby_archive_replace_buffer(VALUE self, VALUE index, VALUE source) {
343
343
  struct zipruby_archive *p_archive;
344
344
  struct zip_source *zsource;
345
+ int i_index;
345
346
  char *data;
346
347
  off_t len;
347
348
 
348
- Check_Type(index, T_FIXNUM);
349
+ if (!rb_obj_is_instance_of(index, rb_cString) && !rb_obj_is_instance_of(index, rb_cFixnum)) {
350
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or String)", rb_class2name(CLASS_OF(index)));
351
+ }
352
+
349
353
  Check_Type(source, T_STRING);
350
354
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
351
355
  Check_Archive(p_archive);
352
356
 
357
+ if (rb_obj_is_instance_of(index, rb_cFixnum)) {
358
+ i_index = NUM2INT(index);
359
+ } else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index), ZIP_FL_NOCASE)) == -1) {
360
+ rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", StringValuePtr(index));
361
+ }
362
+
353
363
  len = RSTRING(source)->len;
354
364
 
355
365
  if ((data = malloc(len)) == NULL) {
@@ -360,14 +370,14 @@ static VALUE zipruby_archive_replace_buffer(VALUE self, VALUE index, VALUE sourc
360
370
 
361
371
  if ((zsource = zip_source_buffer(p_archive->archive, data, len, 1)) == NULL) {
362
372
  free(data);
363
- rb_raise(Error, "Replace file failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
373
+ rb_raise(Error, "Replace file failed at %d: %s", i_index, zip_strerror(p_archive->archive));
364
374
  }
365
375
 
366
- if (zip_replace(p_archive->archive, NUM2INT(index), zsource) == -1) {
376
+ if (zip_replace(p_archive->archive, i_index, zsource) == -1) {
367
377
  zip_source_free(zsource);
368
378
  zip_unchange_all(p_archive->archive);
369
379
  zip_unchange_archive(p_archive->archive);
370
- rb_raise(Error, "Replace file failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
380
+ rb_raise(Error, "Replace file failed at %d: %s", i_index, zip_strerror(p_archive->archive));
371
381
  }
372
382
 
373
383
  return Qnil;
@@ -432,21 +442,31 @@ static VALUE zipruby_archive_add_file(int argc, VALUE *argv, VALUE self) {
432
442
  static VALUE zipruby_archive_replace_file(VALUE self, VALUE index, VALUE fname) {
433
443
  struct zipruby_archive *p_archive;
434
444
  struct zip_source *zsource;
445
+ int i_index;
446
+
447
+ if (!rb_obj_is_instance_of(index, rb_cString) && !rb_obj_is_instance_of(index, rb_cFixnum)) {
448
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or String)", rb_class2name(CLASS_OF(index)));
449
+ }
435
450
 
436
- Check_Type(index, T_FIXNUM);
437
451
  Check_Type(fname, T_STRING);
438
452
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
439
453
  Check_Archive(p_archive);
440
454
 
455
+ if (rb_obj_is_instance_of(index, rb_cFixnum)) {
456
+ i_index = NUM2INT(index);
457
+ } else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index), ZIP_FL_NOCASE)) == -1) {
458
+ rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", StringValuePtr(index));
459
+ }
460
+
441
461
  if ((zsource = zip_source_file(p_archive->archive, StringValuePtr(fname), 0, -1)) == NULL) {
442
- rb_raise(Error, "Replace file failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
462
+ rb_raise(Error, "Replace file failed at %d: %s", i_index, zip_strerror(p_archive->archive));
443
463
  }
444
464
 
445
- if (zip_replace(p_archive->archive, NUM2INT(index), zsource) == -1) {
465
+ if (zip_replace(p_archive->archive, i_index, zsource) == -1) {
446
466
  zip_source_free(zsource);
447
467
  zip_unchange_all(p_archive->archive);
448
468
  zip_unchange_archive(p_archive->archive);
449
- rb_raise(Error, "Replace file failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
469
+ rb_raise(Error, "Replace file failed at %d: %s", i_index, zip_strerror(p_archive->archive));
450
470
  }
451
471
 
452
472
  return Qnil;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: mswin32
6
6
  authors:
7
7
  - winebarrel
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-01 00:00:00 +09:00
12
+ date: 2008-05-05 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15