Skip to content

Commit bf33609

Browse files
author
Dave Zuckerman
committed
Lbnl processed
1 parent 7529a82 commit bf33609

4 files changed

Lines changed: 18 additions & 18 deletions

File tree

lib/berkeley_library/sftp_handler/downloader/base.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ def ssh_options
4141
end
4242
end
4343

44-
def assert_file_not_processed!(processed_path)
45-
raise "File was already processed: #{processed_path}" \
46-
if Pathname.new(processed_path).exist?
47-
end
48-
4944
def assert_not_exists!(local_path)
5045
raise "Local file already exists: #{local_path}" \
5146
if Pathname.new(local_path).exist?

lib/berkeley_library/sftp_handler/downloader/lbnl.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def download!(filename: nil, local_dir: '/opt/app/data')
1515
filename ||= default_filename
1616
remote_path = Pathname.new(filename)
1717
local_path = Pathname.new(local_dir) + filename
18-
assert_file_not_processed! local_path + '.old'
18+
assert_file_not_processed! local_path
1919
assert_not_exists! local_path
2020

2121
connect do |sftp|
@@ -25,6 +25,11 @@ def download!(filename: nil, local_dir: '/opt/app/data')
2525
end
2626
end
2727

28+
def assert_file_not_processed!(filepath)
29+
raise "File was already processed: #{filepath}" \
30+
if Pathname.glob("#{filepath}*.old").any?
31+
end
32+
2833
def default_host
2934
'ncc-1701.lbl.gov'
3035
end

spec/downloader/base_spec.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@
99
end
1010
end
1111

12-
describe '#assert_file_not_processed!' do
13-
it 'proceeds if processed file is absent' do
14-
expect { subject.assert_file_not_processed! '/path/to/non-existent-file' }.not_to raise_error
15-
end
16-
17-
it 'raises if processed file exists' do
18-
Tempfile.open do |f|
19-
expect { subject.assert_file_not_processed! f.path }.to raise_error RuntimeError
20-
end
21-
end
22-
end
23-
2412
describe '#assert_not_exists!' do
2513
it 'proceeds if file is absent' do
2614
expect { subject.assert_not_exists! '/path/to/non-existent-file' }.not_to raise_error

spec/downloader/lbnl_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'berkeley_library/sftp_handler/downloader/lbnl'
22
require 'net/sftp'
33
require 'spec_helper'
4+
require 'tempfile'
45

56
describe BerkeleyLibrary::SftpHandler::Downloader::Lbnl do
67
its(:default_host) { is_expected.to eq 'ncc-1701.lbl.gov' }
@@ -55,6 +56,17 @@
5556
end
5657
end
5758

59+
describe '#assert_file_not_processed!' do
60+
it 'proceeds if processed file is absent' do
61+
expect { subject.assert_file_not_processed!('/path/to/non-existent-file') }.not_to raise_error
62+
end
63+
64+
it 'raises if processed file exists' do
65+
f = Tempfile.new(['temp_file38348', '.old'])
66+
expect { subject.assert_file_not_processed! f.path.gsub('.old', '') }.to raise_error RuntimeError
67+
end
68+
end
69+
5870
describe '#default_filename' do
5971
context 'on Sunday May 29, 2022' do
6072
its(:default_filename) do

0 commit comments

Comments
 (0)