Skip to content

Commit 920e5dd

Browse files
authored
Gracefully skip non-existent collection directories (#662)
Signed-off-by: Juan Cruz Viotti <[email protected]>
1 parent 7209db9 commit 920e5dd

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

src/index/index.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ static auto index_main(const std::string_view &program,
169169
continue;
170170
}
171171

172+
if (!std::filesystem::is_directory(collection->absolute_path)) {
173+
continue;
174+
}
175+
172176
for (const auto &entry : std::filesystem::recursive_directory_iterator{
173177
collection->absolute_path}) {
174178
if (!entry.is_regular_file()) {

test/cli/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ if(ONE_INDEX)
5555
sourcemeta_one_test_cli(common index no-id)
5656
sourcemeta_one_test_cli(common index encoded-percentage)
5757
sourcemeta_one_test_cli(common index string-directory-overlap)
58+
sourcemeta_one_test_cli(common index non-existent-collection-directory)
59+
sourcemeta_one_test_cli(common index collection-path-is-file)
5860

5961
if(ONE_ENTERPRISE)
6062
sourcemeta_one_test_cli(enterprise index no-options)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
TMP="$(mktemp -d)"
7+
clean() { rm -rf "$TMP"; }
8+
trap clean EXIT
9+
10+
touch "$TMP/schemas"
11+
12+
cat << EOF > "$TMP/one.json"
13+
{
14+
"url": "http://localhost:8000",
15+
"html": false,
16+
"contents": {
17+
"example": {
18+
"baseUri": "https://example.com",
19+
"path": "./schemas"
20+
}
21+
}
22+
}
23+
EOF
24+
25+
"$1" "$TMP/one.json" "$TMP/output"
26+
27+
cd "$TMP/output"
28+
find . -mindepth 1 | LC_ALL=C sort > "$TMP/manifest.txt"
29+
cd - > /dev/null
30+
31+
cat << 'EOF' > "$TMP/expected.txt"
32+
./configuration.json
33+
./dependency-tree.metapack
34+
./dependency-tree.metapack.deps
35+
./explorer
36+
./explorer/%
37+
./explorer/%/directory.metapack
38+
./explorer/%/directory.metapack.deps
39+
./explorer/%/search.metapack
40+
./explorer/%/search.metapack.deps
41+
./routes.bin
42+
./routes.bin.deps
43+
./version.json
44+
EOF
45+
46+
diff "$TMP/manifest.txt" "$TMP/expected.txt"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
TMP="$(mktemp -d)"
7+
clean() { rm -rf "$TMP"; }
8+
trap clean EXIT
9+
10+
cat << EOF > "$TMP/one.json"
11+
{
12+
"url": "http://localhost:8000",
13+
"html": false,
14+
"contents": {
15+
"example": {
16+
"baseUri": "https://example.com",
17+
"path": "./schemas"
18+
}
19+
}
20+
}
21+
EOF
22+
23+
"$1" "$TMP/one.json" "$TMP/output"
24+
25+
cd "$TMP/output"
26+
find . -mindepth 1 | LC_ALL=C sort > "$TMP/manifest.txt"
27+
cd - > /dev/null
28+
29+
cat << 'EOF' > "$TMP/expected.txt"
30+
./configuration.json
31+
./dependency-tree.metapack
32+
./dependency-tree.metapack.deps
33+
./explorer
34+
./explorer/%
35+
./explorer/%/directory.metapack
36+
./explorer/%/directory.metapack.deps
37+
./explorer/%/search.metapack
38+
./explorer/%/search.metapack.deps
39+
./routes.bin
40+
./routes.bin.deps
41+
./version.json
42+
EOF
43+
44+
diff "$TMP/manifest.txt" "$TMP/expected.txt"

0 commit comments

Comments
 (0)