2 # Copyright (C) 2004 Mauricio Julio Fernández Pradier
3 # See LICENSE.txt for additional licensing information.
12 require 'rubygems/digest/md5'
13 require 'rubygems/security'
14 require 'rubygems/specification'
16 # Wrapper for FileUtils meant to provide logging and additional operations if
18 class Gem::FileOperations
20 def initialize(logger = nil)
24 def method_missing(meth, *args, &block)
26 when FileUtils.respond_to?(meth)
27 @logger.log "#{meth}: #{args}" if @logger
28 FileUtils.send meth, *args, &block
29 when Gem::FileOperations.respond_to?(meth)
30 @logger.log "#{meth}: #{args}" if @logger
31 Gem::FileOperations.send meth, *args, &block
41 class Error < StandardError; end
42 class NonSeekableIO < Error; end
43 class ClosedIO < Error; end
44 class BadCheckSum < Error; end
45 class TooLongFileName < Error; end
46 class FormatError < Error; end
48 def self.open(io, mode = "r", signer = nil, &block)
50 when 'r' then TarInput
51 when 'w' then TarOutput
53 raise "Unknown Package open mode"
56 tar_type.open(io, signer, &block)
59 def self.pack(src, destname, signer = nil)
60 TarOutput.open(destname, signer) do |outp|
61 dir_class.chdir(src) do
62 outp.metadata = (file_class.read("RPA/metadata") rescue nil)
63 find_class.find('.') do |entry|
65 when file_class.file?(entry)
66 entry.sub!(%r{\./}, "")
67 next if entry =~ /\ARPA\//
68 stat = File.stat(entry)
69 outp.add_file_simple(entry, stat.mode, stat.size) do |os|
70 file_class.open(entry, "rb") do |f|
71 os.write(f.read(4096)) until f.eof?
74 when file_class.dir?(entry)
75 entry.sub!(%r{\./}, "")
76 next if entry == "RPA"
77 outp.mkdir(entry, file_class.stat(entry).mode)
79 raise "Don't know how to pack this yet!"
88 require 'rubygems/package/f_sync_dir'
89 require 'rubygems/package/tar_header'
90 require 'rubygems/package/tar_input'
91 require 'rubygems/package/tar_output'
92 require 'rubygems/package/tar_reader'
93 require 'rubygems/package/tar_reader/entry'
94 require 'rubygems/package/tar_writer'