Skip to content

Commit 21f6bcb

Browse files
committed
attempt at fixing the graph writing logic for windows
1 parent 69fee1b commit 21f6bcb

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

raphtory-graphql/src/data.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::{
2121
path::{Path, PathBuf},
2222
sync::Arc,
2323
};
24+
use std::ffi::OsStr;
2425
use tokio::fs;
2526
use tracing::warn;
2627
use walkdir::WalkDir;
@@ -282,28 +283,17 @@ impl Data {
282283
/// Serializes a graph to disk, overwriting any existing data in its folder.
283284
fn encode_graph_to_disk(graph: GraphWithVectors) -> Result<(), GraphError> {
284285
let folder_path = graph.folder.get_base_path();
286+
let bak_name = "_".to_string() + folder_path.file_name().and_then(|n| n.to_str()).unwrap_or("");
287+
let bak_path = folder_path.with_file_name(bak_name);
285288

286-
// Create a backup of the existing folder
289+
// Write to backup path first
290+
graph.graph.encode(&bak_path)?;
291+
287292
if folder_path.exists() {
288-
let bak_path = folder_path.with_extension("bak");
289-
290-
// Remove any old backups
291-
if bak_path.exists() {
292-
std::fs::remove_dir_all(&bak_path)?;
293-
}
294-
295-
std::fs::rename(&folder_path, &bak_path)?;
296-
}
297-
298-
// Serialize the graph to the original folder path
299-
graph.graph.encode(&folder_path)?;
300-
301-
// Delete the backup on success
302-
let bak_path = folder_path.with_extension("bak");
303-
304-
if bak_path.exists() {
305-
std::fs::remove_dir_all(&bak_path)?;
293+
// delete old data
294+
std::fs::remove_dir_all(folder_path)?;
306295
}
296+
std::fs::rename(&bak_path, folder_path)?;
307297

308298
Ok(())
309299
}

raphtory-graphql/src/paths.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,12 @@ pub(crate) fn valid_path(
125125
}
126126
full_path.push(component);
127127
//check if the path with the component is a graph
128-
if namespace && full_path.join(META_PATH).exists() {
129-
return Err(InvalidPathReason::ParentIsGraph(user_facing_path));
128+
if full_path.join(META_PATH).exists() {
129+
if namespace {
130+
return Err(InvalidPathReason::ParentIsGraph(user_facing_path));
131+
} else if component.to_str().ok_or(InvalidPathReason::NonUTFCharacters)?.starts_with("_") {
132+
return Err(InvalidPathReason::GraphNamePrefix)
133+
}
130134
}
131135
//check for symlinks
132136
if full_path.is_symlink() {

raphtory/src/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ pub enum InvalidPathReason {
5454
PathNotParsable(PathBuf),
5555
#[error("The path to the graph contains a subpath to an existing graph: {0}")]
5656
ParentIsGraph(PathBuf),
57+
#[error("Graph name cannot start with _")]
58+
GraphNamePrefix,
5759
#[error("The path provided does not exists as a namespace: {0}")]
5860
NamespaceDoesNotExist(String),
5961
#[error("The path provided contains non-UTF8 characters.")]

0 commit comments

Comments
 (0)