Skip to content

Commit cbd9081

Browse files
sypharjyn514
authored andcommitted
storage.exists_in_archive should return false when index doesn't exist
Currently this leads to a server error
1 parent c5d1c99 commit cbd9081

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/storage/mod.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,16 @@ impl Storage {
195195
}
196196

197197
pub(crate) fn exists_in_archive(&self, archive_path: &str, path: &str) -> Result<bool> {
198-
let index = self.get_index_for(archive_path)?;
199-
Ok(index.find_file(path).is_ok())
198+
match self.get_index_for(archive_path) {
199+
Ok(index) => Ok(index.find_file(path).is_ok()),
200+
Err(err) => {
201+
if err.downcast_ref::<PathNotFoundError>().is_some() {
202+
Ok(false)
203+
} else {
204+
Err(err)
205+
}
206+
}
207+
}
200208
}
201209

202210
pub(crate) fn get(&self, path: &str, max_size: usize) -> Result<Blob> {
@@ -724,6 +732,13 @@ mod backend_tests {
724732
Ok(())
725733
}
726734

735+
fn test_exists_without_remote_archive(storage: &Storage) -> Result<()> {
736+
// when remote and local index don't exist, any `exists_in_archive` should
737+
// return `false`
738+
assert!(!storage.exists_in_archive("some_archive_name", "some_file_name")?);
739+
Ok(())
740+
}
741+
727742
fn test_store_all_in_archive(storage: &Storage, metrics: &Metrics) -> Result<()> {
728743
let dir = tempfile::Builder::new()
729744
.prefix("docs.rs-upload-archive-test")
@@ -989,6 +1004,7 @@ mod backend_tests {
9891004
test_get_too_big,
9901005
test_delete_prefix,
9911006
test_delete_percent,
1007+
test_exists_without_remote_archive,
9921008
}
9931009

9941010
tests_with_metrics {

0 commit comments

Comments
 (0)