File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11use std:: collections:: BTreeMap ;
22use std:: fmt;
33use std:: future:: Future ;
4- use std:: path:: PathBuf ;
4+ use std:: path:: { Path , PathBuf } ;
55use std:: pin:: Pin ;
66use std:: str:: FromStr ;
77use std:: sync:: Arc ;
@@ -85,6 +85,28 @@ impl SegmentKey {
8585 pub ( crate ) fn includes ( & self , frame_no : u64 ) -> bool {
8686 ( self . start_frame_no ..=self . end_frame_no ) . contains ( & frame_no)
8787 }
88+
89+ #[ tracing:: instrument]
90+ fn validate_from_path ( mut path : & Path , ns : & NamespaceName ) -> Option < Self > {
91+ // path in the form "v2/clusters/{cluster-id}/namespaces/{namespace}/indexes/{index-key}"
92+ let key: Self = path. file_name ( ) ?. to_str ( ) ?. parse ( ) . ok ( ) ?;
93+
94+ path = path. parent ( ) ?;
95+
96+ if path. file_name ( ) ? != "indexes" {
97+ tracing:: debug!( "invalid key, ignoring" ) ;
98+ return None ;
99+ }
100+
101+ path = path. parent ( ) ?;
102+
103+ if path. file_name ( ) ? != ns. as_str ( ) {
104+ tracing:: debug!( "invalid namespace for key" ) ;
105+ return None ;
106+ }
107+
108+ Some ( key)
109+ }
88110}
89111
90112impl From < & SegmentMeta > for SegmentKey {
You can’t perform that action at this time.
0 commit comments