1
1
use super :: { metadata:: InodeMetaData , utils:: validate_and_normalize_path} ;
2
2
use crate :: auth:: user:: FileFighterUser ;
3
3
use async_trait:: async_trait;
4
+ use chrono:: NaiveDateTime ;
4
5
use filefighter_api:: ffs_api:: {
5
6
endpoints:: {
6
7
create_directory, delete_inode, download_file, get_contents_of_folder, get_inode,
@@ -14,7 +15,7 @@ use libunftp::storage::{
14
15
} ;
15
16
use std:: {
16
17
fmt:: Debug ,
17
- path:: { Path , PathBuf } ,
18
+ path:: { Component , Path , PathBuf } ,
18
19
} ;
19
20
use tokio:: io:: AsyncRead ;
20
21
use tracing:: { debug, error, instrument, warn} ;
@@ -33,18 +34,31 @@ impl StorageBackend<FileFighterUser> for FileFighter {
33
34
FEATURE_RESTART
34
35
}
35
36
37
+ /// Endpoint to request Metadata for a inode
38
+ ///
39
+ /// # Rclone
40
+ /// In some cases the path consists of /<date>/ /acutal_path.
41
+ /// This means that rclone wants to update the modification date of that inode at the path
36
42
#[ instrument( skip( self ) , level = "debug" ) ]
37
43
async fn metadata < P : AsRef < Path > + Send + Debug > (
38
44
& self ,
39
45
user : & FileFighterUser ,
40
46
path : P ,
41
47
) -> Result < Self :: Metadata > {
42
- let path = validate_and_normalize_path ( path) ?;
43
- let inode = get_inode ( & self . api_config , & path, & user. token )
44
- . await
45
- . map_err ( transform_to_ftp_error) ?;
48
+ let path = path. as_ref ( ) ;
49
+
50
+ todo ! ( )
51
+ // // rclone wants to update time
52
+ // if path_contains_rclone_modification_date(path)? {
53
+ // } else {
54
+ // // regular metadata request
55
+ // let path = validate_and_normalize_path(path)?;
56
+ // let inode = get_inode(&self.api_config, &path, &user.token)
57
+ // .await
58
+ // .map_err(transform_to_ftp_error)?;
46
59
47
- Ok ( InodeMetaData :: from ( & inode, user. id ) )
60
+ // Ok(InodeMetaData::from(&inode, user.id))
61
+ // }
48
62
}
49
63
50
64
#[ instrument( skip( self ) , level = "debug" ) ]
@@ -259,3 +273,63 @@ fn transform_to_ftp_error(error: ApiError) -> Error {
259
273
}
260
274
}
261
275
}
276
+
277
+ // IDEA: check if rclone does try to update the root folder
278
+ fn path_contains_rclone_modification_date ( path : & Path ) -> Option < ( NaiveDateTime , PathBuf ) > {
279
+ let mut components: Vec < Component > = path. components ( ) . collect ( ) ;
280
+
281
+ // needs to be at least / and date<whitespace>
282
+ if components. len ( ) < 2 {
283
+ return None ;
284
+ }
285
+
286
+ // does exist
287
+ let mut timestamp_component = components[ 1 ] . as_os_str ( ) . to_str ( ) ?. to_owned ( ) ;
288
+
289
+ #[ allow( clippy:: unwrap_used) ]
290
+ // if root path does not end with whitespace
291
+ if timestamp_component. is_empty ( ) || timestamp_component. pop ( ) . unwrap ( ) != ' ' {
292
+ return None ;
293
+ }
294
+
295
+ // the rest of the root folder needs to be in this format
296
+ // yyyymmddhhmmss
297
+ let parsed_time = NaiveDateTime :: parse_from_str ( & timestamp_component, "%Y%m%d%H%M%S" ) . ok ( ) ?;
298
+
299
+ // remove the timestamp component
300
+ components. remove ( 1 ) ;
301
+
302
+ Some ( ( parsed_time, components. iter ( ) . collect ( ) ) )
303
+ }
304
+
305
+ #[ cfg( test) ]
306
+ mod tests {
307
+ use super :: path_contains_rclone_modification_date;
308
+ use chrono:: NaiveDateTime ;
309
+ use std:: { path:: PathBuf , str:: FromStr } ;
310
+
311
+ #[ test]
312
+ fn timestamp_parsing_works ( ) {
313
+ let result = NaiveDateTime :: parse_from_str ( "20221003093709" , "%Y%m%d%H%M%S" ) . unwrap ( ) ;
314
+ let resulting_string = result. to_string ( ) ;
315
+ assert_eq ! ( "2022-10-03 09:37:09" , resulting_string)
316
+ }
317
+
318
+ #[ test]
319
+ fn path_contains_rclone_modification_date_works ( ) {
320
+ let path = PathBuf :: from_str ( "/20221003093709 /Home/School" ) . unwrap ( ) ;
321
+
322
+ let option = path_contains_rclone_modification_date ( & path) ;
323
+
324
+ match option {
325
+ Some ( result) => {
326
+ assert_eq ! (
327
+ NaiveDateTime :: parse_from_str( "20221003093709" , "%Y%m%d%H%M%S" ) . unwrap( ) ,
328
+ result. 0
329
+ ) ;
330
+ assert_eq ! ( PathBuf :: from_str( "/Home/School" ) . unwrap( ) , result. 1 ) ;
331
+ }
332
+ None => panic ! ( "Expected some value here." ) ,
333
+ }
334
+ }
335
+ }
0 commit comments