lib/geminabox/proxy/splicer.rb in geminabox-0.13.3 vs lib/geminabox/proxy/splicer.rb in geminabox-0.13.4
- old
+ new
@@ -1,6 +1,7 @@
require 'tempfile'
+require 'fileutils'
module Geminabox
module Proxy
class Splicer < FileHandler
@@ -9,20 +10,19 @@
splicer.create
splicer
end
def create
- data = new_content
- return nil if data.nil?
- begin
- tmp = Tempfile.new('geminabox')
- File.open(tmp, 'w'){|f| f.write(data)}
- rescue
- return nil
+ if data = new_content
+ f = Tempfile.create('geminabox')
+ begin
+ f.write(data)
+ ensure
+ f.close rescue nil
+ end
+ FileUtils.mv f.path, splice_path
end
-
- FileUtils.mv tmp, splice_path
end
def new_content
if local_file_exists?
merge_content
@@ -55,10 +55,14 @@
/\.gz$/ =~ file_name
end
private
def merge_gziped_content
- package(unpackage(local_content) | unpackage(remote_content))
+ if rc = remote_content
+ package(unpackage(local_content) | unpackage(rc))
+ else
+ local_content
+ end
end
def unpackage(content)
Marshal.load(Gem.gunzip(content))
end