fluentci_ext/archive/
zip.rs1use std::{env, path::Path, process::ExitStatus, sync::mpsc::Sender};
2
3use crate::{exec, pkgx::Pkgx, Extension};
4use anyhow::Error;
5use fluentci_types::Output;
6
7#[derive(Default)]
8pub struct Zip {}
9
10impl Extension for Zip {
11 fn exec(
12 &mut self,
13 path: &str,
14 tx: Sender<String>,
15 out: Output,
16 last_cmd: bool,
17 _work_dir: &str,
18 ) -> Result<ExitStatus, Error> {
19 self.setup()?;
20
21 let output_file = match path.split('/').last() {
22 Some(file) => format!("{}.zip", file),
23 None => format!("{}.zip", path),
24 };
25
26 let output_file = env::var("FLUENTCI_ZIP_OUTPUT_FILE").unwrap_or(output_file.to_string());
27 let parent_dir = Path::new(path).parent().unwrap();
28 let work_dir = parent_dir.to_str().unwrap();
29 let path = Path::new(path).file_name().unwrap().to_str().unwrap();
30
31 let cmd = format!("zip -r {} {}", output_file, path);
32 exec(&cmd, tx, out, last_cmd, work_dir)
33 }
34
35 fn setup(&self) -> Result<(), Error> {
36 Pkgx::default().install(vec!["zip"])?;
37 Ok(())
38 }
39}