Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

download! method doesn't close file

オープン
#518 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
ruby
領域
devops

調査の方向性

download! の実装から始めて、Tempfile がどのように扱われているかを追跡します。Issue にある逐次的なダウンロード/読み取りの例を再現し、その後、ダウンロード直後の読み取りに対するカバレッジを追加または更新します。完了の条件は、呼び出し元がファイルを閉じなくても、読み取りで一貫して完全な内容が得られることです。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Ruby
スター
1.2k
フォーク
256
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

capistrano/sshkit のほかの issue

capistrano/sshkit の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。