Skip to content

Commit

Permalink
Added fs::try_stat()
Browse files Browse the repository at this point in the history
  • Loading branch information
snej committed Jul 28, 2024
1 parent ae1181f commit a28e0d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 7 additions & 1 deletion include/crouton/io/Filesystem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//

#pragma once
#include "crouton/Result.hh"
#include "crouton/Generator.hh"

namespace crouton::io {
Expand Down Expand Up @@ -87,7 +88,12 @@ namespace crouton::io::fs {
};

/// Returns all the metadata for the item at that path.
statBuf stat(const char* path, bool followSymlink =true);
Result<statBuf> try_stat(const char* path, bool followSymlink =true);

/// Returns all the metadata for the item at that path.
inline statBuf stat(const char* path, bool followSymlink =true) {
return try_stat(path, followSymlink).value();
}

/// Returns all the metadata for an open file.
statBuf fstat(FileStream const&);
Expand Down
8 changes: 5 additions & 3 deletions src/io/uv/Filesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,17 @@ namespace crouton::io::fs {
return result;
}

statBuf stat(const char* path, bool followSymlink) {
Result<statBuf> try_stat(const char* path, bool followSymlink) {
fs_request req;
int err;
if (followSymlink)
err = uv_fs_stat(curLoop(), &req, path, nullptr);
else
err = uv_fs_lstat(curLoop(), &req, path, nullptr);
check(err, "stat");
return copyStatBuf(req);
if (err == 0)
return copyStatBuf(req);
else
return Error(UVError(err));
}


Expand Down

0 comments on commit a28e0d8

Please sign in to comment.