aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2016-05-22 15:31:03 -0400
committerJustin M. Keyes <justinkz@gmail.com>2016-05-22 15:31:03 -0400
commita441356858a458708eb556b4b4ea6a0b29e09f00 (patch)
treef924ff7fddda743d4ed21db35f4a668e44defd42
parent849d61b5510b3a3449c2664cb5a702126a2f6e8b (diff)
parent96f834a8424e889c274273080954c9711f1c9acc (diff)
downloadrneovim-a441356858a458708eb556b4b4ea6a0b29e09f00.tar.gz
rneovim-a441356858a458708eb556b4b4ea6a0b29e09f00.tar.bz2
rneovim-a441356858a458708eb556b4b4ea6a0b29e09f00.zip
Merge pull request #4806 from justinmk/nodetype
os_nodetype: Return NODE_NORMAL if os_stat fails.
-rw-r--r--src/nvim/os/fs.c4
-rw-r--r--test/unit/os/fs_spec.lua19
2 files changed, 18 insertions, 5 deletions
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index 49a74cf0d1..143a7160b0 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -111,8 +111,8 @@ int os_nodetype(const char *name)
#endif
uv_stat_t statbuf;
- if (os_stat(name, &statbuf) == 0) {
- return NODE_NORMAL;
+ if (0 != os_stat(name, &statbuf)) {
+ return NODE_NORMAL; // File doesn't exist.
}
#ifndef WIN32
diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua
index 71b5e7f576..857a5001f1 100644
--- a/test/unit/os/fs_spec.lua
+++ b/test/unit/os/fs_spec.lua
@@ -14,6 +14,8 @@ local to_cstr = helpers.to_cstr
local OK = helpers.OK
local FAIL = helpers.FAIL
local NULL = helpers.NULL
+local NODE_NORMAL = 0
+local NODE_WRITABLE = 1
cimport('unistd.h')
cimport('./src/nvim/os/shell.h')
@@ -357,15 +359,12 @@ describe('fs function', function()
local function os_file_exists(filename)
return fs.os_file_exists((to_cstr(filename)))
end
-
local function os_rename(path, new_path)
return fs.os_rename((to_cstr(path)), (to_cstr(new_path)))
end
-
local function os_remove(path)
return fs.os_remove((to_cstr(path)))
end
-
local function os_open(path, flags, mode)
return fs.os_open((to_cstr(path)), flags, mode)
end
@@ -484,6 +483,20 @@ describe('fs function', function()
assert.is_true(0 <= (os_open(existing_file, ffi.C.kO_RDWR, 0)))
end)
end)
+
+ describe('os_nodetype', function()
+ before_each(function()
+ os.remove('non-existing-file')
+ end)
+
+ it('returns NODE_NORMAL for non-existing file', function()
+ eq(NODE_NORMAL, fs.os_nodetype(to_cstr('non-existing-file')))
+ end)
+
+ it('returns NODE_WRITABLE for /dev/stderr', function()
+ eq(NODE_WRITABLE, fs.os_nodetype(to_cstr('/dev/stderr')))
+ end)
+ end)
end)
describe('folder operations', function()