Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental beginnings of a FIFO IOMethod.
- Loading branch information
tailor
committed
Feb 14, 2008
1 parent
351c6c9
commit 4a4ab42
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class LiveConsole::IOMethods::FifoIO | ||
DefaultOpts = { | ||
:remove? => false, # If the file exists, should we remove it? | ||
:user => nil, # User to give file ownership to | ||
:mode => 0600, # The file's mode | ||
}.freeze | ||
RequiredOpts = DefaultOpts.keys + [:filename] | ||
|
||
def start | ||
maybe_remove! | ||
if check_file | ||
make_fifo | ||
else | ||
raise Errno::EEXIST, "File exists; either remove it or pass " \ | ||
":remove? => true to LiveConsole.new." | ||
end | ||
end | ||
|
||
include LiveConsole::IOMethods::IOMethod | ||
private | ||
|
||
def maybe_remove! | ||
if !check_file && remove? | ||
File.unlink(filename) | ||
end | ||
end | ||
|
||
# Returns true if we can create the file. | ||
def check_file | ||
!File.exist?(filename) | ||
end | ||
end |