diff --git a/src/main.rs b/src/main.rs index 64ade83..4a337e6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,7 +41,7 @@ struct Args { version: bool, /// Set custom output directory - output: Option, + output: Option, /// Unused. #[options(free)] args: Vec, @@ -179,11 +179,10 @@ struct Binary { impl Package { /// The name of the tarball that should be produced from this `Package`. - fn tarball(&self, output: &str) -> String { - format!( - "{output}/{}-{}-x86_64.tar.gz", - self.name, self.version - ) + fn tarball(&self, output: &PathBuf) -> String { + let mut output = output.clone(); + output.push(format!("{}-{}-x86_64.tar.gz", self.name, self.version)); + output.to_str().unwrap().to_string() } fn git_host(&self) -> Option { @@ -220,8 +219,8 @@ fn work(args: Args) -> Result<(), Error> { p("Checking for musl toolchain...".bold()); musl_check()? } - - let output = args.output.unwrap_or("target/cargo-aur".to_string()); + + let output = args.output.unwrap_or(PathBuf::from("target/cargo-aur")); // Ensure the target can actually be written to. Otherwise the `tar` // operation later on will fail. @@ -249,8 +248,12 @@ fn work(args: Args) -> Result<(), Error> { let sha256: String = sha256sum(&config.package, &output)?; // Write the PKGBUILD. - let file = BufWriter::new(File::create(format!("{output}/PKGBUILD"))?); - pkgbuild(file, &config, &sha256, license.as_ref())?; + { + let mut output = output.clone(); + output.push("PKGBUILD"); + let file = BufWriter::new(File::create(&output)?); + pkgbuild(file, &config, &sha256, license.as_ref())?; + } } Ok(()) @@ -366,7 +369,12 @@ fn release_build(musl: bool) -> Result<(), Error> { Ok(()) } -fn tarball(musl: bool, output: &str, license: Option<&DirEntry>, config: &Config) -> Result<(), Error> { +fn tarball( + musl: bool, + output: &PathBuf, + license: Option<&DirEntry>, + config: &Config, +) -> Result<(), Error> { let target_dir: OsString = match std::env::var_os("CARGO_TARGET_DIR") { Some(p) => p, None => "target".into(), @@ -411,7 +419,7 @@ fn strip(path: &Path) -> Result<(), Error> { Ok(()) // FIXME Would love to use my `void` package here and elsewhere. } -fn sha256sum(package: &Package, output: &str) -> Result { +fn sha256sum(package: &Package, output: &PathBuf) -> Result { let bytes = std::fs::read(package.tarball(output))?; let digest = Hash::hash(&bytes); let hex = digest.iter().map(|u| format!("{:02x}", u)).collect();