diff --git a/docker2fl/src/docker2fl.rs b/docker2fl/src/docker2fl.rs index 2a2e540..7514dda 100644 --- a/docker2fl/src/docker2fl.rs +++ b/docker2fl/src/docker2fl.rs @@ -106,7 +106,7 @@ impl DockerImageToFlist { Ok(()) } - pub async fn pack(&mut self, store: S, sender: Option>) -> Result<()> { + pub async fn pack(&mut self, store: S, sender: Option>) -> Result<()> { rfs::pack( self.meta.clone(), store, @@ -121,7 +121,7 @@ impl DockerImageToFlist { Ok(()) } - pub async fn convert(&mut self, store: S, sender: Option>) -> Result<()> { + pub async fn convert(&mut self, store: S, sender: Option>) -> Result<()> { self.prepare().await?; self.pack(store, sender).await?; diff --git a/fl-server/src/handlers.rs b/fl-server/src/handlers.rs index 5cdc039..d067188 100644 --- a/fl-server/src/handlers.rs +++ b/fl-server/src/handlers.rs @@ -176,7 +176,8 @@ pub async fn create_flist_handler( ); let container_name = Uuid::new_v4().to_string(); - let docker_tmp_dir = tempdir::TempDir::new(&container_name).unwrap(); + let docker_tmp_dir = + tempdir::TempDir::new(&container_name).expect("failed to create tmp dir for docker"); let docker_tmp_dir_path = docker_tmp_dir.path().to_owned(); let (tx, rx) = mpsc::channel(); @@ -193,7 +194,7 @@ pub async fn create_flist_handler( state .jobs_state .lock() - .unwrap() + .expect("failed to lock state") .insert(job.id.clone(), FlistState::Failed); return; } @@ -206,10 +207,10 @@ pub async fn create_flist_handler( let mut progress: f32 = 0.0; for _ in 0..files_count - 1 { - let step = rx.recv().unwrap() as f32; + let step = rx.recv().expect("failed to receive progress") as f32; progress += step; let progress_percentage = progress / files_count as f32 * 100.0; - st.jobs_state.lock().unwrap().insert( + st.jobs_state.lock().expect("failed to lock state").insert( job_id.clone(), FlistState::InProgress(FlistStateInfo { msg: "flist is in progress".to_string(), @@ -218,7 +219,7 @@ pub async fn create_flist_handler( ); st.flists_progress .lock() - .unwrap() + .expect("failed to lock state") .insert(cloned_fl_path.clone(), progress_percentage); } }); @@ -248,7 +249,11 @@ pub async fn create_flist_handler( flist_download_url )), ); - state.flists_progress.lock().unwrap().insert(fl_path, 100.0); + state + .flists_progress + .lock() + .expect("failed to lock state") + .insert(fl_path, 100.0); }); Ok(ResponseResult::FlistCreated(current_job)) diff --git a/fl-server/src/serve_flists.rs b/fl-server/src/serve_flists.rs index 4bbe313..0285421 100644 --- a/fl-server/src/serve_flists.rs +++ b/fl-server/src/serve_flists.rs @@ -103,7 +103,7 @@ pub async fn visit_dir_one_level>( match state .flists_progress .lock() - .unwrap() + .expect("failed to lock state") .get(&path.join(&name).to_path_buf()) { Some(p) => progress = *p, @@ -113,7 +113,7 @@ pub async fn visit_dir_one_level>( let ext = child .path() .extension() - .unwrap() + .expect("failed to get path extension") .to_string_lossy() .to_string(); if ext != "fl" { diff --git a/rfs/src/pack.rs b/rfs/src/pack.rs index fa76a43..33b2a1b 100644 --- a/rfs/src/pack.rs +++ b/rfs/src/pack.rs @@ -27,7 +27,7 @@ pub async fn pack, S: Store>( store: S, root: P, strip_password: bool, - sender: Option>, + sender: Option>, ) -> Result<()> { use tokio::fs; @@ -72,13 +72,13 @@ pub async fn pack, S: Store>( &writer, &mut pool, Item(0, root, OsString::from("/"), meta), - sender.clone(), + sender.as_ref(), ) .await?; while !list.is_empty() { let dir = list.pop_back().unwrap(); - pack_one(&mut list, &writer, &mut pool, dir, sender.clone()).await?; + pack_one(&mut list, &writer, &mut pool, dir, sender.as_ref()).await?; } pool.close().await; @@ -105,7 +105,7 @@ async fn pack_one( writer: &Writer, pool: &mut WorkerPool>, Item(parent, path, name, meta): Item, - sender: Option>, + sender: Option<&Sender>, ) -> Result<()> { use std::os::unix::fs::MetadataExt; use tokio::fs; @@ -139,12 +139,8 @@ async fn pack_one( let meta = child.metadata().await?; let child_path = path.join(&name); - if sender.is_some() { - sender - .clone() - .unwrap() - .send(1) - .context("failed to send progress")?; + if let Some(ref sender) = sender { + sender.send(1).context("failed to send progress")?; } // if this child a directory we add to the tail of the list