Skip to content

Commit bcef8f5

Browse files
committed
Switch fs.exists to use uv_fs_access
1 parent d5c9663 commit bcef8f5

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

lute/fs/src/fs.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#ifdef _WIN32
1414
#include <direct.h>
1515
#endif
16+
#ifndef _WIN32
17+
#include <unistd.h>
18+
#endif
1619
#include <fcntl.h>
1720
#include <filesystem>
1821
#include <map>
@@ -659,26 +662,20 @@ int fs_exists(lua_State* L)
659662
auto* req = new uv_fs_t();
660663
req->data = new ResumeToken(getResumeToken(L));
661664

662-
int err = uv_fs_stat(
665+
int err = uv_fs_access(
663666
uv_default_loop(),
664667
req,
665668
path,
669+
F_OK,
666670
[](uv_fs_t* req)
667671
{
668672
auto* request_state = static_cast<ResumeToken*>(req->data);
669673

670674
request_state->get()->complete(
671675
[req](lua_State* L)
672676
{
673-
if (req->result == UV_ENOENT)
674-
{
675-
lua_pushboolean(L, false); // does not exist
676-
}
677-
else
678-
{
679-
lua_pushboolean(L, true);
680-
}
681-
677+
lua_pushboolean(L, req->result == 0);
678+
682679
uv_fs_req_cleanup(req);
683680

684681
delete req;

0 commit comments

Comments
 (0)