From 57419f66626878ef6680bc1de33c302dcdfb16dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=B3=E5=85=89=E5=B0=91=E5=B9=B4?= <849317537@qq.com> Date: Thu, 1 Aug 2024 05:33:50 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.toml | 0 src/main.rs | 18 +++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) delete mode 100644 src/config.toml diff --git a/src/config.toml b/src/config.toml deleted file mode 100644 index e69de29..0000000 diff --git a/src/main.rs b/src/main.rs index 8703619..f8fd092 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,7 +56,7 @@ struct RockerArgs { // rm container_id #[arg(long)] - rm: Option> + rm: Option } @@ -151,7 +151,7 @@ fn init_container_custom_volume>(container_merged_path: P, custom let container_path = container_path_buf.to_string_lossy().to_string(); // 创建宿主机和容器内的目录 - create_dir(Path::new(host_path), false)?; + create_dir(Path::new(host_path), true)?; create_dir(&container_path, true)?; // 绑定 @@ -386,7 +386,7 @@ impl Display for ContainerInfo { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let volume: String = self.volume.chars().take(20).collect(); let env: String = self.env.chars().take(20).collect(); - write!(f, "\x1b[4m{:<10}{:<8}{:<10}{:<20}{:<20}{:<20}{:<10}\x1b[24m", self.id, self.pid, self.image, self.run, volume, env, &self.status) + write!(f, "\x1b[4m{:<10} {:<8} {:<10} {:<20} {:<20} {:<20} {:<10}\x1b[24m", self.id, self.pid, self.image, self.run, volume, env, &self.status) } } @@ -397,7 +397,7 @@ fn save_container_info(args: &RockerArgs, container_id: &String, pid: i32) -> Re pid: pid, run: args.run.as_ref().unwrap().clone(), image: args.image.as_ref().unwrap().clone(), - volume: "".to_string(), + volume: args.volume.clone().unwrap_or("".to_string()), env: "".to_string(), status: ContainerStatus::READY, }; @@ -406,7 +406,7 @@ fn save_container_info(args: &RockerArgs, container_id: &String, pid: i32) -> Re Ok(()) } -fn get_container_info(container_id: &String) -> Result { +fn get_container_info(container_id: &str) -> Result { let container_work_path = Path::new(WORKSPACE).join("containers").join(container_id); let container_info_path = container_work_path.join(INFO_FILE); let lock_path = container_work_path.join(LOCK_FILE); @@ -436,14 +436,14 @@ fn get_all_container_info() -> Result> { .map(|res| res.map(|e| e.file_name())) .filter_map(|p| p.ok()) .map(|f|f.to_string_lossy().to_string()) - .filter_map(|s|get_container_info(&s).ok()) + .filter_map(|s|get_container_info(s.as_str()).ok()) .collect::>(); Ok(all_containers_info) } /// 读取所有容器的状态 fn show_containers(is_show_all: bool) -> Result<()> { - println!("{:<10}{:<8}{:<10}{:<20}{:<20}{:<20}{:<10}", "id", "pid", "image", "run", "volume", "env", "status"); + println!("{:<10} {:<8} {:<10} {:<20} {:<20} {:<20} {:<10}", "id", "pid", "image", "run", "volume", "env", "status"); for container_info in get_all_container_info()? { if is_show_all{ println!("{container_info}"); @@ -454,8 +454,8 @@ fn show_containers(is_show_all: bool) -> Result<()> { Ok(()) } -fn delete_container(containers_id: &Vec) -> Result<()> { - for container_id in containers_id { +fn delete_container(containers_id: &str) -> Result<()> { + for container_id in containers_id.split(",") { if let Ok(container_info) = get_container_info(container_id) { let container_work_path = Path::new(WORKSPACE).join("containers").join(container_id); let container_merged_path = container_work_path.join("merged");