@@ -38,15 +38,13 @@ impl<T: Clone + std::fmt::Debug> OutputTracker<T> {
3838}
3939
4040pub struct Distrobox {
41- cmd_runner : Box < dyn CommandRunner > ,
41+ cmd_runner : Rc < dyn CommandRunner > ,
4242 output_tracker : OutputTracker < String > ,
43- is_in_flatpak : bool ,
4443}
4544
4645impl std:: fmt:: Debug for Distrobox {
4746 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
4847 f. debug_struct ( "Distrobox" )
49- . field ( "is_in_flatpak" , & self . is_in_flatpak )
5048 . field ( "output_tracker" , & self . output_tracker )
5149 . finish ( )
5250 }
@@ -412,25 +410,22 @@ impl DistroboxCommandRunnerResponse {
412410}
413411
414412impl Distrobox {
415- pub fn new ( ) -> Self {
413+ pub fn new ( cmd_runner : Rc < dyn CommandRunner + ' static > ) -> Self {
416414 Self {
417- cmd_runner : Box :: new ( RealCommandRunner { } ) ,
418- is_in_flatpak : Self :: get_is_in_flatpak ( ) ,
415+ cmd_runner,
419416 output_tracker : Default :: default ( ) ,
420417 }
421418 }
422- pub fn new_null ( runner : NullCommandRunner , is_in_flatpak : bool ) -> Self {
419+ pub fn new_null ( runner : NullCommandRunner ) -> Self {
423420 Self {
424- cmd_runner : Box :: new ( runner) ,
421+ cmd_runner : Rc :: new ( runner) ,
425422 output_tracker : OutputTracker :: default ( ) ,
426- is_in_flatpak,
427423 }
428424 }
429425
430- pub fn new_null_with_responses (
426+ pub fn null_command_runner (
431427 responses : & [ DistroboxCommandRunnerResponse ] ,
432- is_in_flatpak : bool ,
433- ) -> Self {
428+ ) -> Rc < dyn CommandRunner > {
434429 let cmd_runner = {
435430 let mut builder = NullCommandRunnerBuilder :: new ( ) ;
436431 for res in responses {
@@ -440,33 +435,17 @@ impl Distrobox {
440435 }
441436 builder. build ( )
442437 } ;
443- Self {
444- cmd_runner : Box :: new ( cmd_runner) ,
445- output_tracker : OutputTracker :: default ( ) ,
446- is_in_flatpak,
447- }
438+ Rc :: new ( cmd_runner) as Rc < dyn CommandRunner >
448439 }
449440
450441 pub fn output_tracker ( & self ) -> OutputTracker < String > {
451442 self . output_tracker . enable ( ) ;
452443 self . output_tracker . clone ( )
453444 }
454445
455- fn get_is_in_flatpak ( ) -> bool {
456- let fp_env = std:: env:: var ( "FLATPAK_ID" ) . is_ok ( ) ;
457- if fp_env {
458- return true ;
459- }
460-
461- Path :: new ( "/.flatpak-info" ) . exists ( )
462- }
446+
463447
464- pub fn cmd_spawn ( & self , cmd : Command ) -> Result < Box < dyn Child + Send > , Error > {
465- let mut cmd = if self . is_in_flatpak {
466- wrap_flatpak_cmd ( cmd)
467- } else {
468- cmd
469- } ;
448+ pub fn cmd_spawn ( & self , mut cmd : Command ) -> Result < Box < dyn Child + Send > , Error > {
470449 wrap_capture_cmd ( & mut cmd) ;
471450
472451 let program = cmd. program . to_string_lossy ( ) . to_string ( ) ;
@@ -491,12 +470,7 @@ impl Distrobox {
491470 Ok ( child)
492471 }
493472
494- async fn cmd_output ( & self , cmd : Command ) -> Result < Output , Error > {
495- let mut cmd = if self . is_in_flatpak {
496- wrap_flatpak_cmd ( cmd)
497- } else {
498- cmd
499- } ;
473+ async fn cmd_output ( & self , mut cmd : Command ) -> Result < Output , Error > {
500474 wrap_capture_cmd ( & mut cmd) ;
501475
502476 let program = cmd. program . to_string_lossy ( ) . to_string ( ) ;
@@ -838,7 +812,7 @@ impl Distrobox {
838812
839813impl Default for Distrobox {
840814 fn default ( ) -> Self {
841- Self :: new ( )
815+ Self :: new ( Rc :: new ( NullCommandRunner :: default ( ) ) )
842816 }
843817}
844818
@@ -856,7 +830,6 @@ d24405b14180 | ubuntu | Created | ghcr.io/ublue-os/ubun
856830 NullCommandRunnerBuilder :: new ( )
857831 . cmd ( & [ "distrobox" , "ls" , "--no-color" ] , output)
858832 . build ( ) ,
859- false ,
860833 ) ;
861834 assert_eq ! (
862835 db. list( ) . await ?,
@@ -879,7 +852,6 @@ d24405b14180 | ubuntu | Created | ghcr.io/ublue-os/ubun
879852 NullCommandRunnerBuilder :: new ( )
880853 . cmd ( & [ "distrobox" , "version" ] , output)
881854 . build ( ) ,
882- false ,
883855 ) ;
884856 assert_eq ! ( db. version( ) . await ?, "1.7.2.1" . to_string( ) , ) ;
885857 Ok ( ( ) )
@@ -935,7 +907,6 @@ Comment=A brief description of my application
935907Categories=Utility;Network;
936908" , )
937909 . build ( ) ,
938- false
939910 ) ;
940911
941912 let apps = block_on ( db. list_apps ( "ubuntu" ) ) ?;
@@ -950,7 +921,7 @@ Categories=Utility;Network;
950921 #[ test]
951922 fn create ( ) -> Result < ( ) , Error > {
952923 let _ = tracing_subscriber:: fmt ( ) . with_test_writer ( ) . try_init ( ) ;
953- let db = Distrobox :: new_null ( NullCommandRunner :: default ( ) , false ) ;
924+ let db = Distrobox :: new_null ( NullCommandRunner :: default ( ) ) ;
954925 let output_tracker = db. output_tracker ( ) ;
955926 debug ! ( "Testing container creation" ) ;
956927 let args = CreateArgs {
@@ -969,7 +940,7 @@ Categories=Utility;Network;
969940 }
970941 #[ test]
971942 fn assemble ( ) -> Result < ( ) , Error > {
972- let db = Distrobox :: new_null ( NullCommandRunner :: default ( ) , false ) ;
943+ let db = Distrobox :: new_null ( NullCommandRunner :: default ( ) ) ;
973944 let output_tracker = db. output_tracker ( ) ;
974945 db. assemble ( "/path/to/assemble.yml" ) ?;
975946 assert_eq ! (
@@ -981,7 +952,7 @@ Categories=Utility;Network;
981952
982953 #[ test]
983954 fn remove ( ) -> Result < ( ) , Error > {
984- let db = Distrobox :: new_null ( NullCommandRunner :: default ( ) , false ) ;
955+ let db = Distrobox :: new_null ( NullCommandRunner :: default ( ) ) ;
985956 let output_tracker = db. output_tracker ( ) ;
986957 block_on ( db. remove ( "ubuntu" ) ) ?;
987958 assert_eq ! (
0 commit comments