Skip to content

Commit

Permalink
Queue's umask is configurable; Task defaults to 0077
Browse files Browse the repository at this point in the history
  • Loading branch information
guns committed Sep 16, 2011
1 parent c5897fc commit 8cb14c8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lib/haus/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def execute!
end

did_archive = archive unless options.noop
old_umask = File.umask 0077
old_umask = File.umask options.umask if options.umask
fopts = { :noop => options.noop, :verbose => options.debug }

execute_deletions fopts.dup
Expand All @@ -196,8 +196,8 @@ def execute!
# Unfreeze options
@options = options.dup

# Restore original umask
File.umask old_umask
# Restore original umask if it was changed
File.umask old_umask if options.umask

# Restore default signal handlers
%w[INT TERM QUIT].each do |sig|
Expand Down
2 changes: 1 addition & 1 deletion lib/haus/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def summary

def initialize args = []
@args = args
@queue = Queue.new
@queue = Queue.new :umask => 0077
end

# Accesses Task::list entry for the current subclass
Expand Down
8 changes: 5 additions & 3 deletions lib/haus/test/queue.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -613,12 +613,14 @@ def tty_confirm?
end
end

it 'must create files with owner-only privileges, but should not change the process umask' do
it 'must create files with options.umask, but should not permanently change the process umask' do
old_umask = File.umask
@q.options.umask = 0077
@q.execute!
@targets.values_at(0..3, 6..9).each do |f|
File.lstat(f).mode.to_s(8)[/.{2}\z/].must_equal '00'
(File.lstat(f).mode & 0077).must_equal 0
end
File.umask.to_s(8)[/.{2}\z/].wont_equal '77'
File.umask.must_equal old_umask
end

it 'must freeze the options object during execution and unfreeze afterwards' do
Expand Down
5 changes: 2 additions & 3 deletions lib/haus/test/task.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ class Haus::TaskSpec < MiniTest::Spec
Haus::Noop.method(:initialize).arity.must_equal -1
Haus::Noop.new(%w[-f noprocrast]).instance_variable_get(:@args).must_equal %w[-f noprocrast]
end
end

describe :queue do
it 'must always return a Queue instance' do
it 'must initialize the @queue' do
h = Haus::Noop.new
h.queue.must_be_kind_of Haus::Queue
h.queue.options.umask.must_equal 0077
end
end

Expand Down

0 comments on commit 8cb14c8

Please sign in to comment.