Skip to content
This repository was archived by the owner on Jan 1, 2024. It is now read-only.

Commit 4f5bd9c

Browse files
author
Justin Langhorst
committed
Use Dir.tmpdir in place of hardcoded /var/tmp for state files
On non-windows systems, /var/tmp is used as a hard-coded path for the default state file. Use Dir.tmpdir instead. The path can still be overridden using #UUID::state_file=
1 parent e39f719 commit 4f5bd9c

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

README.rdoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ first used by the application, to prevent multiple processes from
6262
generating the same set of identifiers, and deal with changes to the
6363
system clock.
6464

65-
The UUID state file is created in <tt>/var/tmp/ruby-uuid</tt> or the Windows
65+
The UUID state file is created in <tt>#Dir.tmpdir/ruby-uuid</tt> or the Windows
6666
common application data directory using mode 0644. If that directory is not
6767
writable, the file is created as <tt>.ruby-uuid</tt> in the home directory.
6868
If you need to create the file with a different mode, use UUID#state_file

lib/uuid.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def self.server=(address)
146146
end
147147

148148
##
149-
# Creates an empty state file in /var/tmp/ruby-uuid or the windows common
149+
# Creates an empty state file in #Dir.tmpdir/ruby-uuid or the windows common
150150
# application data directory using mode 0644. Call with a different mode
151151
# before creating a UUID generator if you want to open access beyond your
152152
# user by default.
@@ -169,7 +169,7 @@ def self.state_file(mode = 0644)
169169

170170
state_dir = File.join(path.strip)
171171
rescue LoadError
172-
state_dir = File.join('', 'var', 'tmp')
172+
state_dir = Dir.tmpdir
173173
end
174174

175175
@state_file = File.join(state_dir, 'ruby-uuid')

test/test-uuid.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_state_file_specify
3939

4040
def test_mode_is_set_on_state_file_specify
4141
UUID.class_eval{ @state_file = nil; @mode = nil }
42-
path = File.join("/tmp", "ruby-uuid-test")
42+
path = File.join(Dir.tmpdir, "ruby-uuid-test")
4343
File.delete path if File.exist?(path)
4444

4545
UUID.state_file = path

0 commit comments

Comments
 (0)