]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/trace.rb
Use a full path to find the file command.
[rails.git] / app / models / trace.rb
index 2d4e9ef8ab12381a92b22cd13d7ae2b2ca6b47cb..8f99e7bd8cb57bfc35954a5e8b687638d7cd0beb 100644 (file)
@@ -73,7 +73,54 @@ class Trace < ActiveRecord::Base
   end
 
   def mime_type
-    return `file -bi #{trace_name}`.chomp
+    filetype = `/usr/bin/file -bz #{trace_name}`.chomp
+    gzipped = filetype =~ /gzip compressed/
+    bzipped = filetype =~ /bzip2 compressed/
+    zipped = filetype =~ /Zip archive/
+
+    if gzipped then
+      mimetype = "application/x-gzip"
+    elsif bzipped then
+      mimetype = "application/x-bzip2"
+    elsif zipped
+      mimetype = "application/x-zip"
+    else
+      mimetype = "text/xml"
+    end
+
+    return mimetype
+  end
+
+  def extension_name
+    filetype = `/usr/bin/file -bz #{trace_name}`.chomp
+    gzipped = filetype =~ /gzip compressed/
+    bzipped = filetype =~ /bzip2 compressed/
+    zipped = filetype =~ /Zip archive/
+    tarred = filetype =~ /tar archive/
+
+    if tarred and gzipped then
+      extension = ".tar.gz"
+    elsif tarred and bzipped then
+      extension = ".tar.bz2"
+    elsif tarred
+      extension = ".tar"
+    elsif gzipped
+      extension = ".gpx.gz"
+    elsif bzipped
+      extension = ".gpx.bz2"
+    elsif zipped
+      extension = ".zip"
+    else
+      extension = ".gpx"
+    end
+
+    return extension
+  end
+
+  def to_xml
+    doc = OSM::API.new.get_xml_doc
+    doc.root << to_xml_node()
+    return doc
   end
 
   def to_xml_node
@@ -94,7 +141,7 @@ class Trace < ActiveRecord::Base
       logger.info("GPX Import importing #{name} (#{id}) from #{user.email}")
 
       # TODO *nix specific, could do to work on windows... would be functionally inferior though - check for '.gz'
-      filetype = `file -bz #{trace_name}`.chomp
+      filetype = `/usr/bin/file -bz #{trace_name}`.chomp
       gzipped = filetype =~ /gzip compressed/
       bzipped = filetype =~ /bzip2 compressed/
       zipped = filetype =~ /Zip archive/