diff --git a/server/podman/src/lib.rs b/server/podman/src/lib.rs index 03e11ea..d0b73d6 100644 --- a/server/podman/src/lib.rs +++ b/server/podman/src/lib.rs @@ -9,7 +9,6 @@ extern crate serde_json; use nixideserver_lib::*; use rocket::http::Status; use std::fs; -use std::hash::Hash; use std::io::prelude::*; use std::path::{ Path, @@ -18,14 +17,44 @@ use std::path::{ // podman create --name test -p 3000:3000 -v $PWD:/nixide -w /nixide docker.io/nixos/nix nix-shell --pure start-ide.nix --run run_ide.sh +#[derive(Serialize, Deserialize, Clone)] +pub enum PodmanState { + Unkown, + FetchingSource, + StartingContainer, + RunningContainer, + StoppingContainer, + StoppedContainer, + DeletingContainer, + DeletingSources, +} +#[derive(Serialize, Deserialize, Clone)] +pub struct PodmanContainer{ + state : PodmanState, + ide_param : NixIdeServerParam +} + +#[derive(Serialize, Deserialize, Clone)] +pub struct PodmanContainerList{ + container : Vec +} + pub struct PodmanEngine { working_folder: PathBuf, + list : PodmanContainerList } impl PodmanEngine { pub fn new(working_folder: PathBuf) -> Self { + let list_path = format!("{}/.podman_containers", &working_folder.display()); + let list = match read_from_list_file(&list_path) { + Ok(p) => p, + _ => PodmanContainerList{container: Vec::new()} + }; + Self { working_folder, + list } } } @@ -78,7 +107,7 @@ impl NixIdeManageServiceEngine for PodmanEngine { } } -#[derive(Serialize, Deserialize, Hash)] +#[derive(Serialize, Deserialize, Clone)] pub struct NixIdeServerParam { #[serde(default = "default_listen_address")] listen_address: String, @@ -130,4 +159,12 @@ fn read_ide_state(json_string :&str) -> Result { let status: PodmanIdeStatus = serde_json::from_str(json_string)?; Ok(status.ide_state) +} + +fn read_from_list_file(path : &str) -> Result { + match fs::read_to_string(path) + { + Ok(json_string) => serde_json::from_str::(&json_string).map_err(|_| std::io::Error::from(std::io::ErrorKind::InvalidData)), + Err(e) => Err(e) + } } \ No newline at end of file