From 4bebc6233135b604ccb9cb009290e33e14874a47 Mon Sep 17 00:00:00 2001 From: Colin Woodbury Date: Thu, 7 Mar 2024 20:39:11 +0900 Subject: [PATCH] feat: prepend `$pkgdir` to avoid user hassle --- Cargo.toml | 2 +- README.md | 2 +- src/error.rs | 6 +++++- src/lib.rs | 2 +- src/main.rs | 11 ++++++++++- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 05b6859..5676478 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,4 +27,4 @@ panic = "abort" [package.metadata.aur] # depends = ["blah"] -# files = [[".github/dependabot.yml", "$pkgdir/usr/local/share/cargo-aur/dependabot.yml"]] +# files = [[".github/dependabot.yml", "/usr/local/share/cargo-aur/dependabot.yml"]] diff --git a/README.md b/README.md index ecaf8be..bfcc99a 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ filesystem. So this: ```toml [package.metadata.aur] -files = [["path/to/local/foo.txt", "$pkgdir/usr/local/share/your-app/foo.txt"]] +files = [["path/to/local/foo.txt", "/usr/local/share/your-app/foo.txt"]] ``` will result in this: diff --git a/src/error.rs b/src/error.rs index 87531c1..21dd65d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,6 @@ //! Errors that can occur in this application. -use std::fmt::Display; +use std::{fmt::Display, path::PathBuf}; pub(crate) enum Error { IO(std::io::Error), @@ -9,6 +9,7 @@ pub(crate) enum Error { Utf8OsString, MissingMuslTarget, MissingLicense, + TargetNotAbsolute(PathBuf), } impl Display for Error { @@ -25,6 +26,9 @@ impl Display for Error { Error::MissingLicense => { write!(f, "Missing LICENSE file. See https://choosealicense.com/") } + Error::TargetNotAbsolute(p) => { + write!(f, "Target filepath is not absolute: {}", p.display()) + } } } } diff --git a/src/lib.rs b/src/lib.rs index 918f127..3dc379e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -163,5 +163,5 @@ pub struct AUR { #[serde(default)] optdepends: Vec, #[serde(default)] - pub files: Vec<(String, String)>, + pub files: Vec<(PathBuf, PathBuf)>, } diff --git a/src/main.rs b/src/main.rs index 9e36749..0b99026 100644 --- a/src/main.rs +++ b/src/main.rs @@ -239,7 +239,16 @@ where if let Some(aur) = package.metadata.as_ref().and_then(|m| m.aur.as_ref()) { for (source, target) in aur.files.iter() { - writeln!(file, " install -Dm644 \"{}\" \"{}\"", source, target)?; + if target.has_root().not() { + return Err(Error::TargetNotAbsolute(target.to_path_buf())); + } else { + writeln!( + file, + " install -Dm644 \"{}\" \"$pkgdir{}\"", + source.display(), + target.display() + )?; + } } }