git_index

Generates arguments to pass to stagit-index in descending order by commit date.
git clone https://git.philomathiclife.com/repos/git_index
Log | Files | Refs | README

commit 701bbc5703820817025cb67d957b189e7aeb5ad9
parent d10b48d5a0526f207cc5505f2318a448d13b8896
Author: Zack Newman <zack@philomathiclife.com>
Date:   Wed,  8 Nov 2023 16:11:50 -0700

update deps. fix for non-openbsd

Diffstat:
MCargo.toml | 6++++--
Msrc/main.rs | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -8,16 +8,18 @@ license = "MIT OR Apache-2.0" name = "git_index" readme = "README.md" repository = "https://git.philomathiclife.com/repos/git_index/" -version = "0.1.0" +version = "0.1.1" [[bin]] name = "git_index" path = "src/main.rs" [dependencies] -priv_sep = { version = "0.8.0", default-features = false, features = ["openbsd"] } time = { version = "0.3.30", default-features = false, features = ["parsing"] } +[target.'cfg(target_os = "openbsd")'.dependencies] +priv_sep = { version = "0.8.1", default-features = false, features = ["openbsd"], optional = true } + [badges] maintenance = { status = "actively-developed" } diff --git a/src/main.rs b/src/main.rs @@ -30,8 +30,11 @@ extern crate alloc; mod args; use alloc::collections::BTreeMap; use args::{AbsDirPath, ArgsErr}; +#[cfg(not(target_os = "openbsd"))] +use core::convert::Infallible; use core::fmt::{self, Display, Formatter}; use core::str::{self, Utf8Error}; +#[cfg(target_os = "openbsd")] use priv_sep::{Permissions, Promise, Promises, UnveilErr}; use std::error; use std::ffi::OsString; @@ -42,11 +45,17 @@ use std::process::{Command, Stdio}; use time::error::Parse; use time::format_description::well_known::Iso8601; use time::OffsetDateTime; +/// `()` triggers lints when captured by `let`. +/// This only relevant for the no-op functions. +#[cfg(not(target_os = "openbsd"))] +#[derive(Clone, Copy)] +struct Zst; /// Module for reading the options passed to the application. /// Error returned from the program. enum E { /// Variant for errors due to incorrect arguments being passed. Args(ArgsErr), + #[cfg(target_os = "openbsd")] /// Variant for errors due to calls to `unveil`. Unveil(UnveilErr), /// Variant for IO errors. @@ -72,6 +81,7 @@ impl Display for E { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match *self { Self::Args(ref e) => e.fmt(f), + #[cfg(target_os = "openbsd")] Self::Unveil(ref err) => write!(f, "unveil(2) failed with {err}"), Self::Io(ref e) => e.fmt(f), Self::NonUtf8Path(ref e) => write!(f, "{e:?} is not valid UTF-8"), @@ -103,12 +113,20 @@ impl From<Error> for E { Self::Io(value) } } +#[cfg(target_os = "openbsd")] impl From<UnveilErr> for E { #[inline] fn from(value: UnveilErr) -> Self { Self::Unveil(value) } } +#[cfg(not(target_os = "openbsd"))] +impl From<Infallible> for E { + #[inline] + fn from(value: Infallible) -> Self { + match value {} + } +} impl From<Utf8Error> for E { #[inline] fn from(value: Utf8Error) -> Self { @@ -130,6 +148,7 @@ impl From<Parse> for E { /// Calls `pledge` with only the sys calls necessary for a minimal application /// to run. Specifically, the `Promise`s `Exec`, `Proc`, `Rpath`, `Stdio`, and `Unveil` /// are passed. +#[cfg(target_os = "openbsd")] #[inline] fn pledge_init() -> Result<Promises<5>, Error> { let promises = Promises::new([ @@ -144,33 +163,80 @@ fn pledge_init() -> Result<Promises<5>, Error> { Err(e) => Err(e), } } +/// No-op that returns `Ok`. +#[cfg(not(target_os = "openbsd"))] +#[allow(clippy::unnecessary_wraps)] +#[inline] +const fn pledge_init() -> Result<Zst, Infallible> { + Ok(Zst) +} /// Removes `Promise::Unveil`. +#[cfg(target_os = "openbsd")] #[inline] fn pledge_away_unveil(promises: &mut Promises<5>) -> Result<(), Error> { promises.remove(Promise::Unveil); promises.pledge() } +/// No-op that returns `Ok`. +#[cfg(not(target_os = "openbsd"))] +#[allow(clippy::unnecessary_wraps)] +#[inline] +fn pledge_away_unveil(_: &mut Zst) -> Result<(), Infallible> { + Ok(()) +} /// Removes all `Promise`s except `Stdio`. +#[cfg(target_os = "openbsd")] #[inline] fn pledge_away_all_but_stdio(promises: &mut Promises<5>) -> Result<(), Error> { promises.retain([Promise::Stdio]); promises.pledge() } +/// No-op that returns `Ok`. +#[cfg(not(target_os = "openbsd"))] +#[allow(clippy::unnecessary_wraps)] +#[inline] +fn pledge_away_all_but_stdio(_: &mut Zst) -> Result<(), Infallible> { + Ok(()) +} /// Calls `unveil_none` on `/`. +#[cfg(target_os = "openbsd")] #[inline] fn veil_all() -> Result<(), UnveilErr> { Permissions::NONE.unveil("/") } +/// No-op that returns `Ok`. +#[cfg(not(target_os = "openbsd"))] +#[allow(clippy::unnecessary_wraps)] +#[inline] +const fn veil_all() -> Result<(), Infallible> { + Ok(()) +} /// Calls `unveil`_on `GIT` with `Permissions::EXECUTE`. +#[cfg(target_os = "openbsd")] #[inline] fn unveil_git() -> Result<(), UnveilErr> { Permissions::EXECUTE.unveil(GIT) } +/// No-op that returns `Ok`. +#[cfg(not(target_os = "openbsd"))] +#[allow(clippy::unnecessary_wraps)] +#[inline] +const fn unveil_git() -> Result<(), Infallible> { + Ok(()) +} /// Calls `unveil`_on `path` with `Permissions::READ`. +#[cfg(target_os = "openbsd")] #[inline] fn unveil_read<P: AsRef<Path>>(path: P) -> Result<(), UnveilErr> { Permissions::READ.unveil(path) } +/// No-op that returns `Ok`. +#[cfg(not(target_os = "openbsd"))] +#[allow(clippy::unnecessary_wraps)] +#[inline] +fn unveil_read<P: AsRef<Path>>(_: P) -> Result<(), Infallible> { + Ok(()) +} /// For each entry in `dir`, `git` is forked and invoked with `-C <dir><entry_in_dir> log -1 --date=iso-strict --pretty=format:"%cd"`. #[inline] fn get_git_data(map: &mut BTreeMap<OffsetDateTime, Vec<String>>, dir: AbsDirPath) -> Result<(), E> {