unarchiver 0.0.2

CLI Tool for un/archive multiple formats of compressed files
Documentation
use std::path::{Path, PathBuf};

use anyhow::{anyhow, Result};
use tokio::fs::canonicalize;

/// Creates an output file path from an input path and an extension.
pub async fn output_pathname<P: AsRef<Path>>(i: P, ext: &str) -> Result<PathBuf> {
    let mut copies = 0;
    let mut output = canonicalize(i)
        .await
        .map_err(|err| anyhow!("Failed to canonicalize. {}", err))?;

    while output.exists() {
        copies += 1;
        output.set_file_name(format!("{} ({})", output.to_string_lossy(), copies));
    }

    output.set_extension(ext);
    Ok(output)
}