libos: Support not following symlinks
This commit is contained in:
parent
cb205c851c
commit
7a8ef52408
@ -9,11 +9,11 @@ namespace os
|
|||||||
{
|
{
|
||||||
namespace FileSystem
|
namespace FileSystem
|
||||||
{
|
{
|
||||||
bool exists(const Path& path);
|
bool exists(const Path& path, bool follow_symlinks = true);
|
||||||
|
|
||||||
bool is_directory(const Path& path);
|
bool is_directory(const Path& path, bool follow_symlinks = false);
|
||||||
|
|
||||||
Result<void> stat(const Path& path, struct stat& st);
|
Result<void> stat(const Path& path, struct stat& st, bool follow_symlinks = true);
|
||||||
|
|
||||||
Result<void> create_directory(StringView path, mode_t mode);
|
Result<void> create_directory(StringView path, mode_t mode);
|
||||||
|
|
||||||
|
@ -12,28 +12,29 @@
|
|||||||
|
|
||||||
namespace os::FileSystem
|
namespace os::FileSystem
|
||||||
{
|
{
|
||||||
bool exists(const Path& path)
|
bool exists(const Path& path, bool follow_symlinks)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if (stat(path, st).has_error()) return false;
|
if (stat(path, st, follow_symlinks).has_error()) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_directory(const Path& path)
|
bool is_directory(const Path& path, bool follow_symlinks)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if (stat(path, st).has_error()) return false;
|
if (stat(path, st, follow_symlinks).has_error()) return false;
|
||||||
|
|
||||||
return S_ISDIR(st.st_mode);
|
return S_ISDIR(st.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<void> stat(const Path& path, struct stat& st)
|
Result<void> stat(const Path& path, struct stat& st, bool follow_symlinks)
|
||||||
{
|
{
|
||||||
long rc =
|
long rc =
|
||||||
syscall(SYS_fstatat, path.dirfd(), path.name().chars(), &st, path.is_empty_path() ? AT_EMPTY_PATH : 0);
|
syscall(SYS_fstatat, path.dirfd(), path.name().chars(), &st,
|
||||||
|
(int)((path.is_empty_path() ? AT_EMPTY_PATH : 0) | (follow_symlinks ? 0 : AT_SYMLINK_NOFOLLOW)));
|
||||||
|
|
||||||
return Result<void>::from_syscall(rc);
|
return Result<void>::from_syscall(rc);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user