Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

avoid permission conflicts, include `whoami` output in serialization …

…file names.
  • Loading branch information...
commit ed1cf75cd6f39a500b1e097bf07614a16f7574a7 1 parent 108f88f
@samg samg authored
View
8 lib/new_relic/data_serialization.rb
@@ -145,11 +145,15 @@ def create_pid_file
end
def file_path
- "#{NewRelic::Control.instance.log_path}/newrelic_agent_store.db"
+ "#{NewRelic::Control.instance.log_path}/newrelic_agent_store_#{whoami}.db"
end
def pid_file_path
- "#{NewRelic::Control.instance.log_path}/newrelic_agent_store.pid"
+ "#{NewRelic::Control.instance.log_path}/newrelic_agent_store_#{whoami}.pid"
+ end
+
+ def whoami
+ @whoami ||= `whoami`.strip
end
end
extend ClassMethods
View
15 test/new_relic/data_serialization_test.rb
@@ -7,10 +7,11 @@ class NewRelic::DataSerializationTest < Test::Unit::TestCase
def setup
NewRelic::Control.instance['log_file_path'] = './log'
@path = NewRelic::Control.instance.log_path
- @file = "#{path}/newrelic_agent_store.db"
+ @file = NewRelic::DataSerialization.send(:file_path)
+ @pid_file = NewRelic::DataSerialization.send(:pid_file_path)
Dir.mkdir(path) if !File.directory?(path)
FileUtils.rm_rf(@file)
- FileUtils.rm_rf("#{@path}/newrelic_agent_store.pid")
+ FileUtils.rm_rf(@pid_file)
end
def teardown
@@ -18,6 +19,12 @@ def teardown
NewRelic::Control.instance['disable_serialization'] = false
mocha_teardown
end
+
+ def test_file_name_includes_user_name_to_avoid_permission_conflicts
+ me = `whoami`.strip
+ assert_equal(File.basename(NewRelic::DataSerialization.send :file_path), "newrelic_agent_store_#{me}.db")
+ assert_equal(File.basename(NewRelic::DataSerialization.send :pid_file_path), "newrelic_agent_store_#{me}.pid")
+ end
def test_read_and_write_from_file_read_only
File.open(file, 'w') do |f|
@@ -142,11 +149,11 @@ def test_age_file_location_respects_log_file_path_setting
end
def test_pid_age_creates_pid_file_if_none_exists
- assert(!File.exists?("#{@path}/newrelic_agent_store.pid"),
+ assert(!File.exists?(@pid_file),
'pid file found, should not be there')
assert(!NewRelic::DataSerialization.pid_too_old?,
"new pid should not be too old")
- assert(File.exists?("#{@path}/newrelic_agent_store.pid"),
+ assert(File.exists?(@pid_file),
'pid file not found, should be there')
end
Please sign in to comment.
Something went wrong with that request. Please try again.