@@ -13,18 +13,21 @@ use eldritch_core::Value;
1313#[ cfg( unix) ]
1414use nix:: unistd:: { Gid , Group , Uid , User } ;
1515#[ cfg( feature = "stdlib" ) ]
16+ use spin:: RwLock ;
17+ #[ cfg( feature = "stdlib" ) ]
1618use std:: fs;
1719#[ cfg( feature = "stdlib" ) ]
1820use std:: path:: Path ;
1921#[ cfg( feature = "stdlib" ) ]
2022use std:: sync:: Arc ;
21- #[ cfg( feature="stdlib" ) ]
22- use spin:: RwLock ;
2323#[ cfg( feature = "stdlib" ) ]
2424use std:: time:: UNIX_EPOCH ;
2525
2626#[ cfg( feature = "stdlib" ) ]
27- pub fn list ( path : Option < String > , dir_self : Option < bool > ) -> Result < Vec < BTreeMap < String , Value > > , String > {
27+ pub fn list (
28+ path : Option < String > ,
29+ dir_self : Option < bool > ,
30+ ) -> Result < Vec < BTreeMap < String , Value > > , String > {
2831 let path = path. unwrap_or_else ( || {
2932 :: std:: env:: current_dir ( )
3033 . map ( |p| p. to_string_lossy ( ) . to_string ( ) )
@@ -42,7 +45,7 @@ pub fn list(path: Option<String>, dir_self: Option<bool>) -> Result<Vec<BTreeMap
4245#[ cfg( not( feature = "stdlib" ) ) ]
4346pub fn list (
4447 _path : Option < alloc:: string:: String > ,
45- dir_self : Option < bool >
48+ dir_self : Option < bool > ,
4649) -> Result <
4750 alloc:: vec:: Vec < alloc:: collections:: BTreeMap < alloc:: string:: String , eldritch_core:: Value > > ,
4851 alloc:: string:: String ,
@@ -66,7 +69,7 @@ fn list_impl(path: String, dir_self: bool) -> AnyhowResult<Vec<BTreeMap<String,
6669 if !path_buf. is_dir ( ) || dir_self {
6770 final_res. push ( create_dict_from_file ( & path_buf) ?) ;
6871 }
69-
72+
7073 // for dir, show subcontents
7174 if path_buf. is_dir ( ) {
7275 for entry in fs:: read_dir ( & path_buf) ? {
@@ -86,35 +89,42 @@ fn list_impl(path: String, dir_self: bool) -> AnyhowResult<Vec<BTreeMap<String,
8689
8790// get the timestamps of a metadata object and return it as a dictionary
8891#[ cfg( feature = "stdlib" ) ]
89- fn get_times_dict ( metadata : std:: fs:: Metadata , mtime : std:: io:: Result < std:: time:: SystemTime > ) -> Value {
92+ fn get_times_dict (
93+ metadata : std:: fs:: Metadata ,
94+ mtime : std:: io:: Result < std:: time:: SystemTime > ,
95+ ) -> Value {
9096 // create dictionary for times data
9197 let mut times: BTreeMap < Value , Value > = BTreeMap :: new ( ) ;
9298
9399 // add changed time (it's already in epoch format) if we're in unix
94- #[ cfg( unix) ] {
100+ #[ cfg( unix) ]
101+ {
95102 use std:: os:: unix:: fs:: MetadataExt ;
96- times. insert ( Value :: String ( "changed" . to_string ( ) ) , Value :: Int ( metadata. ctime ( ) ) ) ;
103+ times. insert (
104+ Value :: String ( "changed" . to_string ( ) ) ,
105+ Value :: Int ( metadata. ctime ( ) ) ,
106+ ) ;
97107 }
98108
99109 // add time information
100110 let timestamps = [
101111 ( "modified" , mtime) ,
102112 ( "created" , metadata. created ( ) ) ,
103- ( "accessed" , metadata. accessed ( ) )
113+ ( "accessed" , metadata. accessed ( ) ) ,
104114 ] ;
105115 for timestamp_req in timestamps {
106116 // if getting the timestamp was successful, add it
107117 if let Ok ( timestamp) = timestamp_req. 1 {
108118 // convert timestamp to epoch
109119 let secs = match timestamp. duration_since ( UNIX_EPOCH ) {
110120 Ok ( duration) => duration. as_secs ( ) as i64 ,
111- Err ( err) => -( err. duration ( ) . as_secs ( ) as i64 )
121+ Err ( err) => -( err. duration ( ) . as_secs ( ) as i64 ) ,
112122 } ;
113123
114124 // add timestamp to dict
115125 times. insert ( Value :: String ( timestamp_req. 0 . to_string ( ) ) , Value :: Int ( secs) ) ;
116126 }
117- } ;
127+ }
118128
119129 // insert times section to the dictionary
120130 return Value :: Dictionary ( Arc :: new ( RwLock :: new ( times) ) ) ;
@@ -233,14 +243,14 @@ mod tests {
233243 assert ! ( f. contains_key( "absolute_path" ) ) ;
234244 assert ! ( f. contains_key( "times" ) ) ;
235245 // check times sub-dict
236- if let Value :: Dictionary ( d) = & f[ "times" ] {
237- let inner = d. read ( ) ;
246+ if let Value :: Dictionary ( d) = & f[ "times" ] {
247+ let inner = d. read ( ) ;
238248 assert ! ( inner. contains_key( & Value :: String ( "modified" . into( ) ) ) ) ;
239249 assert ! ( inner. contains_key( & Value :: String ( "accessed" . into( ) ) ) ) ;
240250 assert ! ( inner. contains_key( & Value :: String ( "created" . into( ) ) ) ) ;
241- #[ cfg( unix) ]
242- assert ! ( inner. contains_key( & Value :: String ( "changed" . into( ) ) ) ) ;
243- }
251+ #[ cfg( unix) ]
252+ assert ! ( inner. contains_key( & Value :: String ( "changed" . into( ) ) ) ) ;
253+ }
244254
245255 // check modified string
246256 assert ! ( f. contains_key( "modified" ) ) ;
0 commit comments