Skip to content

Commit 6a027cc

Browse files
committed
Fix
1 parent 6086db5 commit 6a027cc

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

crates/io_base/src/app_dirs.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,23 @@
1010
use directories::ProjectDirs;
1111
use std::path::PathBuf;
1212
use std::sync::LazyLock;
13-
use std::{env, fs};
13+
use std::{env, fs, io};
1414
use tectonic_errors::prelude::*;
1515

1616
/// The instance of the `directories` crate that this crate links to.
1717
pub use directories;
1818

19-
const PROJECT_DIRS: LazyLock<Result<ProjectDirs>> = LazyLock::new(|| {
20-
ProjectDirs::from("", "TectonicProject", "Tectonic")
21-
.ok_or_else(|| Error::from("Unable to find standard directories for platform"))
22-
});
19+
static PROJECT_DIRS: LazyLock<Option<ProjectDirs>> =
20+
LazyLock::new(|| ProjectDirs::from("", "TectonicProject", "Tectonic"));
21+
22+
fn dirs() -> Result<&'static ProjectDirs> {
23+
PROJECT_DIRS.as_ref().ok_or_else(|| {
24+
Error::from(io::Error::new(
25+
io::ErrorKind::NotFound,
26+
"Unable to find standard directories for platform",
27+
))
28+
})
29+
}
2330

2431
/// Get the directory for per-user Tectonic configuration files.
2532
///
@@ -36,7 +43,7 @@ const PROJECT_DIRS: LazyLock<Result<ProjectDirs>> = LazyLock::new(|| {
3643
/// - Others: `$XDG_CONFIG_HOME/Tectonic` if defined, otherwise
3744
/// `$HOME/.config/Tectonic`
3845
pub fn get_user_config() -> Result<PathBuf> {
39-
Ok(PROJECT_DIRS?.config_dir().to_path_buf())
46+
Ok(dirs()?.config_dir().to_path_buf())
4047
}
4148

4249
/// Get the directory for per-user Tectonic configuration files, creating it if needed.
@@ -82,7 +89,7 @@ pub fn get_user_cache_dir(subdir: &str) -> Result<PathBuf> {
8289
fs::create_dir_all(&env_cache_path)?;
8390
env_cache_path
8491
}
85-
None => PROJECT_DIRS?.cache_dir().join(subdir),
92+
None => dirs()?.cache_dir().join(subdir),
8693
};
8794

8895
Ok(cache_path)

0 commit comments

Comments
 (0)