@@ -33,20 +33,6 @@ use regex::Regex;
3333use crate :: init_operator;
3434use crate :: DataOperator ;
3535
36- pub struct FileWithMeta {
37- pub path : String ,
38- pub metadata : Metadata ,
39- }
40-
41- impl FileWithMeta {
42- fn new ( path : & str , meta : Metadata ) -> Self {
43- Self {
44- path : path. to_string ( ) ,
45- metadata : meta,
46- }
47- }
48- }
49-
5036#[ derive( serde:: Serialize , serde:: Deserialize , Clone , Debug , PartialEq , Eq ) ]
5137pub enum StageFileStatus {
5238 NeedCopy ,
@@ -79,11 +65,10 @@ impl StageFileInfo {
7965 creator : None ,
8066 }
8167 }
82- }
8368
84- impl From < FileWithMeta > for StageFileInfo {
85- fn from ( value : FileWithMeta ) -> Self {
86- StageFileInfo :: new ( value . path , & value . metadata )
69+ /// NOTE: update this query when add new meta
70+ pub fn meta_query ( ) -> flagset :: FlagSet < Metakey > {
71+ Metakey :: ContentLength | Metakey :: ContentMd5 | Metakey :: LastModified | Metakey :: Etag
8772 }
8873}
8974
@@ -122,7 +107,7 @@ impl StageFilesInfo {
122107 }
123108 }
124109
125- pub async fn list ( & self , operator : & Operator , first_only : bool ) -> Result < Vec < FileWithMeta > > {
110+ pub async fn list ( & self , operator : & Operator , first_only : bool ) -> Result < Vec < StageFileInfo > > {
126111 if let Some ( files) = & self . files {
127112 let mut res = Vec :: new ( ) ;
128113 for file in files {
@@ -132,7 +117,7 @@ impl StageFilesInfo {
132117 . to_string ( ) ;
133118 let meta = operator. stat ( & full_path) . await ?;
134119 if meta. mode ( ) . is_file ( ) {
135- res. push ( FileWithMeta :: new ( & full_path, meta) )
120+ res. push ( StageFileInfo :: new ( full_path, & meta) )
136121 } else {
137122 return Err ( ErrorCode :: BadArguments ( format ! (
138123 "{full_path} is not a file"
@@ -149,15 +134,15 @@ impl StageFilesInfo {
149134 }
150135 }
151136
152- pub async fn first_file ( & self , operator : & Operator ) -> Result < FileWithMeta > {
137+ pub async fn first_file ( & self , operator : & Operator ) -> Result < StageFileInfo > {
153138 let mut files = self . list ( operator, true ) . await ?;
154139 match files. pop ( ) {
155140 None => Err ( ErrorCode :: BadArguments ( "no file found" ) ) ,
156141 Some ( f) => Ok ( f) ,
157142 }
158143 }
159144
160- pub fn blocking_first_file ( & self , operator : & Operator ) -> Result < FileWithMeta > {
145+ pub fn blocking_first_file ( & self , operator : & Operator ) -> Result < StageFileInfo > {
161146 let mut files = self . blocking_list ( operator, true ) ?;
162147 match files. pop ( ) {
163148 None => Err ( ErrorCode :: BadArguments ( "no file found" ) ) ,
@@ -169,7 +154,7 @@ impl StageFilesInfo {
169154 & self ,
170155 operator : & Operator ,
171156 first_only : bool ,
172- ) -> Result < Vec < FileWithMeta > > {
157+ ) -> Result < Vec < StageFileInfo > > {
173158 if let Some ( files) = & self . files {
174159 let mut res = Vec :: new ( ) ;
175160 for file in files {
@@ -179,7 +164,7 @@ impl StageFilesInfo {
179164 . to_string ( ) ;
180165 let meta = operator. blocking ( ) . stat ( & full_path) ?;
181166 if meta. mode ( ) . is_file ( ) {
182- res. push ( FileWithMeta :: new ( & full_path, meta) )
167+ res. push ( StageFileInfo :: new ( full_path, & meta) )
183168 } else {
184169 return Err ( ErrorCode :: BadArguments ( format ! (
185170 "{full_path} is not a file"
@@ -201,11 +186,11 @@ impl StageFilesInfo {
201186 path : & str ,
202187 pattern : Option < Regex > ,
203188 first_only : bool ,
204- ) -> Result < Vec < FileWithMeta > > {
189+ ) -> Result < Vec < StageFileInfo > > {
205190 let root_meta = operator. stat ( path) . await ;
206191 match root_meta {
207192 Ok ( meta) => match meta. mode ( ) {
208- EntryMode :: FILE => return Ok ( vec ! [ FileWithMeta :: new( path, meta) ] ) ,
193+ EntryMode :: FILE => return Ok ( vec ! [ StageFileInfo :: new( path. to_string ( ) , & meta) ] ) ,
209194 EntryMode :: DIR => { }
210195 EntryMode :: Unknown => {
211196 return Err ( ErrorCode :: BadArguments ( "object mode is unknown" ) ) ;
@@ -224,10 +209,9 @@ impl StageFilesInfo {
224209 let mut files = Vec :: new ( ) ;
225210 let mut list = operator. scan ( path) . await ?;
226211 while let Some ( obj) = list. try_next ( ) . await ? {
227- // todo(youngsofun): not always need Metakey::Complete
228- let meta = operator. metadata ( & obj, Metakey :: Complete ) . await ?;
212+ let meta = operator. metadata ( & obj, StageFileInfo :: meta_query ( ) ) . await ?;
229213 if check_file ( obj. path ( ) , meta. mode ( ) , & pattern) {
230- files. push ( FileWithMeta :: new ( obj. path ( ) , meta) ) ;
214+ files. push ( StageFileInfo :: new ( obj. path ( ) . to_string ( ) , & meta) ) ;
231215 if first_only {
232216 return Ok ( files) ;
233217 }
@@ -253,13 +237,13 @@ fn blocking_list_files_with_pattern(
253237 path : & str ,
254238 pattern : Option < Regex > ,
255239 first_only : bool ,
256- ) -> Result < Vec < FileWithMeta > > {
240+ ) -> Result < Vec < StageFileInfo > > {
257241 let operator = operator. blocking ( ) ;
258242
259243 let root_meta = operator. stat ( path) ;
260244 match root_meta {
261245 Ok ( meta) => match meta. mode ( ) {
262- EntryMode :: FILE => return Ok ( vec ! [ FileWithMeta :: new( path, meta) ] ) ,
246+ EntryMode :: FILE => return Ok ( vec ! [ StageFileInfo :: new( path. to_string ( ) , & meta) ] ) ,
263247 EntryMode :: DIR => { }
264248 EntryMode :: Unknown => return Err ( ErrorCode :: BadArguments ( "object mode is unknown" ) ) ,
265249 } ,
@@ -277,9 +261,9 @@ fn blocking_list_files_with_pattern(
277261 let list = operator. list ( path) ?;
278262 for obj in list {
279263 let obj = obj?;
280- let meta = operator. metadata ( & obj, Metakey :: Complete ) ?;
264+ let meta = operator. metadata ( & obj, StageFileInfo :: meta_query ( ) ) ?;
281265 if check_file ( obj. path ( ) , meta. mode ( ) , & pattern) {
282- files. push ( FileWithMeta :: new ( obj. path ( ) , meta) ) ;
266+ files. push ( StageFileInfo :: new ( obj. path ( ) . to_string ( ) , & meta) ) ;
283267 if first_only {
284268 return Ok ( files) ;
285269 }
0 commit comments