os_nodetype: open fd with O_NONBLOCK (#5515)

Closes #5267

Helped-by: oni-link <knil.ino@gmail.com>
This commit is contained in:
Justin M. Keyes 2016-10-21 22:03:01 +02:00 committed by GitHub
parent 82f30bfeda
commit 1ff162c0d9
2 changed files with 39 additions and 10 deletions

View File

@ -163,7 +163,11 @@ int os_nodetype(const char *name)
// saves us the hassle.
int nodetype = NODE_WRITABLE;
int fd = os_open(name, O_RDONLY, 0);
int fd = os_open(name, O_RDONLY
#ifdef O_NONBLOCK
| O_NONBLOCK
#endif
, 0);
switch (uv_guess_handle(fd)) {
case UV_TTY: // FILE_TYPE_CHAR
nodetype = NODE_WRITABLE;

View File

@ -1,20 +1,26 @@
-- Specs for :write
local helpers = require('test.functional.helpers')(after_each)
local eq, eval, clear, write_file, execute, source =
local eq, eval, clear, write_file, execute, source, insert =
helpers.eq, helpers.eval, helpers.clear, helpers.write_file,
helpers.execute, helpers.source
helpers.execute, helpers.source, helpers.insert
if helpers.pending_win32(pending) then return end
describe(':write', function()
after_each(function()
local function cleanup()
os.remove('test_bkc_file.txt')
os.remove('test_bkc_link.txt')
os.remove('test_fifo')
end
before_each(function()
clear()
cleanup()
end)
after_each(function()
cleanup()
end)
it('&backupcopy=auto preserves symlinks', function()
clear('--cmd', 'set backupcopy=auto')
execute('set backupcopy=auto')
write_file('test_bkc_file.txt', 'content0')
execute("silent !ln -s test_bkc_file.txt test_bkc_link.txt")
source([[
@ -27,7 +33,7 @@ describe(':write', function()
end)
it('&backupcopy=no replaces symlink with new file', function()
clear('--cmd', 'set backupcopy=no')
execute('set backupcopy=no')
write_file('test_bkc_file.txt', 'content0')
execute("silent !ln -s test_bkc_file.txt test_bkc_link.txt")
source([[
@ -38,4 +44,23 @@ describe(':write', function()
eq(eval("['content0']"), eval("readfile('test_bkc_file.txt')"))
eq(eval("['content1']"), eval("readfile('test_bkc_link.txt')"))
end)
it("appends FIFO file", function()
if eval("executable('mkfifo')") == 0 then
pending('missing "mkfifo" command', function()end)
return
end
local text = "some fifo text from write_spec"
assert(os.execute("mkfifo test_fifo"))
insert(text)
-- Blocks until a consumer reads the FIFO.
execute("write >> test_fifo")
-- Read the FIFO, this will unblock the :write above.
local fifo = assert(io.open("test_fifo"))
eq(text.."\n", fifo:read("*all"))
fifo:close()
end)
end)