main
阳光少年 1 year ago
parent 66aeab6753
commit 57419f6662

@ -56,7 +56,7 @@ struct RockerArgs {
// rm container_id // rm container_id
#[arg(long)] #[arg(long)]
rm: Option<Vec<String>> rm: Option<String>
} }
@ -151,7 +151,7 @@ fn init_container_custom_volume<P: AsRef<Path>>(container_merged_path: P, custom
let container_path = container_path_buf.to_string_lossy().to_string(); 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)?; create_dir(&container_path, true)?;
// 绑定 // 绑定
@ -397,7 +397,7 @@ fn save_container_info(args: &RockerArgs, container_id: &String, pid: i32) -> Re
pid: pid, pid: pid,
run: args.run.as_ref().unwrap().clone(), run: args.run.as_ref().unwrap().clone(),
image: args.image.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(), env: "".to_string(),
status: ContainerStatus::READY, status: ContainerStatus::READY,
}; };
@ -406,7 +406,7 @@ fn save_container_info(args: &RockerArgs, container_id: &String, pid: i32) -> Re
Ok(()) Ok(())
} }
fn get_container_info(container_id: &String) -> Result<ContainerInfo> { fn get_container_info(container_id: &str) -> Result<ContainerInfo> {
let container_work_path = Path::new(WORKSPACE).join("containers").join(container_id); let container_work_path = Path::new(WORKSPACE).join("containers").join(container_id);
let container_info_path = container_work_path.join(INFO_FILE); let container_info_path = container_work_path.join(INFO_FILE);
let lock_path = container_work_path.join(LOCK_FILE); let lock_path = container_work_path.join(LOCK_FILE);
@ -436,7 +436,7 @@ fn get_all_container_info() -> Result<Vec<ContainerInfo>> {
.map(|res| res.map(|e| e.file_name())) .map(|res| res.map(|e| e.file_name()))
.filter_map(|p| p.ok()) .filter_map(|p| p.ok())
.map(|f|f.to_string_lossy().to_string()) .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::<Vec<ContainerInfo>>(); .collect::<Vec<ContainerInfo>>();
Ok(all_containers_info) Ok(all_containers_info)
} }
@ -454,8 +454,8 @@ fn show_containers(is_show_all: bool) -> Result<()> {
Ok(()) Ok(())
} }
fn delete_container(containers_id: &Vec<String>) -> Result<()> { fn delete_container(containers_id: &str) -> Result<()> {
for container_id in containers_id { for container_id in containers_id.split(",") {
if let Ok(container_info) = get_container_info(container_id) { if let Ok(container_info) = get_container_info(container_id) {
let container_work_path = Path::new(WORKSPACE).join("containers").join(container_id); let container_work_path = Path::new(WORKSPACE).join("containers").join(container_id);
let container_merged_path = container_work_path.join("merged"); let container_merged_path = container_work_path.join("merged");

Loading…
Cancel
Save