]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/trace.rb
api06: simplify exception handling and add exception handling to the diff
[rails.git] / app / models / trace.rb
index fef9983ddd69a74189c9d06bda8fde80f7af45b0..0e9e7bcc1598df1ffd54f447f18afa75d6fbae1a 100644 (file)
@@ -145,23 +145,25 @@ class Trace < ActiveRecord::Base
     tarred = filetype =~ /tar archive/
 
     if gzipped or bzipped or zipped or tarred then
     tarred = filetype =~ /tar archive/
 
     if gzipped or bzipped or zipped or tarred then
-      file = Tempfile.new("trace.#{id}");
+      tmpfile = Tempfile.new("trace.#{id}");
 
       if tarred and gzipped then
 
       if tarred and gzipped then
-        system("tar -zxOf #{trace_name} > #{file.path}")
+        system("tar -zxOf #{trace_name} > #{tmpfile.path}")
       elsif tarred and bzipped then
       elsif tarred and bzipped then
-        system("tar -jxOf #{trace_name} > #{file.path}")
+        system("tar -jxOf #{trace_name} > #{tmpfile.path}")
       elsif tarred
       elsif tarred
-        system("tar -xOf #{trace_name} > #{file.path}")
+        system("tar -xOf #{trace_name} > #{tmpfile.path}")
       elsif gzipped
       elsif gzipped
-        system("gunzip -c #{trace_name} > #{file.path}")
+        system("gunzip -c #{trace_name} > #{tmpfile.path}")
       elsif bzipped
       elsif bzipped
-        system("bunzip2 -c #{trace_name} > #{file.path}")
+        system("bunzip2 -c #{trace_name} > #{tmpfile.path}")
       elsif zipped
       elsif zipped
-        system("unzip -p #{trace_name} > #{file.path}")
+        system("unzip -p #{trace_name} > #{tmpfile.path}")
       end
 
       end
 
-      file.unlink
+      tmpfile.unlink
+
+      file = tmpfile.file
     else
       file = File.open(trace_name)
     end
     else
       file = File.open(trace_name)
     end
@@ -189,6 +191,7 @@ class Trace < ActiveRecord::Base
       if first
         f_lat = point['latitude']
         f_lon = point['longitude']
       if first
         f_lat = point['latitude']
         f_lon = point['longitude']
+        first = false
       end
 
       tp = Tracepoint.new
       end
 
       tp = Tracepoint.new