Skip to content

Commit 5abb79b

Browse files
committed
add a cache_dir_mode option to set the permission mode on the cached tmp files
1 parent 7f77946 commit 5abb79b

File tree

6 files changed

+18
-0
lines changed

6 files changed

+18
-0
lines changed

CHANGELOG.markdown

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## unreleased
44

5+
* Added `cache_dir_permissions` option to cache results [@nathantsoi](https://github.com/nathantsoi)
6+
57
## v0.24.2 (2017-02-18)
68

79
* Describe `nice` level option [#140](https://github.com/toy/image_optim/issues/140) [@toy](https://github.com/toy)

README.markdown

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ optipng:
270270
* `:skip_missing_workers` — Skip workers with missing or problematic binaries *(defaults to `false`)*
271271
* `:allow_lossy` — Allow lossy workers and optimizations *(defaults to `false`)*
272272
* `:cache_dir` — Configure cache directory
273+
* `:cache_dir_mode` — Configure cache directory permissions mode per https://apidock.com/ruby/FileUtils/chmod
273274
* `:cache_worker_digests` - Also cache worker digests along with original file digest and worker options: updating workers invalidates cache
274275

275276
Worker can be disabled by passing `false` instead of options hash or by setting option `:disable` to `true`.

lib/image_optim.rb

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class ImageOptim
4141
# Cache directory
4242
attr_reader :cache_dir
4343

44+
# Cache directory permissions mode per https://apidock.com/ruby/FileUtils/chmod
45+
attr_reader :cache_dir_mode
46+
4447
# Cache worker digests
4548
attr_reader :cache_worker_digests
4649

@@ -75,6 +78,7 @@ def initialize(options = {})
7578
skip_missing_workers
7679
allow_lossy
7780
cache_dir
81+
cache_dir_mode
7882
cache_worker_digests
7983
].each do |name|
8084
instance_variable_set(:"@#{name}", config.send(name))

lib/image_optim/cache.rb

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def fetch(original)
3333

3434
if optimized
3535
tmp = FSPath.temp_file_path(digest, @cache_dir)
36+
FileUtils.chmod(@cache_dir_permissions, tmp) unless @cache_dir_permissions.nil?
3637
FileUtils.mv(optimized, tmp)
3738
tmp.rename(cached)
3839
cached_path = CachePath.convert(cached)

lib/image_optim/config.rb

+5
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ def cache_dir
153153
dir unless dir.nil? || dir.empty?
154154
end
155155

156+
def cache_dir_mode
157+
dir_mode = get!(:cache_dir_mode)
158+
dir_mode unless dir_mode.nil?
159+
end
160+
156161
def cache_worker_digests
157162
!!get!(:cache_worker_digests)
158163
end

lib/image_optim/runner/option_parser.rb

+5
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ def wrap_regex(width)
153153
options[:cache_dir] = cache_dir
154154
end
155155

156+
op.on('--cache-dir-mode MODE', 'Cache optimized images '\
157+
'with the specified permissions mode') do |cache_dir|
158+
options[:cache_dir_mode] = cache_dir_mode
159+
end
160+
156161
op.on('--cache-worker-digests', 'Cache worker digests '\
157162
'(updating workers invalidates cache)') do |cache_worker_digests|
158163
options[:cache_worker_digests] = cache_worker_digests

0 commit comments

Comments
 (0)