From 293cf600f0ddefd6f5b1c13e69f2446cff528467 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 19 Sep 2018 15:46:23 +0800 Subject: [PATCH] FIX: Use a tmp file in `UploadRecovery` for local store. --- lib/upload_recovery.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/upload_recovery.rb b/lib/upload_recovery.rb index cc3056bf596..fba1a0073d2 100644 --- a/lib/upload_recovery.rb +++ b/lib/upload_recovery.rb @@ -90,10 +90,12 @@ class UploadRecovery @paths.each do |path| if path =~ /#{sha1}/ begin - file = File.open(path, "r") - create_upload(file, File.basename(path), post) + tmp = Tempfile.new + tmp.write(File.read(path)) + tmp.rewind + create_upload(tmp, File.basename(path), post) ensure - file&.close + tmp&.close end end end