1010use directories:: ProjectDirs ;
1111use std:: path:: PathBuf ;
1212use std:: sync:: LazyLock ;
13- use std:: { env, fs} ;
13+ use std:: { env, fs, io } ;
1414use tectonic_errors:: prelude:: * ;
1515
1616/// The instance of the `directories` crate that this crate links to.
1717pub 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`
3845pub 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