Make home directory optional.

This commit is contained in:
Justus Winter 2024-11-13 12:04:49 +01:00
parent b8dba63d39
commit 5414ceec07
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386
4 changed files with 28 additions and 16 deletions

View File

@ -153,17 +153,24 @@ pub fn generate(
rev_cert
} else if on_keystore {
let dir = sq.home.data_dir(sequoia_directories::Component::Other(
"revocation-certificates".into()));
std::fs::create_dir_all(&dir)
.with_context(|| {
format!("While creating {}", dir.display())
})?;
if let Some(home) = &sq.home {
let dir = home.data_dir(sequoia_directories::Component::Other(
"revocation-certificates".into()));
std::fs::create_dir_all(&dir)
.with_context(|| {
format!("While creating {}", dir.display())
})?;
(cert, rev) = gen()?;
FileOrStdout::new(
Some(dir.join(format!("{}-revocation.pgp",
cert.fingerprint()))))
(cert, rev) = gen()?;
FileOrStdout::new(
Some(dir.join(format!("{}-revocation.pgp",
cert.fingerprint()))))
} else {
return Err(anyhow::anyhow!(
"Missing arguments: --rev-cert is mandatory if --home=none is \
given."
));
}
} else {
return Err(anyhow::anyhow!(
"Missing arguments: --rev-cert is mandatory if --output is \

View File

@ -447,7 +447,10 @@ pub fn list(sq: Sq, mut cmd: cli::key::list::Command) -> Result<()> {
let mut hint = sq.hint(format_args!(
"There are no secret keys."));
if sq.key_store_path.is_some() || ! sq.home.is_default_location() {
if sq.key_store_path.is_some()
|| ! sq.home.as_ref()
.map(|h| h.is_default_location()).unwrap_or(false)
{
hint = hint.hint(format_args!(
"The non-default key store location {} is selected \
using the `{}` option. Consider using the default \

View File

@ -301,14 +301,14 @@ fn real_main() -> Result<()> {
time_is_now,
policy_as_of,
policy: &policy,
home: if let Some(p) = c.home.as_ref().and_then(|a| a.path()) {
home: Some(if let Some(p) = c.home.as_ref().and_then(|a| a.path()) {
sequoia_directories::Home::new(p)?
} else {
sequoia_directories::Home::default()
.ok_or(anyhow::anyhow!("no default SEQUOIA_HOME \
on this platform"))?
.clone()
},
}),
no_rw_cert_store: c.no_cert_store,
cert_store_path: c.cert_store.as_ref().and_then(|a| a.path()),
keyrings: c.keyring.clone(),

View File

@ -104,7 +104,7 @@ pub struct Sq<'store, 'rstore>
pub time_is_now: bool,
pub policy: &'rstore P<'rstore>,
pub policy_as_of: SystemTime,
pub home: sequoia_directories::Home,
pub home: Option<sequoia_directories::Home>,
// --no-cert-store
#[deprecated]
pub no_rw_cert_store: bool,
@ -161,7 +161,8 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
} else if let Ok(path) = std::env::var("PGP_CERT_D") {
Some(PathBuf::from(path))
} else {
Some(self.home.data_dir(sequoia_directories::Component::CertD))
self.home.as_ref()
.map(|h| h.data_dir(sequoia_directories::Component::CertD))
}
}
@ -366,7 +367,8 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
} else if let Some(dir) = self.key_store_path.as_ref() {
Ok(Some(dir.clone()))
} else {
Ok(Some(self.home.data_dir(sequoia_directories::Component::Keystore)))
Ok(self.home.as_ref()
.map(|h| h.data_dir(sequoia_directories::Component::Keystore)))
}
}