feat: prepend $pkgdir to avoid user hassle

This commit is contained in:
Colin Woodbury
2024-03-07 20:39:11 +09:00
parent 5df440310e
commit 4bebc62331
5 changed files with 18 additions and 5 deletions

View File

@@ -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"]]

View File

@@ -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:

View File

@@ -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())
}
}
}
}

View File

@@ -163,5 +163,5 @@ pub struct AUR {
#[serde(default)]
optdepends: Vec<String>,
#[serde(default)]
pub files: Vec<(String, String)>,
pub files: Vec<(PathBuf, PathBuf)>,
}

View File

@@ -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()
)?;
}
}
}