A platform for community discussion. Free, open, simple.
FIX: Avoid infinite loop if disk space is low
David Taylore3a9a2d2ddac
diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rbindex 92d48bd3016..d4ec97ac640 100644--- a/lib/cooked_post_processor.rb+++ b/lib/cooked_post_processor.rb@@ -627,7 +627,7 @@ class CookedPostProcessordef pull_hotlinked_images(bypass_bump = false)# have we enough disk space?- return if disable_if_low_on_disk_space+ disable_if_low_on_disk_space # But still enqueue the job# don't download remote images for posts that are more than n days oldreturn unless @post.created_at > (Date.today - SiteSetting.download_remote_images_max_days_old)# we only want to run the job whenever it's changed by a user@@ -640,6 +640,7 @@ class CookedPostProcessorenddef disable_if_low_on_disk_space+ return false if !SiteSetting.download_remote_images_to_localreturn false if available_disk_space >= SiteSetting.download_remote_images_thresholdSiteSetting.download_remote_images_to_local = falsediff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rbindex 43203da4413..b5c83c1f90e 100644--- a/spec/components/cooked_post_processor_spec.rb+++ b/spec/components/cooked_post_processor_spec.rb@@ -1094,10 +1094,10 @@ describe CookedPostProcessor doSiteSetting.download_remote_images_to_local = trueend- it "does not run when there is not enough disk space" do- cpp.expects(:disable_if_low_on_disk_space).returns(true)- Jobs.expects(:cancel_scheduled_job).never+ it "disables download_remote_images if there is not enough disk space" do+ cpp.expects(:available_disk_space).returns(5)cpp.pull_hotlinked_images+ expect(SiteSetting.download_remote_images_to_local).to eq(false)endcontext "and there is enough disk space" do@@ -1136,11 +1136,14 @@ describe CookedPostProcessor dolet(:post) { build(:post, created_at: 20.days.ago) }let(:cpp) { CookedPostProcessor.new(post) }- before { cpp.expects(:available_disk_space).returns(50) }+ before do+ SiteSetting.download_remote_images_to_local = true+ cpp.expects(:available_disk_space).returns(50)+ endit "does nothing when there's enough disk space" doSiteSetting.expects(:download_remote_images_threshold).returns(20)- SiteSetting.expects(:download_remote_images_to_local).never+ SiteSetting.expects(:download_remote_images_to_local=).neverexpect(cpp.disable_if_low_on_disk_space).to eq(false)end