rubyzip 0.9.1 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubyzip might be problematic. Click here for more details.

Files changed (54) hide show
  1. data/ChangeLog +92 -450
  2. data/NEWS +18 -0
  3. data/README +1 -1
  4. data/Rakefile +14 -13
  5. data/install.rb +4 -3
  6. data/lib/zip/ioextras.rb +11 -1
  7. data/lib/zip/stdrubyext.rb +0 -0
  8. data/lib/zip/tempfile_bugfixed.rb +0 -0
  9. data/lib/zip/zip.rb +57 -24
  10. data/lib/zip/zipfilesystem.rb +1 -0
  11. data/lib/zip/ziprequire.rb +0 -0
  12. data/samples/example.rb +0 -0
  13. data/samples/example_filesystem.rb +0 -1
  14. data/samples/gtkRubyzip.rb +0 -0
  15. data/samples/qtzip.rb +0 -0
  16. data/samples/write_simple.rb +0 -0
  17. data/samples/zipfind.rb +0 -0
  18. data/test/alltests.rb +0 -0
  19. data/test/data/notzippedruby.rb +0 -0
  20. data/test/gentestfiles.rb +0 -0
  21. data/test/ioextrastest.rb +0 -0
  22. data/test/stdrubyexttest.rb +0 -0
  23. data/test/zipfilesystemtest.rb +14 -4
  24. data/test/ziprequiretest.rb +0 -0
  25. data/test/ziptest.rb +30 -9
  26. metadata +76 -88
  27. data/lib/download_quizzes.rb +0 -119
  28. data/lib/quiz1/t/solutions/Bill Guindon/solitaire.rb +0 -205
  29. data/lib/quiz1/t/solutions/Carlos/solitaire.rb +0 -111
  30. data/lib/quiz1/t/solutions/Dennis Ranke/solitaire.rb +0 -111
  31. data/lib/quiz1/t/solutions/Florian Gross/solitaire.rb +0 -301
  32. data/lib/quiz1/t/solutions/Glen M. Lewis/solitaire.rb +0 -268
  33. data/lib/quiz1/t/solutions/James Edward Gray II/solitaire.rb +0 -132
  34. data/lib/quiz1/t/solutions/Jamis Buck/bin/main.rb +0 -13
  35. data/lib/quiz1/t/solutions/Jamis Buck/lib/cipher.rb +0 -230
  36. data/lib/quiz1/t/solutions/Jamis Buck/lib/cli.rb +0 -24
  37. data/lib/quiz1/t/solutions/Jamis Buck/test/tc_deck.rb +0 -30
  38. data/lib/quiz1/t/solutions/Jamis Buck/test/tc_key-stream.rb +0 -19
  39. data/lib/quiz1/t/solutions/Jamis Buck/test/tc_keying-algorithms.rb +0 -31
  40. data/lib/quiz1/t/solutions/Jamis Buck/test/tc_solitaire-cipher.rb +0 -66
  41. data/lib/quiz1/t/solutions/Jamis Buck/test/tc_unkeyed-algorithm.rb +0 -17
  42. data/lib/quiz1/t/solutions/Jamis Buck/test/tests.rb +0 -2
  43. data/lib/quiz1/t/solutions/Jim Menard/solitaire_cypher.rb +0 -204
  44. data/lib/quiz1/t/solutions/Jim Menard/test.rb +0 -47
  45. data/lib/quiz1/t/solutions/Moses Hohman/cipher.rb +0 -97
  46. data/lib/quiz1/t/solutions/Moses Hohman/deck.rb +0 -140
  47. data/lib/quiz1/t/solutions/Moses Hohman/solitaire.rb +0 -14
  48. data/lib/quiz1/t/solutions/Moses Hohman/test_cipher.rb +0 -68
  49. data/lib/quiz1/t/solutions/Moses Hohman/test_deck.rb +0 -146
  50. data/lib/quiz1/t/solutions/Moses Hohman/test_util.rb +0 -38
  51. data/lib/quiz1/t/solutions/Moses Hohman/testsuite.rb +0 -5
  52. data/lib/quiz1/t/solutions/Moses Hohman/util.rb +0 -27
  53. data/lib/quiz1/t/solutions/Niklas Frykholm/solitaire.rb +0 -151
  54. data/lib/quiz1/t/solutions/Thomas Leitner/solitaire.rb +0 -198
data/NEWS CHANGED
@@ -1,3 +1,21 @@
1
+ = Version 0.9.4
2
+
3
+ Changed ZipOutputStream.put_next_entry signature (API CHANGE!). Now
4
+ allows comment, extra field and compression method to be specified.
5
+
6
+ = Version 0.9.3
7
+
8
+ Fixed: Added ZipEntry::name_encoding which retrieves the character
9
+ encoding of the name and comment of the entry. Also added convenience
10
+ methods ZipEntry::name_in(enc) and ZipEntry::comment_in(enc) for
11
+ getting zip entry names and comments in a specified character
12
+ encoding.
13
+
14
+ = Version 0.9.2
15
+
16
+ Fixed: Renaming an entry failed if the entry's new name was a
17
+ different length than its old name. (Diego Barros)
18
+
1
19
  = Version 0.9.1
2
20
 
3
21
  Added symlink support and support for unix file permissions. Reduced
data/README CHANGED
@@ -69,4 +69,4 @@ Thomas Sondergaard (thomas at sondergaard.cc)
69
69
 
70
70
  Technorama Ltd. (oss-ruby-zip at technorama.net)
71
71
 
72
- extra-field support contributed by Tatsuki Sugiura (sugi at nemui.org)
72
+ extra-field support contributed by Tatsuki Sugiura (sugi at nemui.org)
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require 'rake/packagetask'
7
7
  require 'rake/gempackagetask'
8
8
  require 'rake/rdoctask'
9
9
  require 'rake/contrib/sshpublisher'
10
- require 'net/ftp'
10
+ require 'net/sftp'
11
11
 
12
12
  PKG_NAME = 'rubyzip'
13
13
  PKG_VERSION = File.read('lib/zip/zip.rb').match(/\s+VERSION\s*=\s*'(.*)'/)[1]
@@ -32,6 +32,10 @@ clobberFromCvsIgnore 'samples'
32
32
  clobberFromCvsIgnore 'test'
33
33
  clobberFromCvsIgnore 'test/data'
34
34
 
35
+ def rsystem(cmd)
36
+ system(cmd) or raise "system command failed: '#{cmd}"
37
+ end
38
+
35
39
  task :default => [:test]
36
40
 
37
41
  desc "Run unit tests"
@@ -62,29 +66,26 @@ end
62
66
  Rake::RDocTask.new do |rd|
63
67
  rd.main = "README"
64
68
  rd.rdoc_files.add %W{ lib/zip/*.rb README NEWS TODO ChangeLog }
65
- rd.options << "--title 'rubyzip documentation' --webcvs http://cvs.sourceforge.net/viewcvs.py/rubyzip/rubyzip/"
69
+ rd.options << "-t 'rubyzip documentation' --webcvs http://cvs.sourceforge.net/viewcvs.py/rubyzip/rubyzip/"
66
70
  # rd.options << "--all"
67
71
  end
68
72
 
69
73
  desc "Publish documentation"
70
74
  task :pdoc => [:rdoc] do
71
- Rake::SshFreshDirPublisher.
72
- new("thomas@rubyzip.sourceforge.net", "/home/groups/r/ru/rubyzip/htdocs", "html").upload
75
+ rsystem("rsync -avz --delete html/* thomas,rubyzip@frs.sourceforge.net:/home/groups/r/ru/rubyzip/htdocs")
73
76
  end
74
77
 
75
78
  desc "Publish package"
76
79
  task :ppackage => [:package] do
77
- Net::FTP.open("upload.sourceforge.net",
78
- "ftp",
79
- ENV['USER']+"@"+ENV['HOSTNAME']) {
80
+ Net::SFTP.start("frs.sourceforge.net", "thomas,rubyzip") do
80
81
  |ftpclient|
81
- ftpclient.passive = true
82
- ftpclient.chdir "incoming"
83
- Dir['pkg/*.{tgz,zip,gem}'].each {
82
+ releasedir = File.join("/home/pfs/project/r/ru/rubyzip/rubyzip", PKG_VERSION)
83
+ ftpclient.mkdir releasedir
84
+ Dir['pkg/*.{tgz,zip,gem}'].each do
84
85
  |e|
85
- ftpclient.putbinaryfile(e, File.basename(e))
86
- }
87
- }
86
+ ftpclient.upload!(e, File.join(releasedir, File.basename(e)))
87
+ end
88
+ end
88
89
  end
89
90
 
90
91
  desc "Generate the ChangeLog file"
data/install.rb CHANGED
@@ -4,19 +4,20 @@ $VERBOSE = true
4
4
 
5
5
  require 'rbconfig'
6
6
  require 'find'
7
- require 'ftools'
7
+ require 'fileutils'
8
8
 
9
9
  include Config
10
10
 
11
11
  files = %w{ stdrubyext.rb ioextras.rb zip.rb zipfilesystem.rb ziprequire.rb tempfile_bugfixed.rb }
12
12
 
13
13
  INSTALL_DIR = File.join(CONFIG["sitelibdir"], "zip")
14
- File.makedirs(INSTALL_DIR)
14
+ FileUtils.makedirs(INSTALL_DIR)
15
15
 
16
16
  SOURCE_DIR = File.join(File.dirname($0), "lib/zip")
17
17
 
18
18
  files.each {
19
19
  |filename|
20
20
  installPath = File.join(INSTALL_DIR, filename)
21
- File::install(File.join(SOURCE_DIR, filename), installPath, 0644, true)
21
+ FileUtils::install(File.join(SOURCE_DIR, filename), installPath, 0644,
22
+ :verbose => true)
22
23
  }
@@ -1,6 +1,6 @@
1
1
  module IOExtras #:nodoc:
2
2
 
3
- CHUNK_SIZE = 32768
3
+ CHUNK_SIZE = 131072
4
4
 
5
5
  RANGE_ALL = 0..-1
6
6
 
@@ -9,6 +9,16 @@ module IOExtras #:nodoc:
9
9
  ostream.write(istream.read(CHUNK_SIZE, s)) until istream.eof?
10
10
  end
11
11
 
12
+ def self.copy_stream_n(ostream, istream, nbytes)
13
+ s = ''
14
+ toread = nbytes
15
+ while (toread > 0 && ! istream.eof?)
16
+ tr = toread > CHUNK_SIZE ? CHUNK_SIZE : toread
17
+ ostream.write(istream.read(tr, s))
18
+ toread -= tr
19
+ end
20
+ end
21
+
12
22
 
13
23
  # Implements kind_of? in order to pretend to be an IO object
14
24
  module FakeIO
File without changes
File without changes
@@ -1,7 +1,8 @@
1
1
  require 'delegate'
2
+ require 'iconv'
2
3
  require 'singleton'
3
4
  require 'tempfile'
4
- require 'ftools'
5
+ require 'fileutils'
5
6
  require 'stringio'
6
7
  require 'zlib'
7
8
  require 'zip/stdrubyext'
@@ -20,7 +21,7 @@ end
20
21
 
21
22
  module Zip
22
23
 
23
- VERSION = '0.9.1'
24
+ VERSION = '0.9.4'
24
25
 
25
26
  RUBY_MINOR_VERSION = RUBY_VERSION.split(".")[1].to_i
26
27
 
@@ -349,6 +350,21 @@ module Zip
349
350
 
350
351
  attr_reader :ftype, :filepath # :nodoc:
351
352
 
353
+ # Returns the character encoding used for name and comment
354
+ def name_encoding
355
+ (@gp_flags & 0b100000000000) != 0 ? "utf8" : "CP437//"
356
+ end
357
+
358
+ # Returns the name in the encoding specified by enc
359
+ def name_in(enc)
360
+ Iconv.conv(enc, name_encoding, @name)
361
+ end
362
+
363
+ # Returns the name in the encoding specified by enc
364
+ def comment_in(enc)
365
+ Iconv.conv(enc, name_encoding, @name)
366
+ end
367
+
352
368
  def initialize(zipfile = "", name = "", comment = "", extra = "",
353
369
  compressed_size = 0, crc = 0,
354
370
  compression_method = ZipEntry::DEFLATED, size = 0,
@@ -358,6 +374,7 @@ module Zip
358
374
  raise ZipEntryNameError, "Illegal ZipEntry name '#{name}', name must not start with /"
359
375
  end
360
376
  @localHeaderOffset = 0
377
+ @local_header_size = 0
361
378
  @internalFileAttributes = 1
362
379
  @externalFileAttributes = 0
363
380
  @version = 52 # this library's version
@@ -368,9 +385,14 @@ module Zip
368
385
  else
369
386
  @fstype = FSTYPE_UNIX
370
387
  end
371
- @zipfile, @comment, @compressed_size, @crc, @extra, @compression_method,
372
- @name, @size = zipfile, comment, compressed_size, crc,
373
- extra, compression_method, name, size
388
+ @zipfile = zipfile
389
+ @comment = comment
390
+ @compressed_size = compressed_size
391
+ @crc = crc
392
+ @extra = extra
393
+ @compression_method = compression_method
394
+ @name = name
395
+ @size = size
374
396
  @time = time
375
397
 
376
398
  @follow_symlinks = false
@@ -432,7 +454,7 @@ module Zip
432
454
  # Returns +true+ if the entry is a symlink.
433
455
  def symlink?
434
456
  raise ZipInternalError, "current filetype is unknown: #{self.inspect}" unless @ftype
435
- @ftype == :link
457
+ @ftype == :symlink
436
458
  end
437
459
 
438
460
  def name_is_directory? #:nodoc:all
@@ -440,10 +462,10 @@ module Zip
440
462
  end
441
463
 
442
464
  def local_entry_offset #:nodoc:all
443
- localHeaderOffset + local_header_size
465
+ localHeaderOffset + @local_header_size
444
466
  end
445
467
 
446
- def local_header_size #:nodoc:all
468
+ def calculate_local_header_size #:nodoc:all
447
469
  LOCAL_ENTRY_STATIC_HEADER_LENGTH + (@name ? @name.size : 0) + (@extra ? @extra.local_size : 0)
448
470
  end
449
471
 
@@ -491,7 +513,8 @@ module Zip
491
513
  LOCAL_ENTRY_SIGNATURE = 0x04034b50
492
514
  LOCAL_ENTRY_STATIC_HEADER_LENGTH = 30
493
515
  LOCAL_ENTRY_TRAILING_DESCRIPTOR_LENGTH = 4+4+4
494
-
516
+ VERSION_NEEDED_TO_EXTRACT = 10
517
+
495
518
  def read_local_entry(io) #:nodoc:all
496
519
  @localHeaderOffset = io.tell
497
520
  staticSizedFieldsBuf = io.read(LOCAL_ENTRY_STATIC_HEADER_LENGTH)
@@ -516,6 +539,7 @@ module Zip
516
539
  raise ZipError, "Zip local header magic not found at location '#{localHeaderOffset}'"
517
540
  end
518
541
  set_time(lastModDate, lastModTime)
542
+
519
543
 
520
544
  @name = io.read(nameLength)
521
545
  extra = io.read(extraLength)
@@ -529,6 +553,7 @@ module Zip
529
553
  @extra = ZipExtraField.new(extra)
530
554
  end
531
555
  end
556
+ @local_header_size = calculate_local_header_size
532
557
  end
533
558
 
534
559
  def ZipEntry.read_local_entry(io)
@@ -544,7 +569,7 @@ module Zip
544
569
 
545
570
  io <<
546
571
  [LOCAL_ENTRY_SIGNATURE ,
547
- 0 ,
572
+ VERSION_NEEDED_TO_EXTRACT , # version needed to extract
548
573
  0 , # @gp_flags ,
549
574
  @compression_method ,
550
575
  @time.to_binary_dos_time , # @lastModTime ,
@@ -615,7 +640,7 @@ module Zip
615
640
  when 010
616
641
  @ftype = :file
617
642
  when 012
618
- @ftype = :link
643
+ @ftype = :symlink
619
644
  else
620
645
  raise ZipInternalError, "unknown file type #{'0%o' % (@externalFileAttributes >> 28)}"
621
646
  end
@@ -626,6 +651,7 @@ module Zip
626
651
  @ftype = :file
627
652
  end
628
653
  end
654
+ @local_header_size = calculate_local_header_size
629
655
  end
630
656
 
631
657
  def ZipEntry.read_c_dir_entry(io) #:nodoc:all
@@ -662,8 +688,8 @@ module Zip
662
688
  # ignore setuid/setgid bits by default. honor if @restore_ownership
663
689
  unix_perms_mask = 01777
664
690
  unix_perms_mask = 07777 if (@restore_ownership)
665
- File::chmod(@unix_perms & unix_perms_mask, destPath) if (@restore_permissions && @unix_perms)
666
- File::chown(@unix_uid, @unix_gid, destPath) if (@restore_ownership && @unix_uid && @unix_gid && Process::egid == 0)
691
+ FileUtils::chmod(@unix_perms & unix_perms_mask, destPath) if (@restore_permissions && @unix_perms)
692
+ FileUtils::chown(@unix_uid, @unix_gid, destPath) if (@restore_ownership && @unix_uid && @unix_gid && Process::egid == 0)
667
693
  # File::utimes()
668
694
  end
669
695
  end
@@ -693,7 +719,7 @@ module Zip
693
719
  [CENTRAL_DIRECTORY_ENTRY_SIGNATURE,
694
720
  @version , # version of encoding software
695
721
  @fstype , # filesystem type
696
- 0 , # @versionNeededToExtract ,
722
+ VERSION_NEEDED_TO_EXTRACT , # @versionNeededToExtract ,
697
723
  0 , # @gp_flags ,
698
724
  @compression_method ,
699
725
  @time.to_binary_dos_time , # @lastModTime ,
@@ -849,7 +875,7 @@ module Zip
849
875
  return
850
876
  elsif File.exists? destPath
851
877
  if block_given? && yield(self, destPath)
852
- File.rm_f destPath
878
+ FileUtils::rm_f destPath
853
879
  else
854
880
  raise ZipDestinationFileExistsError,
855
881
  "Cannot create directory '#{destPath}'. "+
@@ -951,11 +977,16 @@ module Zip
951
977
 
952
978
  # Closes the current entry and opens a new for writing.
953
979
  # +entry+ can be a ZipEntry object or a string.
954
- def put_next_entry(entry, level = Zlib::DEFAULT_COMPRESSION)
980
+ def put_next_entry(entryname, comment = nil, extra = nil, compression_method = ZipEntry::DEFLATED, level = Zlib::DEFAULT_COMPRESSION)
955
981
  raise ZipError, "zip stream is closed" if @closed
956
- newEntry = entry.kind_of?(ZipEntry) ? entry : ZipEntry.new(@fileName, entry.to_s)
957
- init_next_entry(newEntry, level)
958
- @currentEntry=newEntry
982
+ new_entry = ZipEntry.new(@fileName, entryname.to_s)
983
+ new_entry.comment = comment if !comment.nil?
984
+ if (!extra.nil?)
985
+ new_entry.extra = ZipExtraField === extra ? extra : ZipExtraField.new(extra.to_s)
986
+ end
987
+ new_entry.compression_method = compression_method
988
+ init_next_entry(new_entry, level)
989
+ @currentEntry = new_entry
959
990
  end
960
991
 
961
992
  def copy_raw_entry(entry)
@@ -967,10 +998,10 @@ module Zip
967
998
  src_pos = entry.local_entry_offset
968
999
  entry.write_local_entry(@outputStream)
969
1000
  @compressor = NullCompressor.instance
970
- @outputStream << entry.get_raw_input_stream {
1001
+ entry.get_raw_input_stream {
971
1002
  |is|
972
1003
  is.seek(src_pos, IO::SEEK_SET)
973
- is.read(entry.compressed_size)
1004
+ IOExtras.copy_stream_n(@outputStream, is, entry.compressed_size)
974
1005
  }
975
1006
  @compressor = NullCompressor.instance
976
1007
  @currentEntry = nil
@@ -981,7 +1012,7 @@ module Zip
981
1012
  return unless @currentEntry
982
1013
  finish
983
1014
  @currentEntry.compressed_size = @outputStream.tell - @currentEntry.localHeaderOffset -
984
- @currentEntry.local_header_size
1015
+ @currentEntry.calculate_local_header_size
985
1016
  @currentEntry.size = @compressor.size
986
1017
  @currentEntry.crc = @compressor.crc
987
1018
  @currentEntry = nil
@@ -1453,7 +1484,9 @@ module Zip
1453
1484
  def rename(entry, newName, &continueOnExistsProc)
1454
1485
  foundEntry = get_entry(entry)
1455
1486
  check_entry_exists(newName, continueOnExistsProc, "rename")
1456
- foundEntry.name=newName
1487
+ @entrySet.delete(foundEntry)
1488
+ foundEntry.name = newName
1489
+ @entrySet << foundEntry
1457
1490
  end
1458
1491
 
1459
1492
  # Replaces the specified entry with the contents of srcPath (from
@@ -1566,7 +1599,7 @@ module Zip
1566
1599
  tmpFilename = tmpfile.path
1567
1600
  tmpfile.close
1568
1601
  if yield tmpFilename
1569
- File.move(tmpFilename, name)
1602
+ File.rename(tmpFilename, name)
1570
1603
  end
1571
1604
  end
1572
1605
 
@@ -225,6 +225,7 @@ module Zip
225
225
  end
226
226
 
227
227
  def open(fileName, openMode = "r", &block)
228
+ openMode.gsub!("b", "") # ignore b option
228
229
  case openMode
229
230
  when "r"
230
231
  @mappedZip.get_input_stream(fileName, &block)
File without changes
File without changes
@@ -3,7 +3,6 @@
3
3
  $: << "../lib"
4
4
 
5
5
  require 'zip/zipfilesystem'
6
- require 'ftools'
7
6
 
8
7
  EXAMPLE_ZIP = "filesystem.zip"
9
8
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -6,6 +6,7 @@ $: << "../lib"
6
6
 
7
7
  require 'zip/zipfilesystem'
8
8
  require 'test/unit'
9
+ require 'fileutils'
9
10
 
10
11
  module ExtraAssertions
11
12
 
@@ -23,7 +24,7 @@ module ExtraAssertions
23
24
  assert_equal(retVal, yield) # Invoke test
24
25
  assert_equal(expectedArgs, callArgs)
25
26
  ensure
26
- anObject.instance_eval "alias #{method} #{method}_org"
27
+ anObject.instance_eval "undef #{method}; alias #{method} #{method}_org"
27
28
  end
28
29
 
29
30
  end
@@ -67,6 +68,15 @@ class ZipFsFileNonmutatingTest < Test::Unit::TestCase
67
68
  }
68
69
  assert(blockCalled)
69
70
 
71
+ blockCalled = false
72
+ @zipFile.file.open("file1", "rb") { # test binary flag is ignored
73
+ |f|
74
+ blockCalled = true
75
+ assert_equal("this is the entry 'file1' in my test archive!",
76
+ f.readline.chomp)
77
+ }
78
+ assert(blockCalled)
79
+
70
80
  blockCalled = false
71
81
  @zipFile.dir.chdir "dir2"
72
82
  @zipFile.file.open("file21", "r") {
@@ -552,7 +562,7 @@ end
552
562
  class ZipFsFileMutatingTest < Test::Unit::TestCase
553
563
  TEST_ZIP = "zipWithDirs_copy.zip"
554
564
  def setup
555
- File.copy("data/zipWithDirs.zip", TEST_ZIP)
565
+ FileUtils.cp("data/zipWithDirs.zip", TEST_ZIP)
556
566
  end
557
567
 
558
568
  def teardown
@@ -579,7 +589,7 @@ class ZipFsFileMutatingTest < Test::Unit::TestCase
579
589
  zf.file.read("test_open_write_entry"))
580
590
 
581
591
  # Test with existing entry
582
- zf.file.open("file1", "w") {
592
+ zf.file.open("file1", "wb") { #also check that 'b' option is ignored
583
593
  |f|
584
594
  blockCalled = true
585
595
  f.write "This is what I'm writing too"
@@ -640,7 +650,7 @@ class ZipFsDirectoryTest < Test::Unit::TestCase
640
650
  TEST_ZIP = "zipWithDirs_copy.zip"
641
651
 
642
652
  def setup
643
- File.copy("data/zipWithDirs.zip", TEST_ZIP)
653
+ FileUtils.cp("data/zipWithDirs.zip", TEST_ZIP)
644
654
  end
645
655
 
646
656
  def test_delete