mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge #7140 'os_stat: return ENOENT on NULL fname'
This commit is contained in:
commit
de1084f3c4
@ -2570,11 +2570,9 @@ buf_write (
|
|||||||
perm = -1;
|
perm = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else /* win32 */
|
#else // win32
|
||||||
/*
|
// Check for a writable device name.
|
||||||
* Check for a writable device name.
|
c = fname == NULL ? NODE_OTHER : os_nodetype((char *)fname);
|
||||||
*/
|
|
||||||
c = os_nodetype((char *)fname);
|
|
||||||
if (c == NODE_OTHER) {
|
if (c == NODE_OTHER) {
|
||||||
SET_ERRMSG_NUM("E503", _("is not a file or writable device"));
|
SET_ERRMSG_NUM("E503", _("is not a file or writable device"));
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -2594,9 +2592,8 @@ buf_write (
|
|||||||
if (overwriting) {
|
if (overwriting) {
|
||||||
os_fileinfo((char *)fname, &file_info_old);
|
os_fileinfo((char *)fname, &file_info_old);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif /* !UNIX */
|
#endif // !UNIX
|
||||||
|
|
||||||
if (!device && !newfile) {
|
if (!device && !newfile) {
|
||||||
/*
|
/*
|
||||||
|
@ -605,8 +605,11 @@ int os_fsync(int fd)
|
|||||||
///
|
///
|
||||||
/// @return libuv return code.
|
/// @return libuv return code.
|
||||||
static int os_stat(const char *name, uv_stat_t *statbuf)
|
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;
|
uv_fs_t request;
|
||||||
int result = uv_fs_stat(&fs_loop, &request, name, NULL);
|
int result = uv_fs_stat(&fs_loop, &request, name, NULL);
|
||||||
*statbuf = request.statbuf;
|
*statbuf = request.statbuf;
|
||||||
@ -618,7 +621,6 @@ static int os_stat(const char *name, uv_stat_t *statbuf)
|
|||||||
///
|
///
|
||||||
/// @return libuv error code on error.
|
/// @return libuv error code on error.
|
||||||
int32_t os_getperm(const char *name)
|
int32_t os_getperm(const char *name)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
|
||||||
{
|
{
|
||||||
uv_stat_t statbuf;
|
uv_stat_t statbuf;
|
||||||
int stat_result = os_stat(name, &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
|
/// @return `true` if `path` exists
|
||||||
bool os_path_exists(const char_u *path)
|
bool os_path_exists(const char_u *path)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
|
||||||
{
|
{
|
||||||
uv_stat_t statbuf;
|
uv_stat_t statbuf;
|
||||||
return os_stat((char *)path, &statbuf) == kLibuvSuccess;
|
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.
|
/// @param[out] file_info Pointer to a FileInfo to put the information in.
|
||||||
/// @return `true` on success, `false` for failure.
|
/// @return `true` on success, `false` for failure.
|
||||||
bool os_fileinfo(const char *path, FileInfo *file_info)
|
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;
|
return os_stat(path, &(file_info->stat)) == kLibuvSuccess;
|
||||||
}
|
}
|
||||||
|
@ -862,6 +862,11 @@ describe('fs.c', function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe('os_fileinfo', function()
|
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()
|
itp('returns false if given a non-existing file', function()
|
||||||
local file_info = file_info_new()
|
local file_info = file_info_new()
|
||||||
assert.is_false((fs.os_fileinfo('/non-existent', file_info)))
|
assert.is_false((fs.os_fileinfo('/non-existent', file_info)))
|
||||||
|
Loading…
Reference in New Issue
Block a user