@@ -9,7 +9,7 @@ use std::path::PathBuf;
99use std:: str;
1010use std:: str:: FromStr ;
1111
12- use tracing:: { debug , error, info, warn} ;
12+ use tracing:: { error, info, warn} ;
1313
1414use ffs:: config:: Config ;
1515use ffs:: config:: Symlink ;
@@ -40,6 +40,12 @@ pub struct Pack {
4040 regex : Regex ,
4141}
4242
43+ impl Default for Pack {
44+ fn default ( ) -> Self {
45+ Self :: new ( )
46+ }
47+ }
48+
4349impl Pack {
4450 pub fn new ( ) -> Self {
4551 Self {
@@ -75,7 +81,7 @@ impl Pack {
7581 let mut link_follower = path. clone ( ) ;
7682 while link_follower. is_symlink ( ) {
7783 if link_trail. contains ( & link_follower) {
78- error ! ( "Symlink loop detected at {:? }." , link_follower) ;
84+ error ! ( "Symlink loop detected at {}." , link_follower. display ( ) ) ;
7985 std:: process:: exit ( ERROR_STATUS_FUSE ) ;
8086 }
8187 link_trail. push ( link_follower. clone ( ) ) ;
@@ -92,8 +98,8 @@ impl Pack {
9298 // Err(_) => {
9399 // // Cannot call xattr::get on ._ file
94100 // warn!(
95- // "._ files, like {:? }, prevent xattr calls. It will be encoded in base64.",
96- // link_follower
101+ // "._ files, like {}, prevent xattr calls. It will be encoded in base64.",
102+ // link_follower.display()
97103 // );
98104 // path_type = b"bytes".to_vec()
99105 // }
@@ -130,8 +136,8 @@ impl Pack {
130136 {
131137 // the symlink is broken, so don't pack this file.
132138 warn ! (
133- "The symlink at the end of the chain starting from '{:? }' is broken." ,
134- path
139+ "The symlink at the end of the chain starting from '{}' is broken." ,
140+ path. display ( )
135141 ) ;
136142 for link in link_trail {
137143 let symlink_map_data = & self . symlinks [ & link] ;
@@ -150,16 +156,16 @@ impl Pack {
150156 let canonicalized = link_follower. canonicalize ( ) ?;
151157 if path. starts_with ( & canonicalized) {
152158 error ! (
153- "The symlink {:? } points to some ancestor directory: {:? }, causing an infinite loop." ,
154- path, canonicalized
159+ "The symlink {} points to some ancestor directory: {}, causing an infinite loop." ,
160+ path. display ( ) , canonicalized. display ( ) ,
155161 ) ;
156162 std:: process:: exit ( ERROR_STATUS_FUSE ) ;
157163 }
158164 if !config. allow_symlink_escape
159165 && !canonicalized. starts_with ( config. mount . as_ref ( ) . unwrap ( ) )
160166 {
161- warn ! ( "The symlink {:? } points to some file outside of the directory being packed. \
162- Specify --allow-symlink-escape to allow pack to follow this symlink.", path) ;
167+ warn ! ( "The symlink {} points to some file outside of the directory being packed. \
168+ Specify --allow-symlink-escape to allow pack to follow this symlink.", path. display ( ) ) ;
163169 return Ok ( None ) ;
164170 }
165171 }
@@ -170,14 +176,14 @@ impl Pack {
170176 // none of the symlinks on the chain have an xattr. Use the actual file's xattr
171177 if path_type. is_empty ( ) {
172178 let canonicalized = path. canonicalize ( ) ?;
173- path_type = match xattr:: get ( & canonicalized, "user.type" ) {
179+ path_type = match xattr:: get ( canonicalized, "user.type" ) {
174180 Ok ( Some ( xattr_type) ) if config. allow_xattr => xattr_type,
175181 Ok ( _) => b"auto" . to_vec ( ) ,
176182 Err ( _) => {
177183 // Cannot call xattr::get on ._ file
178184 warn ! (
179- "._ files, like {:? }, prevent xattr calls. It will be encoded in base64." ,
180- path
185+ "._ files, like {}, prevent xattr calls. It will be encoded in base64." ,
186+ path. display ( ) ,
181187 ) ;
182188 b"bytes" . to_vec ( )
183189 }
@@ -191,19 +197,18 @@ impl Pack {
191197 if path. is_dir ( ) && ( path_type == "auto" || path_type != "named" && path_type != "list" ) {
192198 if path_type != "auto" {
193199 warn ! (
194- "Unknown directory type '{}'. Possible types are 'named' or 'list'. \
195- Resolving type automatically.",
196- path_type
200+ "Unknown directory type '{path_type}'. Possible types are 'named' or 'list'. \
201+ Resolving type automatically."
197202 ) ;
198203 }
199204 let all_files_begin_with_num = fs:: read_dir ( path. clone ( ) ) ?
200205 . map ( |res| res. map ( |e| e. path ( ) ) )
201206 . map ( |e| e. unwrap ( ) . file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_owned ( ) )
202207 . all ( |filename| {
203- filename. chars ( ) . nth ( 0 ) . unwrap ( ) . is_digit ( 10 )
208+ filename. chars ( ) . nth ( 0 ) . unwrap ( ) . is_ascii_digit ( )
204209 || filename. len ( ) > 1
205210 && filename. chars ( ) . nth ( 0 ) . unwrap ( ) == '-'
206- && filename. chars ( ) . nth ( 1 ) . unwrap ( ) . is_digit ( 10 )
211+ && filename. chars ( ) . nth ( 1 ) . unwrap ( ) . is_ascii_digit ( )
207212 } ) ;
208213 if all_files_begin_with_num {
209214 path_type = "list"
@@ -212,8 +217,6 @@ impl Pack {
212217 } ;
213218 }
214219
215- info ! ( "type of {:?} is {}" , path, path_type) ;
216-
217220 // return the value based on determined type
218221 match path_type {
219222 "named" => {
@@ -227,11 +230,11 @@ impl Pack {
227230 for child in & children {
228231 let child_name = child. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
229232 if config. ignored_file ( child_name) {
230- warn ! ( "skipping ignored file {:? }" , child_name ) ;
233+ warn ! ( "skipping ignored file {}" , child . display ( ) ) ;
231234 continue ;
232235 }
233236 let name: String ;
234- match xattr:: get ( & child, "user.original_name" ) {
237+ match xattr:: get ( child, "user.original_name" ) {
235238 Ok ( Some ( original_name) ) if config. allow_xattr => {
236239 let old_name = str:: from_utf8 ( & original_name) . unwrap ( ) ;
237240 if !config. valid_name ( old_name) {
@@ -250,14 +253,14 @@ impl Pack {
250253 }
251254 }
252255 self . depth += 1 ;
253- let value = self . pack ( child. clone ( ) , & config) ?;
256+ let value = self . pack ( child. clone ( ) , config) ?;
254257 self . depth -= 1 ;
255258 if let Some ( value) = value {
256259 entries. insert ( name, value) ;
257260 }
258261 }
259262
260- Ok ( Some ( V :: from_named_dir ( entries, & config) ) )
263+ Ok ( Some ( V :: from_named_dir ( entries, config) ) )
261264 }
262265 "list" => {
263266 let mut numbers_filenames_paths = fs:: read_dir ( path. clone ( ) ) ?
@@ -296,23 +299,21 @@ impl Pack {
296299 . collect :: < Vec < _ > > ( ) ;
297300 numbers_filenames_paths. sort ( ) ;
298301
299- info ! ( "parsed numbers and filenames {:?}" , numbers_filenames_paths) ;
300-
301302 let mut entries = Vec :: with_capacity ( numbers_filenames_paths. len ( ) ) ;
302303 for ( _, filename, child) in numbers_filenames_paths {
303304 if config. ignored_file ( & filename) {
304- warn ! ( "skipping ignored file {:? }" , child) ;
305+ warn ! ( "skipping ignored file {}" , child. display ( ) ) ;
305306 continue ;
306307 }
307308 self . depth += 1 ;
308- let value = self . pack ( child, & config) ?;
309+ let value = self . pack ( child, config) ?;
309310 self . depth -= 1 ;
310311 if let Some ( value) = value {
311312 entries. push ( value) ;
312313 }
313314 }
314315
315- Ok ( Some ( V :: from_list_dir ( entries, & config) ) )
316+ Ok ( Some ( V :: from_list_dir ( entries, config) ) )
316317 }
317318 typ => {
318319 if let Ok ( t) = Typ :: from_str ( typ) {
@@ -325,14 +326,13 @@ impl Pack {
325326 if config. add_newlines && contents. ends_with ( '\n' ) {
326327 contents. truncate ( contents. len ( ) - 1 ) ;
327328 }
328- Ok ( Some ( V :: from_string ( t, contents, & config) ) )
329+ Ok ( Some ( V :: from_string ( t, contents, config) ) )
329330 }
330- Ok ( _) | Err ( _) => Ok ( Some ( V :: from_bytes ( contents, & config) ) ) ,
331+ Ok ( _) | Err ( _) => Ok ( Some ( V :: from_bytes ( contents, config) ) ) ,
331332 }
332333 } else {
333334 error ! (
334- "This error should never be called. Received undetected and unknown type '{}' for file '{}'" ,
335- typ,
335+ "Received undetected and unknown type '{typ}' for file '{}'" ,
336336 path. display( )
337337 ) ;
338338 std:: process:: exit ( ERROR_STATUS_FUSE ) ;
@@ -344,12 +344,11 @@ impl Pack {
344344
345345fn main ( ) -> std:: io:: Result < ( ) > {
346346 let config = Config :: from_pack_args ( ) ;
347- debug ! ( "received config: {:?}" , config) ;
348347
349348 let mount = match & config. mount {
350349 Some ( mount) => mount,
351350 None => {
352- error ! ( "Cannot pack unspecified directory." ) ;
351+ error ! ( "You must specify a directory to pack ." ) ;
353352 std:: process:: exit ( ERROR_STATUS_CLI ) ;
354353 }
355354 } ;
0 commit comments