Skip to content

Commit

Permalink
Merge pull request assaf#17 from blt04/create_mode
Browse files Browse the repository at this point in the history
State file mode isn't respected with standard umask
  • Loading branch information
assaf committed Sep 2, 2011
2 parents a544b50 + d6aecd8 commit de0efda
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/uuid.rb
Expand Up @@ -259,6 +259,9 @@ def initialize
fail "Cannot determine MAC address from any available interface, tried with #{mac_address}" if @mac == 0
@sequence = rand 0x10000

# Ensure the mode is respected, even with a restrictive umask
File.open(state_file, 'w') { |f| f.chmod(self.class.mode) } if state_file && !File.exists?(state_file)

if state_file
open_lock 'wb' do |io|
write_state io
Expand Down
13 changes: 13 additions & 0 deletions test/test-uuid.rb
Expand Up @@ -17,6 +17,19 @@ def test_state_file_creation
File.exist?(path)
end

def test_state_file_creation_mode
UUID.class_eval{ @state_file = nil; @mode = nil }
UUID.state_file 0666
path = UUID.state_file
File.delete path if File.exist?(path)

old_umask = File.umask(0022)
UUID.new.generate
File.umask(old_umask)

assert_equal '0666', sprintf('%04o', File.stat(path).mode & 0777)
end

def test_state_file_specify
path = File.join("path", "to", "ruby-uuid")
UUID.state_file = path
Expand Down

0 comments on commit de0efda

Please sign in to comment.