Class: ImageOptim::CachePath

Inherits:
Path
  • Object
show all
Defined in:
lib/image_optim/cache_path.rb

Overview

ImageOptiom::Path with a non self destructing #replace method

Constant Summary

Constants inherited from Path

Path::NULL

Instance Method Summary collapse

Methods inherited from Path

convert, #copy, #copy_metadata, #image_format, #move, #temp_path

Instance Method Details

#replace(dst) ⇒ Object

Atomic replace dst with self



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/image_optim/cache_path.rb', line 9

def replace(dst)
  dst = self.class.convert(dst)
  tmpdir = [dirname, Path.new(Dir.tmpdir)].find do |dir|
    dir.same_dev?(dst.dirname)
  end
  if tmpdir
    begin
      replace_using_tmp_file(dst, tmpdir)
    rescue Errno::EXDEV
      replace_using_tmp_file(dst, dst.dirname)
    end
  else
    replace_using_tmp_file(dst, dst.dirname)
  end
end