Skip to content

Commit

Permalink
fix: rename files during the transfer, adding the .partial extension
Browse files Browse the repository at this point in the history
  • Loading branch information
DeboraTahara committed Mar 7, 2025
1 parent 85baa6d commit c912aec
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/syskit/roby_app/log_transfer_server/ftp_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def open
# @return [LogUploadState::Result]
def open_and_transfer(root: nil)
open { |ftp| transfer(ftp, root) }

LogUploadState::Result.new(@file, true, nil)
rescue StandardError => e
LogUploadState::Result.new(@file, false, e.message)
Expand All @@ -87,13 +88,18 @@ def chdir_to_file_directory(ftp, root)
def transfer(ftp, root)
last = Time.now
chdir_to_file_directory(ftp, root) if root
File.open(@file) do |file_io|
ftp.storbinary("STOR #{File.basename(@file)}",
file_io, Net::FTP::DEFAULT_BLOCKSIZE) do |buf|
now = Time.now
rate_limit(buf.size, now, last)
last = Time.now
begin
File.open(@file) do |file_io|
ftp.storbinary("STOR #{File.basename(@file)}",
file_io, Net::FTP::DEFAULT_BLOCKSIZE) do |buf|
now = Time.now
rate_limit(buf.size, now, last)
last = Time.now
end
end
ftp.rename("#{File.basename(@file)}.partial", File.basename(@file))
rescue StandardError => e
LogUploadState::Result.new(@file, false, e.message)
end
end

Expand Down

0 comments on commit c912aec

Please sign in to comment.