@@ -16,6 +16,7 @@ use tracing::info;
1616use tracing:: { debug, warn} ;
1717
1818use crate :: container:: Container ;
19+ use crate :: container_stats:: ContainerRuntime ;
1920use crate :: distrobox;
2021use crate :: distrobox:: CreateArgs ;
2122use crate :: distrobox:: Distrobox ;
@@ -126,6 +127,7 @@ mod imp {
126127 pub distrobox : OnceCell < crate :: distrobox:: Distrobox > ,
127128 pub terminal_repository : RefCell < TerminalRepository > ,
128129 pub command_runner : OnceCell < CommandRunner > ,
130+ pub container_runtime : RefCell < Option < ContainerRuntime > > ,
129131
130132 pub distrobox_version : Query < String > ,
131133 pub images_query : Query < Vec < String > > ,
@@ -152,6 +154,7 @@ mod imp {
152154 Self {
153155 containers : TypedListStore :: new ( ) ,
154156 command_runner : OnceCell :: new ( ) ,
157+ container_runtime : RefCell :: new ( None ) ,
155158 terminal_repository : RefCell :: new ( TerminalRepository :: new (
156159 CommandRunner :: new_null ( ) ,
157160 ) ) ,
@@ -668,6 +671,38 @@ impl RootStore {
668671 }
669672 }
670673 }
674+
675+ pub async fn get_container_runtime ( & self ) -> anyhow:: Result < ContainerRuntime > {
676+ if let Some ( runtime) = * self . imp ( ) . container_runtime . borrow ( ) {
677+ return Ok ( runtime) ;
678+ }
679+
680+ let runner = self . imp ( ) . command_runner . get ( ) . unwrap ( ) ;
681+ let mut cmd = Command :: new ( "podman" ) ;
682+ cmd. arg ( "--version" ) ;
683+ cmd. stdout = FdMode :: Pipe ;
684+ cmd. stderr = FdMode :: Pipe ;
685+
686+ let podman_check = runner. output ( cmd) . await ;
687+
688+ let runtime = if podman_check. is_ok ( ) && podman_check. unwrap ( ) . status . success ( ) {
689+ ContainerRuntime :: Podman
690+ } else {
691+ let mut cmd = Command :: new ( "docker" ) ;
692+ cmd. arg ( "--version" ) ;
693+ cmd. stdout = FdMode :: Pipe ;
694+ cmd. stderr = FdMode :: Pipe ;
695+ let docker_check = runner. output ( cmd) . await ;
696+ if docker_check. is_ok ( ) && docker_check. unwrap ( ) . status . success ( ) {
697+ ContainerRuntime :: Docker
698+ } else {
699+ ContainerRuntime :: Podman
700+ }
701+ } ;
702+
703+ * self . imp ( ) . container_runtime . borrow_mut ( ) = Some ( runtime) ;
704+ Ok ( runtime)
705+ }
671706}
672707
673708impl Default for RootStore {
0 commit comments