mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
Fix path prefix issue on Windows (again)
This commit is contained in:
parent
006761cff0
commit
f7ecf2e179
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -1786,6 +1786,7 @@ dependencies = [
|
||||
"lmdb-rkv-sys",
|
||||
"memoize",
|
||||
"mime",
|
||||
"normpath",
|
||||
"nostr-types",
|
||||
"parking_lot",
|
||||
"qrcode",
|
||||
@ -2602,6 +2603,15 @@ dependencies = [
|
||||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "normpath"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec60c60a693226186f5d6edf073232bfb6464ed97eb22cf3b01c1e8198fd97f5"
|
||||
dependencies = [
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nostr-types"
|
||||
version = "0.7.0-unstable"
|
||||
|
@ -71,6 +71,9 @@ url = "2.4"
|
||||
vecmap-rs = "0.1"
|
||||
zeroize = "1.6"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
normpath = "1.1"
|
||||
|
||||
# Force scrypt to build with release-like speed even in dev mode
|
||||
[profile.dev.package.scrypt]
|
||||
opt-level = 3
|
||||
|
@ -2,9 +2,12 @@ use crate::error::Error;
|
||||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::RwLock;
|
||||
|
||||
#[cfg(windows)]
|
||||
use normpath::PathExt;
|
||||
|
||||
lazy_static! {
|
||||
static ref CURRENT: RwLock<Option<Profile>> = RwLock::new(None);
|
||||
}
|
||||
@ -32,21 +35,21 @@ impl Profile {
|
||||
.ok_or::<Error>("Cannot find a directory to store application data.".into())?;
|
||||
|
||||
// Canonicalize (follow symlinks, resolve ".." paths)
|
||||
let data_dir = fs::canonicalize(data_dir)?;
|
||||
let data_dir = normalize(data_dir)?;
|
||||
|
||||
// Push "gossip" to data_dir, or override with GOSSIP_DIR
|
||||
let base_dir = match env::var("GOSSIP_DIR") {
|
||||
Ok(dir) => {
|
||||
tracing::info!("Using GOSSIP_DIR: {}", dir);
|
||||
// Note, this must pre-exist
|
||||
fs::canonicalize(PathBuf::from(dir))?
|
||||
normalize(dir)?
|
||||
}
|
||||
Err(_) => {
|
||||
let mut base_dir = data_dir;
|
||||
base_dir.push("gossip");
|
||||
// We canonicalize here because gossip might be a link, but if it
|
||||
// doesn't exist yet we have to just go with basedir
|
||||
fs::canonicalize(base_dir.as_path()).unwrap_or(base_dir)
|
||||
normalize(base_dir.as_path()).unwrap_or(base_dir)
|
||||
}
|
||||
};
|
||||
|
||||
@ -125,3 +128,13 @@ impl Profile {
|
||||
Ok(created)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn normalize<P: AsRef<Path>>(path: P) -> Result<PathBuf, Error> {
|
||||
Ok(fs::canonicalize(path)?)
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn normalize<P: AsRef<Path>>(path: P) -> Result<PathBuf, Error> {
|
||||
Ok(path.normalize()?)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user