Merge #7140 'os_stat: return ENOENT on NULL fname'

This commit is contained in:
Justin M. Keyes 2017-08-10 03:59:43 +02:00 committed by GitHub
commit de1084f3c4
3 changed files with 14 additions and 11 deletions

View File

@ -2570,11 +2570,9 @@ buf_write (
perm = -1;
}
}
#else /* win32 */
/*
* Check for a writable device name.
*/
c = os_nodetype((char *)fname);
#else // win32
// Check for a writable device name.
c = fname == NULL ? NODE_OTHER : os_nodetype((char *)fname);
if (c == NODE_OTHER) {
SET_ERRMSG_NUM("E503", _("is not a file or writable device"));
goto fail;
@ -2594,9 +2592,8 @@ buf_write (
if (overwriting) {
os_fileinfo((char *)fname, &file_info_old);
}
}
#endif /* !UNIX */
#endif // !UNIX
if (!device && !newfile) {
/*

View File

@ -605,8 +605,11 @@ int os_fsync(int fd)
///
/// @return libuv return code.
static int os_stat(const char *name, uv_stat_t *statbuf)
FUNC_ATTR_NONNULL_ALL
FUNC_ATTR_NONNULL_ARG(2)
{
if (!name) {
return UV_ENOENT;
}
uv_fs_t request;
int result = uv_fs_stat(&fs_loop, &request, name, NULL);
*statbuf = request.statbuf;
@ -618,7 +621,6 @@ static int os_stat(const char *name, uv_stat_t *statbuf)
///
/// @return libuv error code on error.
int32_t os_getperm(const char *name)
FUNC_ATTR_NONNULL_ALL
{
uv_stat_t statbuf;
int stat_result = os_stat(name, &statbuf);
@ -657,7 +659,6 @@ int os_fchown(int fd, uv_uid_t owner, uv_gid_t group)
///
/// @return `true` if `path` exists
bool os_path_exists(const char_u *path)
FUNC_ATTR_NONNULL_ALL
{
uv_stat_t statbuf;
return os_stat((char *)path, &statbuf) == kLibuvSuccess;
@ -847,7 +848,7 @@ int os_remove(const char *path)
/// @param[out] file_info Pointer to a FileInfo to put the information in.
/// @return `true` on success, `false` for failure.
bool os_fileinfo(const char *path, FileInfo *file_info)
FUNC_ATTR_NONNULL_ALL
FUNC_ATTR_NONNULL_ARG(2)
{
return os_stat(path, &(file_info->stat)) == kLibuvSuccess;
}

View File

@ -862,6 +862,11 @@ describe('fs.c', function()
end
describe('os_fileinfo', function()
itp('returns false if path=NULL', function()
local file_info = file_info_new()
assert.is_false((fs.os_fileinfo(nil, file_info)))
end)
itp('returns false if given a non-existing file', function()
local file_info = file_info_new()
assert.is_false((fs.os_fileinfo('/non-existent', file_info)))