Module: BagIt::Fetch

Included in:
Bag
Defined in:
lib/bagit/fetch.rb

Instance Method Summary collapse

Instance Method Details

#add_remote_file(url, path, size, sha1, md5) ⇒ Object



11
12
13
14
15
# File 'lib/bagit/fetch.rb', line 11

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

#fetch!Object

feth all remote files



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bagit/fetch.rb', line 18

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

#fetch_txt_fileObject



7
8
9
# File 'lib/bagit/fetch.rb', line 7

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