Merge branch 'main' into P11c
This commit is contained in:
commit
1c88667ade
3 files changed
+22
-5
No files matched your search
@@ -15,7 +15,13 @@ fn names(dir: &Path) -> Vec<String> {
|
||||
if p.is_dir() {
|
||||
walk(base, &p, out);
|
||||
} else {
|
||||
out.push(p.strip_prefix(base).unwrap().to_string_lossy().into_owned());
|
||||
// One spelling on every OS (Windows walks with backslashes).
|
||||
out.push(
|
||||
p.strip_prefix(base)
|
||||
.unwrap()
|
||||
.to_string_lossy()
|
||||
.replace('\\', "/"),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,7 +512,12 @@ impl Root {
|
||||
chosen: Option<&Path>,
|
||||
xdg_data_home: Option<&Path>,
|
||||
) -> Result<(Self, SetupReport), RootError> {
|
||||
let default = default_root(home);
|
||||
// The default as the system spells it, since a chosen root is
|
||||
// resolved that way too: on macOS `/tmp` is `/private/tmp`, and a
|
||||
// root chosen at the default must read as the default (so the
|
||||
// record goes), not as somewhere else.
|
||||
let default =
|
||||
default_root(&std::fs::canonicalize(home).unwrap_or_else(|_| home.to_path_buf()));
|
||||
let recorded = recorded_root(home)?;
|
||||
let current = recorded.clone().unwrap_or_else(|| default.clone());
|
||||
let path = match (chosen, &recorded, xdg_data_home) {
|
||||
|
||||
@@ -156,11 +156,14 @@ fn the_root_is_found_without_the_environment() {
|
||||
default_root(home.path()),
|
||||
platform_data_dir(home.path()).join("wanderbooks")
|
||||
);
|
||||
// An explicit root wins.
|
||||
// An explicit root wins (answered as the system spells it: macOS
|
||||
// keeps /tmp as /private/tmp).
|
||||
let elsewhere = home.path().join("elsewhere");
|
||||
assert_eq!(
|
||||
Root::locate(home.path(), Some(&elsewhere)).unwrap(),
|
||||
elsewhere
|
||||
std::fs::canonicalize(home.path())
|
||||
.unwrap()
|
||||
.join("elsewhere")
|
||||
);
|
||||
// A recorded root is used when none is given.
|
||||
std::fs::create_dir_all(platform_data_dir(home.path())).unwrap();
|
||||
@@ -211,7 +214,10 @@ fn setup_records_a_root_chosen_elsewhere_and_forgets_it_when_back_to_default() {
|
||||
assert_eq!(Root::find_in(home.path(), None).unwrap().path(), chosen);
|
||||
// Back to the default (it holds no books): the record goes.
|
||||
let (root, report) = Root::setup(home.path(), Some(&default_root(home.path())), None).unwrap();
|
||||
assert_eq!(root.path(), default_root(home.path()));
|
||||
assert_eq!(
|
||||
root.path(),
|
||||
default_root(&std::fs::canonicalize(home.path()).unwrap())
|
||||
);
|
||||
assert!(!report.recorded && !pointer.exists());
|
||||
|
||||
// $XDG_DATA_HOME is honoured at setup, when nothing is recorded, and
|
||||
|
||||
Reference in new issue
Block a user