From 95742615ef31e7751663b0192a882fb7e5a9d718 Mon Sep 17 00:00:00 2001 From: "Jakob L. Kreuze" Date: Sun, 14 Jun 2020 18:56:22 -0400 Subject: Don't expose image IDs through the CLI interface. --- src/database.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/database.rs') diff --git a/src/database.rs b/src/database.rs index bd5ae65..4e33fa7 100644 --- a/src/database.rs +++ b/src/database.rs @@ -264,6 +264,11 @@ impl TagDatabase { })?) } + /// Return the `File` object for the file at `path`. + pub fn file_by_path>(&self, path: T) -> Result { + self.file_by_id(self.id_for_path(path)?) + } + /// Return the files in the database satisfying `q` and `k`. pub fn query(&self, q: &Query, k: Option) -> Result> { // Return an empty vector if the query contains tags that aren't in the @@ -433,7 +438,7 @@ mod tests { #[test] fn test_add_file_fail_on_already_indexed() { let tb = TagDatabase::new_mem().unwrap(); - let img = tb.add_file("test", &vec!["tag1"]).unwrap(); + tb.add_file("test", &vec!["tag1"]).unwrap(); assert!(tb.add_file("test", &vec!["tag2"]).is_err()); } @@ -569,6 +574,13 @@ mod tests { assert_eq!(tb.file_by_id(img.id).unwrap().path, "test1"); } + #[test] + fn test_path_resolution() { + let tb = TagDatabase::new_mem().unwrap(); + let img = tb.add_file("test1", &vec!["tag1", "tag2"]).unwrap(); + assert_eq!(tb.file_by_path(img.path).unwrap().path, "test1"); + } + #[test] fn top_tags() { let tb = TagDatabase::new_mem().unwrap(); -- cgit v1.3