lib/image_optim/path.rb in image_optim-0.27.0 vs lib/image_optim/path.rb in image_optim-0.27.1

- old
+ new

@@ -51,17 +51,17 @@ # Atomic replace dst with self def replace(dst) dst = self.class.convert(dst) if same_dev?(dst.dirname) dst.copy_metadata(self) - rename(dst.to_s) - else - dst.temp_path_with_tmp_ext(dst.dirname) do |temp| - move(temp) - dst.copy_metadata(temp) - temp.rename(dst.to_s) + begin + rename(dst.to_s) + rescue Errno::EXDEV + replace_using_tmp_file(dst) end + else + replace_using_tmp_file(dst) end end # Get format using ImageSize def image_format @@ -76,9 +76,17 @@ protected def same_dev?(other) stat.dev == other.stat.dev + end + + def replace_using_tmp_file(dst) + dst.temp_path_with_tmp_ext(dst.dirname) do |temp| + move(temp) + dst.copy_metadata(temp) + temp.rename(dst.to_s) + end end def temp_path_with_tmp_ext(*args, &block) self.class.temp_file_path([basename.to_s, '.tmp'], *args, &block) end