Skip to content

Commit

Permalink
feat: prepend $pkgdir to avoid user hassle
Browse files Browse the repository at this point in the history
  • Loading branch information
fosskers committed Mar 7, 2024
1 parent 5df4403 commit 4bebc62
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -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),
Expand All @@ -9,6 +9,7 @@ pub(crate) enum Error {
Utf8OsString,
MissingMuslTarget,
MissingLicense,
TargetNotAbsolute(PathBuf),
}

impl Display for Error {
Expand All @@ -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())
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,5 @@ pub struct AUR {
#[serde(default)]
optdepends: Vec<String>,
#[serde(default)]
pub files: Vec<(String, String)>,
pub files: Vec<(PathBuf, PathBuf)>,
}
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)?;
}
}
}

Expand Down

0 comments on commit 4bebc62

Please sign in to comment.