From 1aabb62f46264fe501d3bdb088f7164c86f5bc58 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sun, 15 Dec 2024 05:38:55 -0800 Subject: [PATCH] check for directories, fail appropriately --- src/python/tests/test_pairwise.py | 10 ++++++++++ src/utils/mod.rs | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/python/tests/test_pairwise.py b/src/python/tests/test_pairwise.py index 1a940043..cfb4849a 100644 --- a/src/python/tests/test_pairwise.py +++ b/src/python/tests/test_pairwise.py @@ -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") diff --git a/src/utils/mod.rs b/src/utils/mod.rs index b416ac73..5674d13d 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -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; @@ -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) {