barron 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/barron.gemspec +1 -1
- data/bin/barron +7 -3
- data/lib/barron.rb +1 -1
- data/lib/barron/tmpfile.rb +8 -0
- metadata +3 -3
data/barron.gemspec
CHANGED
data/bin/barron
CHANGED
@@ -34,6 +34,10 @@ opts = OptionParser.new do |opts|
|
|
34
34
|
options[:block] = true
|
35
35
|
end
|
36
36
|
|
37
|
+
opts.on("--silent", "Don't make any noise") do
|
38
|
+
options[:silent] = true
|
39
|
+
end
|
40
|
+
|
37
41
|
opts.on("--version", "Display current version") do
|
38
42
|
puts "Spinto " + Spinto::VERSION
|
39
43
|
exit 0
|
@@ -49,19 +53,19 @@ case ARGV.size
|
|
49
53
|
when 1
|
50
54
|
resource = ARGV[0]
|
51
55
|
else
|
52
|
-
puts "Invalid options. Run `barron --help` for assistance."
|
56
|
+
$stderr.puts "Invalid options. Run `barron --help` for assistance." unless options[:silent]
|
53
57
|
exit(1)
|
54
58
|
end
|
55
59
|
|
56
60
|
# Fire the lock, return success if it is free,
|
57
61
|
# or hang until it is free.
|
58
62
|
Barron.lock resource, options do
|
59
|
-
$stdout.puts "Requested resource is free."
|
63
|
+
$stdout.puts "Requested resource is free." unless options[:silent]
|
60
64
|
exit(0)
|
61
65
|
end
|
62
66
|
|
63
67
|
# Unless barron was told to hang, we will pass
|
64
68
|
# through to here when barron cannot get a lock.
|
65
69
|
# So return failue.
|
66
|
-
$stderr.puts "Requested resource is being used."
|
70
|
+
$stderr.puts "Requested resource is being used." unless options[:silent]
|
67
71
|
exit(1)
|
data/lib/barron.rb
CHANGED
data/lib/barron/tmpfile.rb
CHANGED
@@ -14,8 +14,16 @@ module Barron::Tmpfile
|
|
14
14
|
begin
|
15
15
|
if options[:block]
|
16
16
|
f.flock(File::LOCK_EX)
|
17
|
+
begin
|
18
|
+
f.chmod(0666)
|
19
|
+
rescue Errno::EPERM
|
20
|
+
end
|
17
21
|
value = yield f
|
18
22
|
elsif f.flock(File::LOCK_EX|File::LOCK_NB)
|
23
|
+
begin
|
24
|
+
f.chmod(0666)
|
25
|
+
rescue Errno::EPERM
|
26
|
+
end
|
19
27
|
value = yield f
|
20
28
|
end
|
21
29
|
ensure
|
metadata
CHANGED