Skip to content

Commit

Permalink
check for directories, fail appropriately
Browse files Browse the repository at this point in the history
  • Loading branch information
ctb committed Dec 15, 2024
1 parent fd66cc4 commit 1aabb62
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/python/tests/test_pairwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ def test_installed(runtmp):
assert "usage: pairwise" in runtmp.last_result.err


def test_on_dir(runtmp, capfd):
with pytest.raises(utils.SourmashCommandFailed):
runtmp.sourmash("scripts", "pairwise", runtmp.output(""),
"-o", runtmp.output('xxx.csv'))

captured = capfd.readouterr()
print(captured.err)
assert "arbitrary directories are not supported" in captured.err


def test_simple_no_ani(runtmp, capfd, zip_query, indexed):
# test basic execution!
query_list = runtmp.output("query.txt")
Expand Down
10 changes: 9 additions & 1 deletion src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize};
// use rust_decimal::{MathematicalOps, Decimal};
use std::cmp::{Ordering, PartialOrd};
use std::collections::BinaryHeap;
use std::fs::{create_dir_all, File};
use std::fs::{create_dir_all, metadata, File};
use std::io::{BufWriter, Write};
use std::panic;
use std::sync::atomic;
Expand Down Expand Up @@ -555,6 +555,14 @@ pub fn load_collection(
}
});

// we support RocksDB directory paths, but nothing else, unlike sourmash.
if collection.is_none() {
let path_metadata = metadata(sigpath.clone()).expect("getting path metadata failed");
if path_metadata.is_dir() {
bail!("arbitrary directories are not supported as input");
}
}

let collection =
collection.or_else(
|| match MultiCollection::from_standalone_manifest(&sigpath) {
Expand Down

0 comments on commit 1aabb62

Please sign in to comment.