Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,29 @@ ensure that you the manifest has been verified before proceeding:
filepack verify --print | jq
```

Data Directory
--------------

Filepack stores local configuration in the `filepack` subdirectory of the
platform data directory.

The location of the platform data directory is platform dependent, with the
`$XDG_DATA_DIR` being respected on all platforms.

| Platform | Value |
| -------- | ----------------------------------- |
| All | `$XDG_DATA_DIR` |
| Linux | `$HOME`/.local/share |
| macOS | `$HOME`/Library/Application Support |
| Windows | `{FOLDERID_LocalAppData}` |

Filepack stores keys in the `keychain` subdirectory of the filepack data
directory. So if the platform data directory is `~/.local/share`, the
`keychain` directory is `~/.local/share/filepack/keychain`.

The location of the filepack data directory used by a command can be overridden
with the `--data-dir` option.

Manifest
--------

Expand Down Expand Up @@ -388,17 +411,8 @@ Keypairs are generated with:
filepack keygen
```

Which creates `master.public` and `master.private` files in the filepack
`keychain` directory.

The `keychain` directory is located in the filepack data directory whose
location is platform-dependent:

| Platform | Value | Example |
| -------- | ---------------------------------------- | ---------------------------------------- |
| Linux | `$XDG_DATA_HOME` or `$HOME`/.local/share | /home/alice/.local/share |
| macOS | `$HOME`/Library/Application Support | /Users/Alice/Library/Application Support |
| Windows | `{FOLDERID_LocalAppData}` | C:\Users\Alice\AppData\Local |
Which creates `master.public` and `master.private` files in the `keychain`
subdirectory of the filepack data directory.

### Public Key Printing

Expand Down
11 changes: 9 additions & 2 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ impl Options {
if let Some(path) = &self.data_dir {
Ok(path.into())
} else {
let path = dirs::data_local_dir().context(error::DataLocalDir)?;
Ok(decode_path(&path)?.join("filepack"))
let dir = if let Some(dir) = env::var_os("XDG_DATA_HOME")
&& !dir.is_empty()
{
dir.into()
} else {
dirs::data_local_dir().context(error::DataLocalDir)?
};

Ok(decode_path(&dir)?.join("filepack"))
}
}

Expand Down
31 changes: 31 additions & 0 deletions tests/data_dir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use super::*;

#[test]
fn flag() {
Test::new()
.args(["--data-dir", "foo", "keygen"])
.assert_file_regex("foo/keychain/master.public", "public1a.{58}\n")
.assert_file_regex("foo/keychain/master.private", "private1a.{58}\n")
.success();
}

#[test]
fn xdg_data_home() {
Test::new()
.env_remove("FILEPACK_DATA_DIR")
.env("XDG_DATA_HOME", "foo")
.arg("keygen")
.assert_file_regex("foo/filepack/keychain/master.public", "public1a.{58}\n")
.assert_file_regex("foo/filepack/keychain/master.private", "private1a.{58}\n")
.success();
}

#[test]
fn xdg_data_home_empty() {
Test::new()
.env("XDG_DATA_HOME", "")
.arg("keygen")
.assert_file_regex("keychain/master.public", "public1a.{58}\n")
.assert_file_regex("keychain/master.private", "private1a.{58}\n")
.success();
}
1 change: 1 addition & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use {
mod bech32m;
mod contains;
mod create;
mod data_dir;
mod expected;
mod files;
mod fingerprint;
Expand Down
19 changes: 15 additions & 4 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub(crate) struct Test {
args: Vec<String>,
current_dir: Option<String>,
data_dir: Option<String>,
env: BTreeMap<String, String>,
env: BTreeMap<String, Option<String>>,
files: BTreeMap<String, Expected>,
stderr: Expected,
stdin: Option<String>,
Expand Down Expand Up @@ -76,7 +76,12 @@ impl Test {
}

pub(crate) fn env(mut self, key: &str, value: &str) -> Self {
assert!(self.env.insert(key.into(), value.into()).is_none());
assert!(self.env.insert(key.into(), Some(value.into())).is_none());
self
}

pub(crate) fn env_remove(mut self, key: &str) -> Self {
assert!(self.env.insert(key.into(), None).is_none());
self
}

Expand Down Expand Up @@ -155,10 +160,16 @@ impl Test {
self.path()
};

command.env("FILEPACK_DATA_DIR", data_dir);
if !self.env.contains_key("FILEPACK_DATA_DIR") {
command.env("FILEPACK_DATA_DIR", data_dir);
}

for (key, value) in &self.env {
command.env(key, value);
if let Some(value) = value {
command.env(key, value);
} else {
command.env_remove(key);
}
}

command.args(&self.args);
Expand Down