File tree 6 files changed +18
-0
lines changed
6 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## unreleased
4
4
5
+ * Added ` cache_dir_permissions ` option to cache results [ @nathantsoi ] ( https://github.com/nathantsoi )
6
+
5
7
## v0.24.2 (2017-02-18)
6
8
7
9
* Describe ` nice ` level option [ #140 ] ( https://github.com/toy/image_optim/issues/140 ) [ @toy ] ( https://github.com/toy )
Original file line number Diff line number Diff line change @@ -270,6 +270,7 @@ optipng:
270
270
* `:skip_missing_workers` — Skip workers with missing or problematic binaries *(defaults to `false`)*
271
271
* `:allow_lossy` — Allow lossy workers and optimizations *(defaults to `false`)*
272
272
* `:cache_dir` — Configure cache directory
273
+ * `:cache_dir_mode` — Configure cache directory permissions mode per https://apidock.com/ruby/FileUtils/chmod
273
274
* `:cache_worker_digests` - Also cache worker digests along with original file digest and worker options: updating workers invalidates cache
274
275
275
276
Worker can be disabled by passing `false` instead of options hash or by setting option `:disable` to `true`.
Original file line number Diff line number Diff line change @@ -41,6 +41,9 @@ class ImageOptim
41
41
# Cache directory
42
42
attr_reader :cache_dir
43
43
44
+ # Cache directory permissions mode per https://apidock.com/ruby/FileUtils/chmod
45
+ attr_reader :cache_dir_mode
46
+
44
47
# Cache worker digests
45
48
attr_reader :cache_worker_digests
46
49
@@ -75,6 +78,7 @@ def initialize(options = {})
75
78
skip_missing_workers
76
79
allow_lossy
77
80
cache_dir
81
+ cache_dir_mode
78
82
cache_worker_digests
79
83
] . each do |name |
80
84
instance_variable_set ( :"@#{ name } " , config . send ( name ) )
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ def fetch(original)
33
33
34
34
if optimized
35
35
tmp = FSPath . temp_file_path ( digest , @cache_dir )
36
+ FileUtils . chmod ( @cache_dir_permissions , tmp ) unless @cache_dir_permissions . nil?
36
37
FileUtils . mv ( optimized , tmp )
37
38
tmp . rename ( cached )
38
39
cached_path = CachePath . convert ( cached )
Original file line number Diff line number Diff line change @@ -153,6 +153,11 @@ def cache_dir
153
153
dir unless dir . nil? || dir . empty?
154
154
end
155
155
156
+ def cache_dir_mode
157
+ dir_mode = get! ( :cache_dir_mode )
158
+ dir_mode unless dir_mode . nil?
159
+ end
160
+
156
161
def cache_worker_digests
157
162
!!get! ( :cache_worker_digests )
158
163
end
Original file line number Diff line number Diff line change @@ -153,6 +153,11 @@ def wrap_regex(width)
153
153
options [ :cache_dir ] = cache_dir
154
154
end
155
155
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
+
156
161
op . on ( '--cache-worker-digests' , 'Cache worker digests ' \
157
162
'(updating workers invalidates cache)' ) do |cache_worker_digests |
158
163
options [ :cache_worker_digests ] = cache_worker_digests
You can’t perform that action at this time.
0 commit comments