lib/entangler/entangled_file.rb in entangler-0.1.1 vs lib/entangler/entangled_file.rb in entangler-0.1.2

- old
+ new

@@ -26,10 +26,27 @@ def file_exists? File.exists?(full_path) end + def export + raise "Delta file doesn't exist when creaing patched file" unless delta_exists? + tempfile = Tempfile.new('final_file') + if File.exists?(full_path) + LibRubyDiff.patch(full_path, delta_file.path, tempfile.path) + else + temp_empty_file = Tempfile.new('empty_file') + LibRubyDiff.patch(temp_empty_file.path, delta_file.path, tempfile.path) + end + tempfile.rewind + File.open(full_path, 'w'){|f| f.write(tempfile.read)} + tempfile.close + tempfile.unlink + File.utime(File.atime(full_path), @desired_modtime, full_path) + end + + private def signature_exists? defined?(@signature_tempfile) end def signature_file @@ -75,25 +92,9 @@ @delta_tempfile.rewind end def delta delta_file.read - end - - def export - raise "Delta file doesn't exist when creaing patched file" unless delta_exists? - tempfile = Tempfile.new('final_file') - if File.exists?(full_path) - LibRubyDiff.patch(full_path, delta_file.path, tempfile.path) - else - temp_empty_file = Tempfile.new('empty_file') - LibRubyDiff.patch(temp_empty_file.path, delta_file.path, tempfile.path) - end - tempfile.rewind - File.open(full_path, 'w'){|f| f.write(tempfile.read)} - tempfile.close - tempfile.unlink - File.utime(File.atime(full_path), @desired_modtime, full_path) end def close_and_unlink_files if signature_exists? @signature_tempfile.close