Skip to content

Commit 8c2e32a

Browse files
committed
Remove parent unchecked
1 parent 7217822 commit 8c2e32a

File tree

1 file changed

+10
-29
lines changed
  • quickwit/quickwit-common/src

1 file changed

+10
-29
lines changed

quickwit/quickwit-common/src/uri.rs

+10-29
Original file line numberDiff line numberDiff line change
@@ -169,30 +169,23 @@ impl Uri {
169169
}
170170

171171
/// Returns the parent URI.
172-
///
173-
/// When the URI points to an object store, this method makes sure that the
174-
/// result targets to a well defined bucket, e.g `s3://` returns `None`.
175-
///
176172
/// Does not apply to PostgreSQL URIs.
177173
pub fn parent(&self) -> Option<Uri> {
178-
self.parent_unchecked().filter(|parent| {
179-
let path = parent.path();
180-
match self.protocol() {
181-
Protocol::S3 => path.components().count() >= 1,
182-
Protocol::Azure => path.components().count() >= 2,
183-
Protocol::Google => path.components().count() >= 1,
184-
_ => true,
185-
}
186-
})
187-
}
188-
189-
/// Same as [Self::parent()] but without the additional check on object stores.
190-
pub fn parent_unchecked(&self) -> Option<Uri> {
191174
if self.protocol().is_database() {
192175
return None;
193176
}
194177
let path = self.path();
195178
let protocol = self.protocol();
179+
180+
if protocol == Protocol::S3 && path.components().count() < 2 {
181+
return None;
182+
}
183+
if protocol == Protocol::Azure && path.components().count() < 3 {
184+
return None;
185+
}
186+
if protocol == Protocol::Google && path.components().count() < 2 {
187+
return None;
188+
}
196189
let parent_path = path.parent()?;
197190

198191
Some(Self {
@@ -604,23 +597,11 @@ mod tests {
604597
"ram:///foo"
605598
);
606599
assert!(Uri::for_test("s3://bucket").parent().is_none());
607-
assert_eq!(
608-
Uri::for_test("s3://bucket").parent_unchecked().unwrap(),
609-
"s3://"
610-
);
611600
assert!(Uri::for_test("s3://bucket/").parent().is_none());
612-
assert_eq!(
613-
Uri::for_test("s3://bucket/").parent_unchecked().unwrap(),
614-
"s3://"
615-
);
616601
assert_eq!(
617602
Uri::for_test("s3://bucket/foo").parent().unwrap(),
618603
"s3://bucket"
619604
);
620-
assert_eq!(
621-
Uri::for_test("s3://bucket/foo").parent_unchecked().unwrap(),
622-
"s3://bucket"
623-
);
624605
assert_eq!(
625606
Uri::for_test("s3://bucket/foo/").parent().unwrap(),
626607
"s3://bucket"

0 commit comments

Comments
 (0)