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",
|
"lmdb-rkv-sys",
|
||||||
"memoize",
|
"memoize",
|
||||||
"mime",
|
"mime",
|
||||||
|
"normpath",
|
||||||
"nostr-types",
|
"nostr-types",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"qrcode",
|
"qrcode",
|
||||||
@ -2602,6 +2603,15 @@ dependencies = [
|
|||||||
"minimal-lexical",
|
"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]]
|
[[package]]
|
||||||
name = "nostr-types"
|
name = "nostr-types"
|
||||||
version = "0.7.0-unstable"
|
version = "0.7.0-unstable"
|
||||||
|
@ -71,6 +71,9 @@ url = "2.4"
|
|||||||
vecmap-rs = "0.1"
|
vecmap-rs = "0.1"
|
||||||
zeroize = "1.6"
|
zeroize = "1.6"
|
||||||
|
|
||||||
|
[target.'cfg(windows)'.dependencies]
|
||||||
|
normpath = "1.1"
|
||||||
|
|
||||||
# Force scrypt to build with release-like speed even in dev mode
|
# Force scrypt to build with release-like speed even in dev mode
|
||||||
[profile.dev.package.scrypt]
|
[profile.dev.package.scrypt]
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
|
@ -2,9 +2,12 @@ use crate::error::Error;
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
use normpath::PathExt;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref CURRENT: RwLock<Option<Profile>> = RwLock::new(None);
|
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())?;
|
.ok_or::<Error>("Cannot find a directory to store application data.".into())?;
|
||||||
|
|
||||||
// Canonicalize (follow symlinks, resolve ".." paths)
|
// 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
|
// Push "gossip" to data_dir, or override with GOSSIP_DIR
|
||||||
let base_dir = match env::var("GOSSIP_DIR") {
|
let base_dir = match env::var("GOSSIP_DIR") {
|
||||||
Ok(dir) => {
|
Ok(dir) => {
|
||||||
tracing::info!("Using GOSSIP_DIR: {}", dir);
|
tracing::info!("Using GOSSIP_DIR: {}", dir);
|
||||||
// Note, this must pre-exist
|
// Note, this must pre-exist
|
||||||
fs::canonicalize(PathBuf::from(dir))?
|
normalize(dir)?
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let mut base_dir = data_dir;
|
let mut base_dir = data_dir;
|
||||||
base_dir.push("gossip");
|
base_dir.push("gossip");
|
||||||
// We canonicalize here because gossip might be a link, but if it
|
// We canonicalize here because gossip might be a link, but if it
|
||||||
// doesn't exist yet we have to just go with basedir
|
// 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)
|
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