//! Bundle your distribution as a plain directory, without compression.

use std::path::Path;

use tracing::debug;

use crate::fs;

use super::{Bundler, BundleMetadata};


/// Provides the distribution files in a directory,
/// without compression or other transformations.
///
/// To be used with [`crate::Distribution::bundle`].
#[derive(Default)]
pub struct DirBundler;

impl Bundler for DirBundler {
    fn file_extension(&self) -> &str { "" }

    fn bundle(&self, in_dir: &Path, out_path: &Path, _: &BundleMetadata) -> cicero_core::Result<()> {

        if out_path.exists() {
            debug!("Removing distribution out dir, because it already exists: {out_path:?}");
            fs::remove_dir_all(out_path)?;
        }

        fs::create_dir_all(out_path)?;

        fs::copy_dir_all(in_dir, out_path)?;

        Ok(())
    }
}
