2010-04-22 12:24:42 +04:00
|
|
|
# -*- coding: utf-8 -*-
|
2007-11-10 10:48:56 +03:00
|
|
|
#--
|
2010-04-22 12:24:42 +04:00
|
|
|
# Copyright (C) 2004 Mauricio Julio Fernández Pradier
|
|
|
|
# See LICENSE.txt for additional licensing information.
|
|
|
|
#++
|
2007-11-10 10:48:56 +03:00
|
|
|
|
|
|
|
require 'rubygems/specification'
|
|
|
|
|
|
|
|
module Gem::Package
|
|
|
|
|
|
|
|
class Error < StandardError; end
|
|
|
|
class NonSeekableIO < Error; end
|
|
|
|
class ClosedIO < Error; end
|
|
|
|
class BadCheckSum < Error; end
|
|
|
|
class TooLongFileName < Error; end
|
2011-02-01 06:11:34 +03:00
|
|
|
class FormatError < Error
|
|
|
|
attr_reader :path
|
|
|
|
|
|
|
|
def initialize message, path = nil
|
|
|
|
@path = path
|
|
|
|
|
|
|
|
message << " in #{path}" if path
|
|
|
|
|
|
|
|
super message
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Raised when a tar file is corrupt
|
|
|
|
|
|
|
|
class TarInvalidError < Error; end
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2011-06-01 07:45:05 +04:00
|
|
|
# FIX: zenspider said: does it really take an IO?
|
|
|
|
# passed to a method called open?!? that seems stupid.
|
2008-04-01 02:40:06 +04:00
|
|
|
def self.open(io, mode = "r", signer = nil, &block)
|
|
|
|
tar_type = case mode
|
|
|
|
when 'r' then TarInput
|
|
|
|
when 'w' then TarOutput
|
|
|
|
else
|
|
|
|
raise "Unknown Package open mode"
|
|
|
|
end
|
|
|
|
|
|
|
|
tar_type.open(io, signer, &block)
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.pack(src, destname, signer = nil)
|
|
|
|
TarOutput.open(destname, signer) do |outp|
|
|
|
|
dir_class.chdir(src) do
|
|
|
|
outp.metadata = (file_class.read("RPA/metadata") rescue nil)
|
|
|
|
find_class.find('.') do |entry|
|
|
|
|
case
|
|
|
|
when file_class.file?(entry)
|
|
|
|
entry.sub!(%r{\./}, "")
|
|
|
|
next if entry =~ /\ARPA\//
|
|
|
|
stat = File.stat(entry)
|
|
|
|
outp.add_file_simple(entry, stat.mode, stat.size) do |os|
|
|
|
|
file_class.open(entry, "rb") do |f|
|
|
|
|
os.write(f.read(4096)) until f.eof?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
when file_class.dir?(entry)
|
|
|
|
entry.sub!(%r{\./}, "")
|
|
|
|
next if entry == "RPA"
|
|
|
|
outp.mkdir(entry, file_class.stat(entry).mode)
|
|
|
|
else
|
|
|
|
raise "Don't know how to pack this yet!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2008-04-01 02:40:06 +04:00
|
|
|
require 'rubygems/package/f_sync_dir'
|
|
|
|
require 'rubygems/package/tar_header'
|
|
|
|
require 'rubygems/package/tar_input'
|
|
|
|
require 'rubygems/package/tar_output'
|
|
|
|
require 'rubygems/package/tar_reader'
|
|
|
|
require 'rubygems/package/tar_reader/entry'
|
|
|
|
require 'rubygems/package/tar_writer'
|
|
|
|
|