lib/buildmaster/cotta/cotta_dir.rb in BuildMaster-1.1.9 vs lib/buildmaster/cotta/cotta_dir.rb in BuildMaster-1.1.12

- old
+ new

@@ -1,12 +1,5 @@ -require 'rubygems/package' - -$:.unshift File.dirname(__FILE__) - -require 'cotta_file' -require 'io_chain' - module BuildMaster class CottaDir include IoChain attr_reader :path, :system @@ -43,11 +36,15 @@ end def parent parent_path = @path.cotta_parent return nil unless parent_path - return CottaDir.new(@system, parent_path) + candidate = CottaDir.new(@system, parent_path) + if (block_given?) + candidate = candidate.parent until candidate.nil? or yield candidate + end + candidate end def relative_path_from(entry) @path.relative_path_from(entry.path) end @@ -66,14 +63,16 @@ @system.mkdir @path end end def delete - list.each {|children| - children.delete - } - @system.delete_dir(@path) + if (exists?) + list.each {|children| + children.delete + } + @system.delete_dir(@path) + end end def move_to(target) target.parent.mkdirs @system.move_dir(@path, target.path) @@ -87,10 +86,11 @@ target.parent.mkdirs @system.copy_dir(@path, target.path) end def archive(target = nil, &block) + require 'rubygems/package' unless target target = parent.file("#{name}.tar") end target.write_binary do |io| writer = Gem::Package::TarWriter.new(io) do |tar_io| @@ -133,20 +133,24 @@ candidate = file(item) end candidate end end + + def chdir(&block) + @system.chdir(@path, &block) + end def ==(other) return @path == other.path && @system == other.system end def inspect return "#{self.class}:#{self.object_id}-#@path" end def to_s - @path + @path.to_s end end -end \ No newline at end of file +end