diff --git a/app/lib/otis/log_transfer.rb b/app/lib/otis/log_transfer.rb index bc14bfa6..78efa8df 100644 --- a/app/lib/otis/log_transfer.rb +++ b/app/lib/otis/log_transfer.rb @@ -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 diff --git a/spec/lib/otis/log_transfer_spec.rb b/spec/lib/otis/log_transfer_spec.rb index 21237308..0700f9e3 100644 --- a/spec/lib/otis/log_transfer_spec.rb +++ b/spec/lib/otis/log_transfer_spec.rb @@ -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