image_optim 0.27.0 → 0.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +4 -0
- data/image_optim.gemspec +1 -1
- data/lib/image_optim/cache_path.rb +15 -1
- data/lib/image_optim/path.rb +14 -6
- data/lib/image_optim/worker/optipng.rb +2 -2
- data/lib/image_optim/worker/pngcrush.rb +2 -2
- data/spec/image_optim/cache_path_spec.rb +22 -3
- data/spec/image_optim/path_spec.rb +15 -0
- data/spec/image_optim_spec.rb +5 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8d7c83b1d36f1cb0c41866cf421a8477632c43137749f2011b2520854de859d
|
4
|
+
data.tar.gz: 3030f2377d510cc964025e3497dfb2bc860bd560fa88e33acc97e3caaa56614c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3df3a7cd3606e03dc16fd7aed023e40f61e5c4b688707a39240cc67b5432b9705fbb2c33df9ec8a1da96e4408d7a5270b6a181415647e53c686565f45b5c2bd4
|
7
|
+
data.tar.gz: b19684e4d13d29e6ac52e3ba5cddb38a6716f9acfae9946962ab45582a38e49c6c42018387d66e75a5f52d7153e12cf4a9e9dc10388f6d36bd4834d5a5e78ee0
|
data/CHANGELOG.markdown
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## unreleased
|
4
4
|
|
5
|
+
## v0.27.1 (2020-09-30)
|
6
|
+
|
7
|
+
* Fixed atomic replacement for case when equal `File::Stat#dev` doesn't mean that file can be linked [#180](https://github.com/toy/image_optim/issues/180) [@toy](https://github.com/toy)
|
8
|
+
|
5
9
|
## v0.27.0 (2020-08-27)
|
6
10
|
|
7
11
|
* Use `.tmp` as the extension for temporary file if it needs to be created for atomic replacement [#178](https://github.com/toy/image_optim/issues/178) [@toy](https://github.com/toy)
|
data/image_optim.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'image_optim'
|
5
|
-
s.version = '0.27.
|
5
|
+
s.version = '0.27.1'
|
6
6
|
s.summary = %q{Command line tool and ruby interface to optimize (lossless compress, optionally lossy) jpeg, png, gif and svg images using external utilities (advpng, gifsicle, jhead, jpeg-recompress, jpegoptim, jpegrescan, jpegtran, optipng, pngcrush, pngout, pngquant, svgo)}
|
7
7
|
s.homepage = "https://github.com/toy/#{s.name}"
|
8
8
|
s.authors = ['Ivan Kuchin']
|
@@ -11,7 +11,21 @@ class ImageOptim
|
|
11
11
|
tmpdir = [dirname, Path.new(Dir.tmpdir)].find do |dir|
|
12
12
|
dir.same_dev?(dst.dirname)
|
13
13
|
end
|
14
|
-
|
14
|
+
if tmpdir
|
15
|
+
begin
|
16
|
+
replace_using_tmp_file(dst, tmpdir)
|
17
|
+
rescue Errno::EXDEV
|
18
|
+
replace_using_tmp_file(dst, dst.dirname)
|
19
|
+
end
|
20
|
+
else
|
21
|
+
replace_using_tmp_file(dst, dst.dirname)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def replace_using_tmp_file(dst, tmpdir)
|
28
|
+
dst.temp_path_with_tmp_ext(tmpdir) do |temp|
|
15
29
|
copy(temp)
|
16
30
|
dst.copy_metadata(temp)
|
17
31
|
temp.rename(dst.to_s)
|
data/lib/image_optim/path.rb
CHANGED
@@ -53,13 +53,13 @@ class ImageOptim
|
|
53
53
|
dst = self.class.convert(dst)
|
54
54
|
if same_dev?(dst.dirname)
|
55
55
|
dst.copy_metadata(self)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
dst.copy_metadata(temp)
|
61
|
-
temp.rename(dst.to_s)
|
56
|
+
begin
|
57
|
+
rename(dst.to_s)
|
58
|
+
rescue Errno::EXDEV
|
59
|
+
replace_using_tmp_file(dst)
|
62
60
|
end
|
61
|
+
else
|
62
|
+
replace_using_tmp_file(dst)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -80,6 +80,14 @@ class ImageOptim
|
|
80
80
|
stat.dev == other.stat.dev
|
81
81
|
end
|
82
82
|
|
83
|
+
def replace_using_tmp_file(dst)
|
84
|
+
dst.temp_path_with_tmp_ext(dst.dirname) do |temp|
|
85
|
+
move(temp)
|
86
|
+
dst.copy_metadata(temp)
|
87
|
+
temp.rename(dst.to_s)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
83
91
|
def temp_path_with_tmp_ext(*args, &block)
|
84
92
|
self.class.temp_file_path([basename.to_s, '.tmp'], *args, &block)
|
85
93
|
end
|
@@ -39,8 +39,8 @@ class ImageOptim
|
|
39
39
|
#{dst}
|
40
40
|
]
|
41
41
|
args.unshift "-i#{interlace ? 1 : 0}" unless interlace.nil?
|
42
|
-
if resolve_bin!(:optipng).version >= '0.7'
|
43
|
-
args.unshift '-strip', 'all'
|
42
|
+
if strip && resolve_bin!(:optipng).version >= '0.7'
|
43
|
+
args.unshift '-strip', 'all'
|
44
44
|
end
|
45
45
|
execute(:optipng, *args) && optimized?(src, dst)
|
46
46
|
end
|
@@ -39,8 +39,8 @@ class ImageOptim
|
|
39
39
|
end
|
40
40
|
flags.push '-fix' if fix
|
41
41
|
flags.push '-brute' if brute
|
42
|
-
if resolve_bin!(:pngcrush).version >= '1.7.38'
|
43
|
-
flags.push '-blacken'
|
42
|
+
if blacken && resolve_bin!(:pngcrush).version >= '1.7.38'
|
43
|
+
flags.push '-blacken'
|
44
44
|
end
|
45
45
|
|
46
46
|
args = flags + %W[
|
@@ -8,12 +8,14 @@ describe ImageOptim::CachePath do
|
|
8
8
|
include CapabilityCheckHelpers
|
9
9
|
|
10
10
|
before do
|
11
|
+
stub_const('Path', ImageOptim::Path)
|
11
12
|
stub_const('CachePath', ImageOptim::CachePath)
|
12
13
|
end
|
13
14
|
|
14
15
|
describe '#replace' do
|
15
|
-
let(:
|
16
|
-
let(:
|
16
|
+
let(:src_dir){ Path.temp_dir }
|
17
|
+
let(:src){ CachePath.temp_file_path(nil, src_dir) }
|
18
|
+
let(:dst){ Path.temp_file_path }
|
17
19
|
|
18
20
|
shared_examples 'replaces file' do
|
19
21
|
it 'moves data to destination' do
|
@@ -58,7 +60,7 @@ describe ImageOptim::CachePath do
|
|
58
60
|
end
|
59
61
|
|
60
62
|
it 'is using temporary file with .tmp extension' do
|
61
|
-
expect(src).to receive(:copy).with(having_attributes(:extname => '.tmp'))
|
63
|
+
expect(src).to receive(:copy).with(having_attributes(:extname => '.tmp')).at_least(:once)
|
62
64
|
|
63
65
|
src.replace(dst)
|
64
66
|
end
|
@@ -79,5 +81,22 @@ describe ImageOptim::CachePath do
|
|
79
81
|
|
80
82
|
include_examples 'replaces file'
|
81
83
|
end
|
84
|
+
|
85
|
+
context 'when src and dst are on same device, but rename causes Errno::EXDEV' do
|
86
|
+
before do
|
87
|
+
allow_any_instance_of(File::Stat).to receive(:dev).and_return(0)
|
88
|
+
allow(described_class).to receive(:temp_file_path).and_call_original
|
89
|
+
expect(described_class).to receive(:temp_file_path).
|
90
|
+
with([dst.basename.to_s, '.tmp'], src.dirname).
|
91
|
+
and_wrap_original do |m, *args, &block|
|
92
|
+
m.call(*args) do |tmp|
|
93
|
+
expect(tmp).to receive(:rename).with(dst.to_s).and_raise(Errno::EXDEV)
|
94
|
+
block.call(tmp)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
include_examples 'replaces file'
|
100
|
+
end
|
82
101
|
end
|
83
102
|
end
|
@@ -125,5 +125,20 @@ describe ImageOptim::Path do
|
|
125
125
|
src.replace(dst)
|
126
126
|
end
|
127
127
|
end
|
128
|
+
|
129
|
+
context 'when src and dst are on same device, but rename causes Errno::EXDEV' do
|
130
|
+
before do
|
131
|
+
allow_any_instance_of(File::Stat).to receive(:dev).and_return(0)
|
132
|
+
expect(src).to receive(:rename).with(dst.to_s).once.and_raise(Errno::EXDEV)
|
133
|
+
end
|
134
|
+
|
135
|
+
include_examples 'replaces file'
|
136
|
+
|
137
|
+
it 'is using temporary file with .tmp extension' do
|
138
|
+
expect(src).to receive(:move).with(having_attributes(:extname => '.tmp'))
|
139
|
+
|
140
|
+
src.replace(dst)
|
141
|
+
end
|
142
|
+
end
|
128
143
|
end
|
129
144
|
end
|
data/spec/image_optim_spec.rb
CHANGED
@@ -23,10 +23,11 @@ describe ImageOptim do
|
|
23
23
|
stub_const('Cmd', ImageOptim::Cmd)
|
24
24
|
end
|
25
25
|
|
26
|
-
isolated_options_base =
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
isolated_options_base = Hash[
|
27
|
+
ImageOptim::Worker.klasses.map do |klass|
|
28
|
+
[klass.bin_sym, false]
|
29
|
+
end
|
30
|
+
].merge(:skip_missing_workers => false)
|
30
31
|
|
31
32
|
ImageOptim::Worker.klasses.each do |worker_klass|
|
32
33
|
describe "#{worker_klass.bin_sym} worker" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_optim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.27.
|
4
|
+
version: 0.27.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Kuchin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fspath
|
@@ -269,7 +269,7 @@ licenses:
|
|
269
269
|
metadata:
|
270
270
|
bug_tracker_uri: https://github.com/toy/image_optim/issues
|
271
271
|
changelog_uri: https://github.com/toy/image_optim/blob/master/CHANGELOG.markdown
|
272
|
-
documentation_uri: https://www.rubydoc.info/gems/image_optim/0.27.
|
272
|
+
documentation_uri: https://www.rubydoc.info/gems/image_optim/0.27.1
|
273
273
|
source_code_uri: https://github.com/toy/image_optim
|
274
274
|
post_install_message: |
|
275
275
|
Rails image assets optimization is extracted into image_optim_rails gem
|