class ImageOptim::CachePath
ImageOptiom::Path with a non self destructing replace
method
Public Instance Methods
replace(dst)
click to toggle source
Atomic replace dst with self
# 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
Private Instance Methods
replace_using_tmp_file(dst, tmpdir)
click to toggle source
# File lib/image_optim/cache_path.rb, line 27 def replace_using_tmp_file(dst, tmpdir) dst.temp_path_with_tmp_ext(tmpdir) do |temp| copy(temp) dst.copy_metadata(temp) temp.rename(dst.to_s) end end