Skip to content

Commit d6093e5

Browse files
committed
f Canonicalize paths on Windows
1 parent 0cd175b commit d6093e5

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

lightning-persister/src/fs_store.rs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,35 @@ impl FilesystemStore {
6666
outer_lock.retain(|_, v| Arc::strong_count(&v) > 1);
6767
}
6868
}
69+
70+
fn get_dest_dir_path(&self, namespace: &str, sub_namespace: &str) -> std::io::Result<PathBuf> {
71+
let mut dest_dir_path = {
72+
#[cfg(target_os = "windows")]
73+
{
74+
let data_dir = self.data_dir.clone();
75+
fs::create_dir_all(data_dir.clone())?;
76+
fs::canonicalize(data_dir)?
77+
}
78+
#[cfg(not(target_os = "windows"))]
79+
{
80+
self.data_dir.clone()
81+
}
82+
};
83+
84+
dest_dir_path.push(namespace);
85+
if !sub_namespace.is_empty() {
86+
dest_dir_path.push(sub_namespace);
87+
}
88+
89+
Ok(dest_dir_path)
90+
}
6991
}
7092

7193
impl KVStore for FilesystemStore {
7294
fn read(&self, namespace: &str, sub_namespace: &str, key: &str) -> std::io::Result<Vec<u8>> {
7395
check_namespace_key_validity(namespace, sub_namespace, Some(key), "read")?;
7496

75-
let mut dest_file_path = self.data_dir.clone();
76-
dest_file_path.push(namespace);
77-
if !sub_namespace.is_empty() {
78-
dest_file_path.push(sub_namespace);
79-
}
97+
let mut dest_file_path = self.get_dest_dir_path(namespace, sub_namespace)?;
8098
dest_file_path.push(key);
8199

82100
let mut buf = Vec::new();
@@ -99,11 +117,7 @@ impl KVStore for FilesystemStore {
99117
fn write(&self, namespace: &str, sub_namespace: &str, key: &str, buf: &[u8]) -> std::io::Result<()> {
100118
check_namespace_key_validity(namespace, sub_namespace, Some(key), "write")?;
101119

102-
let mut dest_file_path = self.data_dir.clone();
103-
dest_file_path.push(namespace);
104-
if !sub_namespace.is_empty() {
105-
dest_file_path.push(sub_namespace);
106-
}
120+
let mut dest_file_path = self.get_dest_dir_path(namespace, sub_namespace)?;
107121
dest_file_path.push(key);
108122

109123
let parent_directory = dest_file_path
@@ -190,11 +204,7 @@ impl KVStore for FilesystemStore {
190204
fn remove(&self, namespace: &str, sub_namespace: &str, key: &str, lazy: bool) -> std::io::Result<()> {
191205
check_namespace_key_validity(namespace, sub_namespace, Some(key), "remove")?;
192206

193-
let mut dest_file_path = self.data_dir.clone();
194-
dest_file_path.push(namespace);
195-
if !sub_namespace.is_empty() {
196-
dest_file_path.push(sub_namespace);
197-
}
207+
let mut dest_file_path = self.get_dest_dir_path(namespace, sub_namespace)?;
198208
dest_file_path.push(key);
199209

200210
if !dest_file_path.is_file() {
@@ -283,12 +293,7 @@ impl KVStore for FilesystemStore {
283293
fn list(&self, namespace: &str, sub_namespace: &str) -> std::io::Result<Vec<String>> {
284294
check_namespace_key_validity(namespace, sub_namespace, None, "list")?;
285295

286-
let mut prefixed_dest = self.data_dir.clone();
287-
prefixed_dest.push(namespace);
288-
if !sub_namespace.is_empty() {
289-
prefixed_dest.push(sub_namespace);
290-
}
291-
296+
let prefixed_dest = self.get_dest_dir_path(namespace, sub_namespace)?;
292297
let mut keys = Vec::new();
293298

294299
if !Path::new(&prefixed_dest).exists() {

0 commit comments

Comments
 (0)