Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #17 from blt04/create_mode

State file mode isn't respected with standard umask
  • Loading branch information...
commit de0efda18d6c07f854e93397e4af45704f59dd91 2 parents a544b50 + d6aecd8
Assaf Arkin authored
Showing with 16 additions and 0 deletions.
  1. +3 −0  lib/uuid.rb
  2. +13 −0 test/test-uuid.rb
3  lib/uuid.rb
View
@@ -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
13 test/test-uuid.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.