Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions app/lib/otis/log_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,31 @@ def imgsrv_logs

# @return String the destination path to log file that was transferred
def transfer_log(source_path:, destination_directory:)
File.join(destination_directory, File.basename(source_path)).tap do |destination|
cmd = <<~RCLONE.gsub(/\s+/, " ").strip
rclone
--config #{rclone_config_path}
copyto
#{File.join("ulib-logs:/ulib-logs/archive", source_path)}
#{destination}
RCLONE
`#{cmd}`
# Try the path that lsjson returned to us
destination = File.join(destination_directory, File.basename(source_path))
success = system(rclone_copyto_command(source_path: source_path, destination: destination))
if !success && !source_path.end_with?(".gz")
# Didn't get it? If we asked for plain text and the file got gzipped while we were
# not looking, ask for it again but gzipped this time.
destination += ".gz"
# Ignore the return since the absence of the requested file will indicate that
# an error has occurred.
system(rclone_copyto_command(source_path: source_path + ".gz", destination: destination))
end
destination
end

private

def rclone_copyto_command(source_path:, destination:)
<<~RCLONE.gsub(/\s+/, " ").strip
rclone
--config #{rclone_config_path}
--error-on-no-transfer
copyto
#{File.join("ulib-logs:/ulib-logs/archive", source_path)}
#{destination}
RCLONE
end
end
end
12 changes: 12 additions & 0 deletions spec/lib/otis/log_transfer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,17 @@
expect(File.exist?(destination)).to eq(true)
expect(File.size(destination)).to be > 0
end

it "transfers a gzipped version if we asked for the pre-gzipped version" do
# Get the log that has a gzip suffix and strip it.
source = transfer.imgsrv_logs.find do |log|
log["Path"].end_with?(".gz")
end["Path"].sub(/\.gz$/, "")
# Ask for that nonexistent file
destination = transfer.transfer_log(source_path: source, destination_directory: @tmpdir)
expect(File.exist?(destination)).to eq(true)
expect(destination.end_with?(".gz")).to eq(true)
expect(File.size(destination)).to be > 0
end
end
end