1 个不稳定版本

0.1.0 2024年5月10日

配置 中排名 188

Download history 173/week @ 2024-05-06 167/week @ 2024-05-13 250/week @ 2024-05-20 326/week @ 2024-05-27 382/week @ 2024-06-03 575/week @ 2024-06-10 187/week @ 2024-06-17 75/week @ 2024-06-24 156/week @ 2024-07-01 34/week @ 2024-07-08 295/week @ 2024-07-15 72/week @ 2024-07-22 61/week @ 2024-07-29 37/week @ 2024-08-05 403/week @ 2024-08-12

每月下载量 601
2 crate 中使用

LGPL-2.0-or-later

31KB
349

一个小的crate,用于返回平台特定的配置、数据和缓存目录。

此crate主要用于Sequoia库和应用程序,以定位其配置、数据和缓存目录。

默认情况下,Sequoia使用系统标准的用户数据、配置文件和缓存数据位置。例如,在Linux上,这意味着遵循XDG基础目录规范

Sequoia程序还支持使用替代的主目录。在这种情况下,用户数据、配置文件和缓存数据将放置在一个统一的目录下。这是一种轻量级的方法,可以部分隔离程序。

在实例化Home对象时可以指定替代的主目录位置。用户还可以通过设置SEQUOIA_HOME环境变量来覆盖默认设置。默认主目录是用户的主目录。在Linux上,这通常看起来像/home/USER

示例

典型用法

use sequoia_directories::Home;
use sequoia_directories::Component;
use sequoia_directories::Result;

fn main() -> Result<()> {
    // The user can still override this by setting the SEQUOIA_HOME
    // environment variable.
    let home = Home::new(None)?;
    println!("keystore's data directory: {}",
             home.data_dir(Component::Keystore).display());

    Ok(())
}

基于Linux系统的目录

$ cargo run --example list-dirs | sed 's#/home/[^ /]*#/home/USER#; s#/tmp/[^ /]*#/tmp/TMPDIR#;'
Default configuration
---------------------
home: /home/USER (default: true)
base config: /home/USER/.config
cert-d:
  config dir: /home/USER/.config/pgp.cert.d
  data dir: /home/USER/.local/share/pgp.cert.d
  cache dir: /home/USER/.cache/pgp.cert.d
keystore:
  config dir: /home/USER/.config/sequoia/keystore
  data dir: /home/USER/.local/share/sequoia/keystore
  cache dir: /home/USER/.cache/sequoia/keystore
sq:
  config dir: /home/USER/.config/sequoia/sq
  data dir: /home/USER/.local/share/sequoia/sq
  cache dir: /home/USER/.cache/sequoia/sq
foo:
  config dir: /home/USER/.config/sequoia/foo
  data dir: /home/USER/.local/share/sequoia/foo
  cache dir: /home/USER/.cache/sequoia/foo

/tmp/TMPDIR
---------------
home: /tmp/TMPDIR (default: false)
base config: /tmp/TMPDIR
cert-d:
  config dir: /tmp/TMPDIR/config/pgp.cert.d
  data dir: /tmp/TMPDIR/data/pgp.cert.d
  cache dir: /tmp/TMPDIR/cache/pgp.cert.d
keystore:
  config dir: /tmp/TMPDIR/config/keystore
  data dir: /tmp/TMPDIR/data/keystore
  cache dir: /tmp/TMPDIR/cache/keystore
sq:
  config dir: /tmp/TMPDIR/config/sq
  data dir: /tmp/TMPDIR/data/sq
  cache dir: /tmp/TMPDIR/cache/sq
foo:
  config dir: /tmp/TMPDIR/config/foo
  data dir: /tmp/TMPDIR/data/foo
  cache dir: /tmp/TMPDIR/cache/foo

基于Windows系统的目录(我们的CI)

$ cargo run --example list-dirs
Default configuration
---------------------
home: C:\Users\ContainerAdministrator (default: true)
base config: C:\Users\ContainerAdministrator\AppData\Roaming
cert-d:
  config dir: C:\Users\ContainerAdministrator\AppData\Roaming\pgp.cert.d
  data dir: C:\Users\ContainerAdministrator\AppData\Roaming\pgp.cert.d
  cache dir: C:\Users\ContainerAdministrator\AppData\Local\pgp.cert.d
keystore:
  config dir: C:\Users\ContainerAdministrator\AppData\Roaming\Sequoia-PGP\sequoia\config\keystore
  data dir: C:\Users\ContainerAdministrator\AppData\Roaming\Sequoia-PGP\sequoia\data\keystore
  cache dir: C:\Users\ContainerAdministrator\AppData\Local\Sequoia-PGP\sequoia\cache\keystore
sq:
  config dir: C:\Users\ContainerAdministrator\AppData\Roaming\Sequoia-PGP\sequoia\config\sq
  data dir: C:\Users\ContainerAdministrator\AppData\Roaming\Sequoia-PGP\sequoia\data\sq
  cache dir: C:\Users\ContainerAdministrator\AppData\Local\Sequoia-PGP\sequoia\cache\sq
foo:
  config dir: C:\Users\ContainerAdministrator\AppData\Roaming\Sequoia-PGP\sequoia\config\foo
  data dir: C:\Users\ContainerAdministrator\AppData\Roaming\Sequoia-PGP\sequoia\data\foo
  cache dir: C:\Users\ContainerAdministrator\AppData\Local\Sequoia-PGP\sequoia\cache\foo
C:\Users\ContainerAdministrator\AppData\Local\Temp\.tmpPrPmly
-------------------------------------------------------------
home: C:\Users\ContainerAdministrator\AppData\Local\Temp\.tmpPrPmly (default: false)
base config: C:\Users\ContainerAdministrator\AppData\Local\Temp\.tmpPrPmly
cert-d:
  config dir: C:\Users\ContainerAdministrator\AppData\Local\Temp\.tmpPrPmly\config\pgp.cert.d
  data dir: C:\Users\ContainerAdministrator\AppData\Local\Temp\.tmpPrPmly\data\pgp.cert.d
  cache dir: C:\Users\ContainerAdministrator\AppData\Local\Temp\.tmpPrPmly\cache\pgp.cert.d
keystore:
  config dir: C:\Users\ContainerAdministrator\AppData\Local\Temp\.tmpPrPmly\config\keystore
  data dir: C:\Users\ContainerAdministrator\AppData\Local\Temp\.tmpPrPmly\data\keystore
  cache dir: C:\Users\ContainerAdministrator\AppData\Local\Temp\.tmpPrPmly\cache\keystore
sq:
  config dir: C:\Users\ContainerAdministrator\AppData\Local\Temp\.tmpPrPmly\config\sq
  data dir: C:\Users\ContainerAdministrator\AppData\Local\Temp\.tmpPrPmly\data\sq
  cache dir: C:\Users\ContainerAdministrator\AppData\Local\Temp\.tmpPrPmly\cache\sq
foo:
  config dir: C:\Users\ContainerAdministrator\AppData\Local\Temp\.tmpPrPmly\config\foo
  data dir: C:\Users\ContainerAdministrator\AppData\Local\Temp\.tmpPrPmly\data\foo
  cache dir: C:\Users\ContainerAdministrator\AppData\Local\Temp\.tmpPrPmly\cache\foo

依赖关系

~2–14MB
~140K SLoC