PageRenderTime 91ms CodeModel.GetById 81ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/Ruby/lib/ruby/site_ruby/1.8/rubygems/package.rb

http://github.com/agross/netopenspace
Ruby | 107 lines | 80 code | 17 blank | 10 comment | 3 complexity | 70e881b8b453e435fa7fb48086341b23 MD5 | raw file
  1# -*- coding: utf-8 -*-
  2#--
  3# Copyright (C) 2004 Mauricio Julio Fernández Pradier
  4# See LICENSE.txt for additional licensing information.
  5#++
  6
  7require 'rubygems/specification'
  8
  9##
 10# Wrapper for FileUtils meant to provide logging and additional operations if
 11# needed.
 12
 13class Gem::FileOperations
 14
 15  def initialize(logger = nil)
 16    require 'fileutils'
 17    @logger = logger
 18  end
 19
 20  def method_missing(meth, *args, &block)
 21    case
 22    when FileUtils.respond_to?(meth)
 23      @logger.log "#{meth}: #{args}" if @logger
 24      FileUtils.send meth, *args, &block
 25    when Gem::FileOperations.respond_to?(meth)
 26      @logger.log "#{meth}: #{args}" if @logger
 27      Gem::FileOperations.send meth, *args, &block
 28    else
 29      super
 30    end
 31  end
 32
 33end
 34
 35module Gem::Package
 36
 37  class Error < StandardError; end
 38  class NonSeekableIO < Error; end
 39  class ClosedIO < Error; end
 40  class BadCheckSum < Error; end
 41  class TooLongFileName < Error; end
 42  class FormatError < Error
 43    attr_reader :path
 44
 45    def initialize message, path = nil
 46      @path = path
 47
 48      message << " in #{path}" if path
 49
 50      super message
 51    end
 52
 53  end
 54
 55  ##
 56  # Raised when a tar file is corrupt
 57
 58  class TarInvalidError < Error; end
 59
 60  def self.open(io, mode = "r", signer = nil, &block)
 61    tar_type = case mode
 62               when 'r' then TarInput
 63               when 'w' then TarOutput
 64               else
 65                 raise "Unknown Package open mode"
 66               end
 67
 68    tar_type.open(io, signer, &block)
 69  end
 70
 71  def self.pack(src, destname, signer = nil)
 72    TarOutput.open(destname, signer) do |outp|
 73      dir_class.chdir(src) do
 74        outp.metadata = (file_class.read("RPA/metadata") rescue nil)
 75        find_class.find('.') do |entry|
 76          case
 77          when file_class.file?(entry)
 78            entry.sub!(%r{\./}, "")
 79            next if entry =~ /\ARPA\//
 80            stat = File.stat(entry)
 81            outp.add_file_simple(entry, stat.mode, stat.size) do |os|
 82              file_class.open(entry, "rb") do |f|
 83                os.write(f.read(4096)) until f.eof?
 84              end
 85            end
 86          when file_class.dir?(entry)
 87            entry.sub!(%r{\./}, "")
 88            next if entry == "RPA"
 89            outp.mkdir(entry, file_class.stat(entry).mode)
 90          else
 91            raise "Don't know how to pack this yet!"
 92          end
 93        end
 94      end
 95    end
 96  end
 97
 98end
 99
100require 'rubygems/package/f_sync_dir'
101require 'rubygems/package/tar_header'
102require 'rubygems/package/tar_input'
103require 'rubygems/package/tar_output'
104require 'rubygems/package/tar_reader'
105require 'rubygems/package/tar_reader/entry'
106require 'rubygems/package/tar_writer'
107