From: Tom Hughes Date: Wed, 8 Apr 2009 13:53:09 +0000 (+0000) Subject: Merge 14059:14394 from trunk. X-Git-Tag: live~7616^2~37 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/1f8a68371ad34594cce4aadf5fef229588fd4ddc?hp=--cc Merge 14059:14394 from trunk. --- 1f8a68371ad34594cce4aadf5fef229588fd4ddc diff --cc app/controllers/trace_controller.rb index c0a0b36b5,0c4fc9e58..b52be7f34 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@@ -304,33 -293,39 +304,50 @@@ class TraceController < ApplicationCont private def do_create(file, tags, description, public) + # Sanitise the user's filename name = file.original_filename.gsub(/[^a-zA-Z0-9.]/, '_') + + # Get a temporary filename... filename = "/tmp/#{rand}" + # ...and save the uploaded file to that location File.open(filename, "w") { |f| f.write(file.read) } - @trace = Trace.new({:name => name, :tagstring => tags, - :description => description, :public => public}) - @trace.inserted = false - @trace.user = @user - @trace.timestamp = Time.now.getutc - + # Create the trace object, falsely marked as already + # inserted to stop the import daemon trying to load it + @trace = Trace.new({ + :name => name, + :tagstring => tags, + :description => description, + :public => public, + :inserted => true, + :user => @user, - :timestamp => Time.now ++ :timestamp => Time.now.getutc + }) + + # Save the trace object if @trace.save + # Rename the temporary file to the final name FileUtils.mv(filename, @trace.trace_name) + + # Clear the inserted flag to make the import daemon load the trace + @trace.inserted = false + @trace.save! else + # Remove the file as we have failed to update the database FileUtils.rm_f(filename) end + + # Finally save whether the user marked the trace as being public + if @trace.public? + if @user.trace_public_default.nil? + @user.preferences.create(:k => "gps.trace.public", :v => "default") + end + else + pref = @user.trace_public_default + pref.destroy unless pref.nil? + end + end end