fix: replace string path by pathbuf

This commit is contained in:
Sergio Ribera
2023-11-21 17:07:23 -04:00
parent 0484b382eb
commit 55fc12153b

View File

@@ -41,7 +41,7 @@ struct Args {
version: bool,
/// Set custom output directory
output: Option<String>,
output: Option<PathBuf>,
/// Unused.
#[options(free)]
args: Vec<String>,
@@ -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<GitHost> {
@@ -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<String, Error> {
fn sha256sum(package: &Package, output: &PathBuf) -> Result<String, Error> {
let bytes = std::fs::read(package.tarball(output))?;
let digest = Hash::hash(&bytes);
let hex = digest.iter().map(|u| format!("{:02x}", u)).collect();