rubyw_helper 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ require 'exception_string'
3
3
 
4
4
  class RubywHelper
5
5
 
6
- Version = VERSION = '0.1.4'
6
+ Version = VERSION = '0.1.5'
7
7
  def self.version; Version; end
8
8
 
9
9
  app_name = File.basename($0)
@@ -28,8 +28,26 @@ class RubywHelper
28
28
  @old_out, @old_err, @old_in = $stdout, $stderr, $stdin
29
29
  end
30
30
 
31
+ # Returns true for the two common cases when you would not receive data from
32
+ # stdout, stderr and stdin, because they're nulled out in some way, closed,
33
+ # or in some other way unusable. This specific implementation provides
34
+ # checks for rubyw.exe behavior, where all IOs are closed, and Win32::Daemon
35
+ # behavior, where they're all nulled.
36
+ # Sometimes may not be accurate, recommendation is to redirect by
37
+ # configuration, and use this as a guide only where appropriate.
31
38
  def stdio_danger?
32
- $stdout.closed? && $stderr.closed? && $stdin.closed?
39
+ # rubyw.exe running as a user:
40
+ $stdout.closed? && $stderr.closed? && $stdin.closed? ||
41
+ # rubyw.exe + Win32::Daemon started:
42
+ [$stdout, $stderr, $stdin].all? { |io| io.inspect =~ /NUL/ } ||
43
+ # rubyw.exe running as SYSTEM, pre Win32::Daemon started:
44
+ begin
45
+ open("CONIN$") {}
46
+ open("CONOUT$", "w") {}
47
+ false
48
+ rescue SystemCallError
49
+ true
50
+ end
33
51
  end
34
52
 
35
53
  # Takes a block, because under these conditions, it really helps developers
@@ -69,7 +87,10 @@ class RubywHelper
69
87
  fatal! "Cannot read from #{@stdin}" unless File.readable? @stdin
70
88
  [@stdout, @stderr].each do |f|
71
89
  dir = File.dirname(f)
72
- safely { FileUtils.mkdir_p(dir) unless File.directory?(dir) }
90
+ safely do
91
+ FileUtils.mkdir_p(dir) unless File.directory?(dir)
92
+ open(f, 'w') {} unless File.exists?(f)
93
+ end
73
94
  next if File.writable? f
74
95
  fatal! "Cannot write to #{f}"
75
96
  end
@@ -27,6 +27,18 @@ describe "RubywHelper" do
27
27
  $stdout, $stderr, $stdin = STDOUT, STDERR, STDIN
28
28
  end
29
29
 
30
+ should "have stdio_danger? when stdout, stderr, and stdin are all nulled" do
31
+ $stdout, $stderr, $stdin = Array.new(3) do
32
+ s = StringIO.new('')
33
+ def s.inspect
34
+ '#<IO:NUL>'
35
+ end
36
+ s
37
+ end
38
+ RubywHelper.new.stdio_danger?.should.eql true
39
+ $stdout, $stderr, $stdin = STDOUT, STDERR, STDIN
40
+ end
41
+
30
42
  should "restore the old stdios" do
31
43
  oout, oerr, oin = $stdout, $stderr, $stdin
32
44
  h = RubywHelper.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyw_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Tucker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-16 00:00:00 +00:00
12
+ date: 2009-01-19 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency