@@ -34,6 +34,18 @@ fn main() {
3434 info ! ( "Successfully encoded archive in {}!" , humantime:: format_duration( start_time. elapsed( ) ) ) ;
3535 }
3636 }
37+ CliSubcommand :: List { path, recursive } => {
38+ if recursive {
39+ let archive_root = path. join ( "__brarchive" ) ;
40+ if !archive_root. exists ( ) {
41+ error ! ( "No __brarchive/ directory found in \" {}\" " , path. display( ) ) ;
42+ exit ( 1 ) ;
43+ }
44+ list_recursive ( & archive_root, & archive_root) ;
45+ } else {
46+ list_single ( & path) ;
47+ }
48+ }
3749 CliSubcommand :: Decode { path, out, recursive, delete_source } => {
3850 let start_time = Instant :: now ( ) ;
3951
@@ -265,6 +277,38 @@ fn decode_recursive(archive_root: &Path, current: &Path, out_root: &Path, delete
265277 }
266278}
267279
280+ fn list_single ( path : & Path ) {
281+ let data = fs:: read ( path) . unwrap_or_else ( |err| {
282+ error ! ( "Failed to read \" {}\" : {}" , path. display( ) , err) ;
283+ exit ( 1 ) ;
284+ } ) ;
285+ let names = brarchive:: list ( & data) . unwrap_or_else ( |err| {
286+ error ! ( "Failed to list \" {}\" : {}" , path. display( ) , err) ;
287+ exit ( 1 ) ;
288+ } ) ;
289+ for name in names {
290+ println ! ( "{}" , name) ;
291+ }
292+ }
293+
294+ fn list_recursive ( archive_root : & Path , current : & Path ) {
295+ let read_dir = fs:: read_dir ( current) . unwrap_or_else ( |err| {
296+ error ! ( "Failed to read \" {}\" : {}" , current. display( ) , err) ;
297+ exit ( 1 ) ;
298+ } ) ;
299+ for entry in read_dir {
300+ let entry = entry. unwrap_or_else ( |err| { error ! ( "{}" , err) ; exit ( 1 ) ; } ) ;
301+ let p = entry. path ( ) ;
302+ if p. is_dir ( ) {
303+ list_recursive ( archive_root, & p) ;
304+ } else if p. is_file ( ) && p. extension ( ) . and_then ( OsStr :: to_str) == Some ( "brarchive" ) {
305+ let relative = p. strip_prefix ( archive_root) . unwrap_or ( & p) ;
306+ println ! ( "{}:" , relative. display( ) ) ;
307+ list_single ( & p) ;
308+ }
309+ }
310+ }
311+
268312fn extract_file_name ( path : & Path ) -> Option < PathBuf > {
269313 path. file_stem ( ) . and_then ( OsStr :: to_str) . map ( PathBuf :: from)
270314}
0 commit comments