Skip to content

Commit

Permalink
Use the status check from C++ to check for error condition
Browse files Browse the repository at this point in the history
  • Loading branch information
starseeker committed Oct 3, 2024
1 parent 7ab1d06 commit beb8a94
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/libbu/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,35 +415,47 @@ bu_file_executable(const char *path)
int
bu_file_directory(const char *path)
{
struct stat sb;
std::filesystem::file_status fs;

if (UNLIKELY(!path || (path[0] == '\0'))) {
return 0;
}

if (stat(path, &sb) == -1) {
try
{
fs = std::filesystem::status(path);
}
catch (std::filesystem::filesystem_error const &)
{
bu_log("Error: unable to get permissions for %s\n", path);
return 0;
}

bool is_symlink = std::filesystem::is_directory(std::filesystem::status(path));
return (is_symlink) ? 1 : 0;
bool is_directory = std::filesystem::is_directory(fs);
return (is_directory) ? 1 : 0;
}


int
bu_file_symbolic(const char *path)
{
struct stat sb;
std::filesystem::file_status fs;

if (UNLIKELY(!path || (path[0] == '\0'))) {
return 0;
}

if (stat(path, &sb) == -1) {
try
{
fs = std::filesystem::status(path);
}
catch (std::filesystem::filesystem_error const &)
{
bu_log("Error: unable to get permissions for %s\n", path);
return 0;
}

bool is_symlink = std::filesystem::is_symlink(std::filesystem::status(path));
bool is_symlink = std::filesystem::is_symlink(fs);
return (is_symlink) ? 1 : 0;
}

Expand Down

0 comments on commit beb8a94

Please sign in to comment.