From 2120f4c2a94335b08f3ee9b6454d7061473edbd5 Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Sun, 9 Apr 2017 03:10:32 +0200 Subject: [PATCH] set mode of cache files to 0666 & ~umask, related to #147 --- lib/image_optim/cache.rb | 1 + spec/image_optim/cache_spec.rb | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lib/image_optim/cache.rb b/lib/image_optim/cache.rb index 4e062e57..7387311a 100644 --- a/lib/image_optim/cache.rb +++ b/lib/image_optim/cache.rb @@ -34,6 +34,7 @@ def fetch(original) if optimized tmp = FSPath.temp_file_path(digest, @cache_dir) FileUtils.mv(optimized, tmp) + tmp.chmod(0o666 & ~File.umask) tmp.rename(cached) cached_path = CachePath.convert(cached) diff --git a/spec/image_optim/cache_spec.rb b/spec/image_optim/cache_spec.rb index 07b5ab4f..0167e1f8 100644 --- a/spec/image_optim/cache_spec.rb +++ b/spec/image_optim/cache_spec.rb @@ -72,6 +72,9 @@ expect(FileUtils).to receive(:mv).with(optimized, tmp_file) expect(tmp_file).to receive(:rename).with(cached) + allow(File).to receive(:umask).and_return(0o024) + expect(tmp_file).to receive(:chmod).with(0o642) + expect(cache.fetch(original){ optimized }).to eq(cached) end