capistrano / capistrano/sshkit

download! method doesn't close file

Open
#518 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
1.2k
Forks
257
PR merge metrics
No merged PRs in 30d

Description

which causes hard-to-debug errors when you download many files in a row and try to read the file contents immediately after downloading. It works most of the time, but at some point a downloaded file will not be flushed to disk completely when you try to read the file.

Reading only the partially written file from disk will, of course, result in corrupted file contents. I was able to avoid this behavior by explicitly closing the downloaded file before reading it again. But this was not very intuitive, so please consider closing the file within the download method.

```
tmp_file = Tempfile.new(file_name, tmp_dir)
src = File.join(dir, file_name)

download! src, tmp_file, log_percent: -1

# it's important to close the tmp file, otherwise data might not be written
# to disk already, when we try to read the file again
tmp_file.close

begin
File.read tmp_file
ensure
tmp_file.close
tmp_file.unlink
end

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.