image_optim 0.27.0 → 0.27.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2761c4a4a3488017b46d04acf157daa592537169ea05fcbeaf865928b0457618
4
- data.tar.gz: 89c7fbe11f6b99cf3f1e8c4f3336fd122c1b16afd71fd56b1d0cbd6ab88c52c1
3
+ metadata.gz: b8d7c83b1d36f1cb0c41866cf421a8477632c43137749f2011b2520854de859d
4
+ data.tar.gz: 3030f2377d510cc964025e3497dfb2bc860bd560fa88e33acc97e3caaa56614c
5
5
  SHA512:
6
- metadata.gz: facf38c901cbbd1ba0b8222637845b2e96dc8491e4a55b20a779be53e9ff6e14e561b2ab056aa9182205dd96df20ed0b25c8d8b5a1b3ebe721344ef5384bc7fc
7
- data.tar.gz: f2d2f1d4179cce616a1024445d8a30b15367a4a156a0a085fa0d8b177f38e44aaff930788b90de6e8226e7b4c022eb1877794aceee5e62cd7e7c1153554238e3
6
+ metadata.gz: 3df3a7cd3606e03dc16fd7aed023e40f61e5c4b688707a39240cc67b5432b9705fbb2c33df9ec8a1da96e4408d7a5270b6a181415647e53c686565f45b5c2bd4
7
+ data.tar.gz: b19684e4d13d29e6ac52e3ba5cddb38a6716f9acfae9946962ab45582a38e49c6c42018387d66e75a5f52d7153e12cf4a9e9dc10388f6d36bd4834d5a5e78ee0
@@ -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)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'image_optim'
5
- s.version = '0.27.0'
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
- dst.temp_path_with_tmp_ext(tmpdir || dst.dirname) do |temp|
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)
@@ -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
- rename(dst.to_s)
57
- else
58
- dst.temp_path_with_tmp_ext(dst.dirname) do |temp|
59
- move(temp)
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' if strip
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' if 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(:src){ CachePath.temp_file_path }
16
- let(:dst){ CachePath.temp_file_path }
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
@@ -23,10 +23,11 @@ describe ImageOptim do
23
23
  stub_const('Cmd', ImageOptim::Cmd)
24
24
  end
25
25
 
26
- isolated_options_base = {:skip_missing_workers => false}
27
- ImageOptim::Worker.klasses.each do |klass|
28
- isolated_options_base[klass.bin_sym] = false
29
- end
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.0
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-08-27 00:00:00.000000000 Z
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.0
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