upki: add support for system-wide configuration/caching (alt)#121
Open
ctz wants to merge 2 commits into
Open
Conversation
Member
|
Why should this be scoped to Unix only? |
Member
Author
Just trying to avoid looking at |
Member
|
I think one of my PRs had a global path for Windows too. |
Member
Author
|
Sorry, which one is that? |
Member
|
Ah, maybe I never pushed it, but I found this in my git stash stack: djc-2021 system-dirs upki $ git show stash@{1}
commit ed57832313a15096805019b55135426b3ad5bc70
Merge: 46f51ba e8f9072
Author: Dirkjan Ochtman <dirkjan@ochtman.nl>
Date: Fri Apr 17 16:50:45 2026 +0200
WIP on system-dirs: 46f51ba upki: take PathKind for Config construction
diff --cc upki/src/lib.rs
index 6c67473,6c67473..d011502
--- a/upki/src/lib.rs
+++ b/upki/src/lib.rs
@@@ -101,6 -101,6 +101,8 @@@ impl AsRef<Path> for ConfigPath
/// What kind of path is being determined.
#[derive(Clone, Copy, Debug)]
pub enum PathKind {
++ /// System-wide configuration and data.
++ System,
/// User-relative configuration and data.
User,
}
@@@ -108,17 -108,17 +110,69 @@@
impl PathKind {
fn config_dir(self) -> Result<PathBuf, Error> {
Ok(match self {
++ Self::System => platform::system_config_dir()?,
Self::User => project_dirs()?.config_dir().to_owned(),
})
}
fn cache_dir(self) -> Result<PathBuf, Error> {
Ok(match self {
++ Self::System => platform::system_cache_dir()?,
Self::User => project_dirs()?.cache_dir().to_owned(),
})
}
}
++#[cfg(target_os = "macos")]
++mod platform {
++ use super::*;
++
++ pub(super) fn system_config_dir() -> Result<PathBuf, Error> {
++ Ok(PathBuf::from("/Library/Application Support").join(PREFIX))
++ }
++
++ pub(super) fn system_cache_dir() -> Result<PathBuf, Error> {
++ Ok(PathBuf::from("/Library/Caches").join(BUNDLE_ID))
++ }
++}
++
++#[cfg(target_os = "linux")]
++mod platform {
++ use super::*;
++
++ pub(super) fn system_config_dir() -> Result<PathBuf, Error> {
++ Ok(PathBuf::from("/etc").join(PREFIX))
++ }
++
++ pub(super) fn system_cache_dir() -> Result<PathBuf, Error> {
++ Ok(PathBuf::from("/var/cache").join(PREFIX))
++ }
++}
++
++#[cfg(target_os = "windows")]
++mod platform {
++ use super::*;
++
++ pub(super) fn system_config_dir() -> Result<PathBuf, Error> {
++ match env::var_os("ProgramData") {
++ Ok(base) => PathBuf::from(base)
++ .join(VENDOR)
++ .join(PREFIX),
++ Err(_) => return Err(Error::NoConfigDirectoryFound),
++ }
++ }
++
++ pub(super) fn system_cache_dir() -> Result<PathBuf, Error> {
++ match env::var_os("ProgramData") {
++ Ok(base) => PathBuf::from(base)
++ .join(VENDOR)
++ .join(PREFIX)
++ .join("cache"),
++ Err(_) => return Err(Error::NoCacheDirectoryFound),
++ }
++ }
++}
++
/// Errors for the upki library API.
#[non_exhaustive]
#[derive(Debug)]
@@@ -181,5 -181,5 +235,8 @@@ fn project_dirs() -> Result<ProjectDirs
ProjectDirs::from("dev", "rustls", PREFIX).ok_or(Error::NoValidHomeDirectory)
}
++const BUNDLE_ID: &str = "dev.rustls.upki";
++#[cfg(target_os = "windows")]
++const VENDOR: &str = "rustls";
const PREFIX: &str = "upki";
const CONFIG_FILE: &str = "config.toml"; |
djc
reviewed
May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is an alternative of #106