Sha256: afd399a8ada413d89b8b890320fbcac2758a0642faef979fec9a8f3d1183a7eb

Contents?: true

Size: 1.14 KB

Versions: 17

Compression:

Stored size: 1.14 KB

Contents

require 'open-uri'

module BagIt
  
  module Fetch
    
    def fetch_txt_file
      File.join @bag_dir, 'fetch.txt'
    end

    def add_remote_file(url, path, size, sha1, md5)
      open(fetch_txt_file, 'a') { |io| io.puts "#{url} #{size || '-'} #{path}" }
      open(manifest_file('sha1'), 'a') { |io| io.puts "#{sha1} #{File.join 'data', path}" }
      open(manifest_file('md5'), 'a') { |io| io.puts "#{md5} #{File.join 'data', path}" }
    end

    # feth all remote files
    def fetch!

      open(fetch_txt_file) do |io|
        
        io.readlines.each do |line|
          
          (url, length, path) = line.chomp.split(/\s+/, 3)
          
          add_file(path) do |io|
            io.write open(url)
          end
          
        end
        
      end

      # rename the old fetch.txt
      Dir["#{fetch_txt_file}.?*"].sort.reverse.each do |f|
        
        if f =~ /fetch.txt.(\d+)$/
          new_f = File.join File.dirname(f), "fetch.txt.#{$1.to_i + 1}"
          FileUtils::mv f, new_f
        end
        
      end

      # move the current fetch_txt
      FileUtils::mv fetch_txt_file, "#{fetch_txt_file}.0"
    end
    
  end
  
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
bagit-0.4.2 lib/bagit/fetch.rb
bagit-0.4.1 lib/bagit/fetch.rb
bagit-0.4.0 lib/bagit/fetch.rb
bagit-0.3.5 lib/bagit/fetch.rb
bagit-0.3.4 lib/bagit/fetch.rb
flazz-bagit-0.0.1 lib/bagit/fetch.rb
flazz-bagit-0.0.2 lib/bagit/fetch.rb
bagit-0.3.2 lib/bagit/fetch.rb
bagit-0.3.2.pre lib/bagit/fetch.rb
bagit-0.3.1 lib/bagit/fetch.rb
bagit-0.3.0 lib/bagit/fetch.rb
bagit-0.3.0.pre lib/bagit/fetch.rb
bagit-0.2.0 lib/bagit/fetch.rb
bagit-0.1.0 lib/bagit/fetch.rb
bagit-0.0.4 lib/bagit/fetch.rb
bagit-0.0.3 lib/bagit/fetch.rb
bagit-0.0.2 lib/bagit/fetch.rb