Skip to content

Commit 577d7ef

Browse files
committed
Improve Configuration::find to gracefully handle FUSE
See: sourcemeta/jsonschema#650 Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent ce2165f commit 577d7ef

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/configuration/configuration.cc

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
11
#include <sourcemeta/blaze/configuration.h>
22
#include <sourcemeta/core/io.h>
33

4-
#include <algorithm> // std::ranges::any_of
5-
#include <cassert> // assert
6-
#include <string> // std::string
4+
#include <algorithm> // std::ranges::any_of
5+
#include <cassert> // assert
6+
#include <string> // std::string
7+
#include <system_error> // std::error_code
78

89
namespace sourcemeta::blaze {
910

1011
auto Configuration::find(const std::filesystem::path &path)
1112
-> std::optional<std::filesystem::path> {
12-
const auto canonical{sourcemeta::core::weakly_canonical(path)};
13+
// Note we use non-throwing overloads of filesystem functions to gracefully
14+
// handle I/O errors on FUSE and other unusual filesystems
15+
std::filesystem::path canonical;
16+
try {
17+
canonical = sourcemeta::core::weakly_canonical(path);
18+
} catch (const std::filesystem::filesystem_error &) {
19+
return std::nullopt;
20+
}
21+
1322
assert(canonical.is_absolute());
14-
auto current = std::filesystem::is_directory(canonical)
23+
std::error_code error;
24+
auto current = std::filesystem::is_directory(canonical, error)
1525
? canonical
1626
: canonical.parent_path();
1727

1828
while (!current.empty()) {
1929
auto candidate = current / "jsonschema.json";
20-
if (std::filesystem::exists(candidate) &&
21-
std::filesystem::is_regular_file(candidate)) {
30+
if (std::filesystem::exists(candidate, error) &&
31+
std::filesystem::is_regular_file(candidate, error)) {
2232
return candidate;
2333
}
2434

0 commit comments

Comments
 (0)