@@ -169,30 +169,23 @@ impl Uri {
169
169
}
170
170
171
171
/// 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
- ///
176
172
/// Does not apply to PostgreSQL URIs.
177
173
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 > {
191
174
if self . protocol ( ) . is_database ( ) {
192
175
return None ;
193
176
}
194
177
let path = self . path ( ) ;
195
178
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
+ }
196
189
let parent_path = path. parent ( ) ?;
197
190
198
191
Some ( Self {
@@ -604,23 +597,11 @@ mod tests {
604
597
"ram:///foo"
605
598
) ;
606
599
assert ! ( Uri :: for_test( "s3://bucket" ) . parent( ) . is_none( ) ) ;
607
- assert_eq ! (
608
- Uri :: for_test( "s3://bucket" ) . parent_unchecked( ) . unwrap( ) ,
609
- "s3://"
610
- ) ;
611
600
assert ! ( Uri :: for_test( "s3://bucket/" ) . parent( ) . is_none( ) ) ;
612
- assert_eq ! (
613
- Uri :: for_test( "s3://bucket/" ) . parent_unchecked( ) . unwrap( ) ,
614
- "s3://"
615
- ) ;
616
601
assert_eq ! (
617
602
Uri :: for_test( "s3://bucket/foo" ) . parent( ) . unwrap( ) ,
618
603
"s3://bucket"
619
604
) ;
620
- assert_eq ! (
621
- Uri :: for_test( "s3://bucket/foo" ) . parent_unchecked( ) . unwrap( ) ,
622
- "s3://bucket"
623
- ) ;
624
605
assert_eq ! (
625
606
Uri :: for_test( "s3://bucket/foo/" ) . parent( ) . unwrap( ) ,
626
607
"s3://bucket"
0 commit comments