Skip to content

Commit d7aeec3

Browse files
committed
handles deleting an existing checksum.md5 file before generating a new one
1 parent f860ab4 commit d7aeec3

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

lib/stage/generate_checksums.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ def run(agenda)
1616
@bar.steps = shipment.objid_directories.count
1717
shipment.objid_directories.each_with_index do |dir, i|
1818
@bar.step! i, dir
19+
remove_existing_checksum_file(dir)
1920
ChecksumFileGenerator.write(dir)
2021
end
2122
end
23+
24+
private
25+
26+
def remove_existing_checksum_file(dir)
27+
checksum_file_path = File.join(dir, "checksum.md5")
28+
FileUtils.rm_f(checksum_file_path) if File.exist?(checksum_file_path)
29+
end
2230
end

spec/stage/generate_checksums_spec.rb

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,33 @@
1212

1313
describe GenerateChecksums do
1414
include_context "uses temp dir"
15-
it "does something" do
16-
barcode = "39015002231713"
17-
shipment_path = "#{temp_dir_path}/test_shipment"
18-
item_path = "#{shipment_path}/#{barcode}"
15+
let(:barcode) { "39015002231713" }
16+
let(:shipment_path) { "#{temp_dir_path}/test_shipment" }
17+
let(:item_path) { "#{shipment_path}/#{barcode}" }
18+
let(:shipment) { Shipment.new(shipment_path) }
19+
subject do
20+
described_class.new(shipment, config: Config.new({no_progress: true}))
21+
end
22+
23+
def set_up_shipment
1924
FileUtils.mkdir_p(item_path)
2025
FileUtils.cp("spec/fixtures/10_10_8_400.jp2", item_path)
26+
end
27+
28+
it "creates a checksum file" do
29+
set_up_shipment
30+
31+
subject.run!
32+
checksum_contents = File.read(File.join(item_path, "checksum.md5"))
33+
expect(checksum_contents).to include(" 10_10_8_400.jp2")
34+
end
2135

22-
shipment = Shipment.new(shipment_path)
23-
stage = described_class.new(shipment)
24-
stage.run!
36+
it "original checksum file is removed before calculating checksum" do
37+
set_up_shipment
38+
FileUtils.touch("#{item_path}/checksum.md5")
39+
subject.run!
2540
checksum_contents = File.read(File.join(item_path, "checksum.md5"))
2641
expect(checksum_contents).to include(" 10_10_8_400.jp2")
42+
expect(checksum_contents).not_to include(" checksum.md5")
2743
end
2844
end

0 commit comments

Comments
 (0)