- @trace = Trace.new({:name => name, :tagstring => tags,
- :description => description, :public => public})
- @trace.inserted = false
- @trace.user = @user
- @trace.timestamp = Time.now
+ # 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,
+ :visibility => visibility,
+ :inserted => true,
+ :user => @user,
+ :timestamp => Time.now.getutc
+ })
+
+ Trace.transaction do
+ begin
+ # Save the trace object
+ @trace.save!
+
+ # Rename the temporary file to the final name
+ FileUtils.mv(filename, @trace.trace_name)
+ rescue Exception => ex
+ # Remove the file as we have failed to update the database
+ FileUtils.rm_f(filename)
+
+ # Pass the exception on
+ raise
+ end
+
+ begin
+ # Clear the inserted flag to make the import daemon load the trace
+ @trace.inserted = false
+ @trace.save!
+ rescue Exception => ex
+ # Remove the file as we have failed to update the database
+ FileUtils.rm_f(@trace.trace_name)