lib/bagit/bag.rb in bagit-0.3.1 vs lib/bagit/bag.rb in bagit-0.3.2.pre

- old
+ new

@@ -60,37 +60,37 @@ path = File.join(data_dir, base_path) raise "Bag file exists: #{base_path}" if File.exist? path FileUtils::mkdir_p File.dirname(path) if src_path.nil? - f = open(path, 'w') { |io| yield io } + f = File.open(path, 'w') { |io| yield io } else f = FileUtils::cp src_path, path end write_bag_info return f end - + # Remove a bag file def remove_file(base_path) path = File.join(data_dir, base_path) raise "Bag file does not exist: #{base_path}" unless File.exist? path FileUtils::rm path end - + # Retrieve the IO handle for a file in the bag def get(base_path) path = File.join(data_dir, base_path) return nil unless File.exist?(path) File.open(path) end - + # Test if this bag is empty (no files) def empty? self.bag_files.empty? end - + # Get all bag file paths relative to the data dir def paths self.bag_files.collect { |f| f.sub(data_dir + '/', '') } end @@ -101,10 +101,10 @@ #TODO: filesystem quirks? Are we getting the stream size or the size on disk? bytes += File.size(f) end return bytes.to_s + '.' + bag_files.count.to_s end - + # Remove all empty directory trees from the bag def gc! Dir.entries(data_dir).each do |f| unless %w{.. .}.include? f abs_path = File.join data_dir, f