From 463d67a5a4e028166b8914c49b96ccf3977c0f79 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Wed, 20 Mar 2024 21:11:30 -0700 Subject: [PATCH] Widnows attempt #1 --- Cargo.lock | 7 ++ Cargo.toml | 1 + src/fs.rs | 217 ++++++++++++++++++++++++++++------------------------- 3 files changed, 124 insertions(+), 101 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 31cd822..63e07c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -686,6 +686,7 @@ dependencies = [ "itertools", "open", "parking_lot", + "path-slash", "poem", "rust-embed", "serde", @@ -2139,6 +2140,12 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "path-slash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42" + [[package]] name = "pathdiff" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index fb14f48..cf32aa2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,5 +48,6 @@ insta = { version = "1.34.0", features = [ "json", ] } itertools = "0.12.1" +path-slash = "0.2.1" tempdir = "0.3.7" txtar = "1.0.0" diff --git a/src/fs.rs b/src/fs.rs index 9d13aaa..397c7f6 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -151,6 +151,7 @@ mod tests { use indexmap::IndexMap; use indoc::indoc; use itertools::Itertools; + use path_slash::*; use serde::Serialize; use tempdir::TempDir; @@ -160,13 +161,27 @@ mod tests { scan(path) .map(|(dir_path, file_type)| { ( - dir_path.path().strip_prefix(path).unwrap().to_owned(), + dir_path + .path() + .strip_prefix(path) + .unwrap() + .to_slash_lossy() + .to_string(), file_type, ) }) .collect_vec() } + fn showscan(input: &ThreeDirInput) -> impl Serialize { + let entries = input.scan().unwrap(); + entries + .0 + .into_iter() + .map(|(k, v)| (k.to_slash_lossy().to_string(), v)) + .collect_vec() + } + fn left_right_edit_threedirinput(base: &Path) -> ThreeDirInput { ThreeDirInput { left: base.join("left").to_owned(), @@ -211,43 +226,43 @@ mod tests { "###); // TODO: A different bug if edit/subdir/another_file is specified let mut input = left_right_edit_threedirinput(tmp_dir.path()); - insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###" + insta::assert_yaml_snapshot!(showscan(&input), @r###" --- - subdir/txt: - - type: Text - value: "Some text\n" - - type: Text - value: "Changed text\n" - - type: Text - value: "Changed text for editing\n" + - - subdir/txt + - - type: Text + value: "Some text\n" + - type: Text + value: "Changed text\n" + - type: Text + value: "Changed text for editing\n" "###); let () = input .save(IndexMap::from([string_pair("subdir/txt", "Edited text")])) .unwrap(); - insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###" + insta::assert_yaml_snapshot!(showscan(&input), @r###" --- - subdir/txt: - - type: Text - value: "Some text\n" - - type: Text - value: "Changed text\n" - - type: Text - value: Edited text + - - subdir/txt + - - type: Text + value: "Some text\n" + - type: Text + value: "Changed text\n" + - type: Text + value: Edited text "###); // If the file exists on all sides, an empty save means an empty file. let () = input .save(IndexMap::from([string_pair("subdir/txt", "")])) .unwrap(); - insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###" + insta::assert_yaml_snapshot!(showscan(&input), @r###" --- - subdir/txt: - - type: Text - value: "Some text\n" - - type: Text - value: "Changed text\n" - - type: Text - value: "" + - - subdir/txt + - - type: Text + value: "Some text\n" + - type: Text + value: "Changed text\n" + - type: Text + value: "" "###); // Test a validation error @@ -263,15 +278,15 @@ mod tests { ) "###); // Should be the same as previous version - insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###" + insta::assert_yaml_snapshot!(showscan(&input), @r###" --- - subdir/txt: - - type: Text - value: "Some text\n" - - type: Text - value: "Changed text\n" - - type: Text - value: "" + - - subdir/txt + - - type: Text + value: "Some text\n" + - type: Text + value: "Changed text\n" + - type: Text + value: "" "###); } @@ -293,40 +308,40 @@ mod tests { value: "Some text for editing\n" "###); let mut input = left_right_edit_threedirinput(tmp_dir.path()); - insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###" + insta::assert_yaml_snapshot!(showscan(&input), @r###" --- - txt: - - type: Missing - - type: Text - value: "Some text\n" - - type: Text - value: "Some text for editing\n" + - - txt + - - type: Missing + - type: Text + value: "Some text\n" + - type: Text + value: "Some text for editing\n" "###); let () = input .save(IndexMap::from([string_pair("txt", "somevalue")])) .unwrap(); - insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###" + insta::assert_yaml_snapshot!(showscan(&input), @r###" --- - txt: - - type: Missing - - type: Text - value: "Some text\n" - - type: Text - value: somevalue + - - txt + - - type: Missing + - type: Text + value: "Some text\n" + - type: Text + value: somevalue "###); // TODO: If the file is missing on LHS, an empty save should mean that the file // should be deleted. let () = input .save(IndexMap::from([string_pair("txt", "")])) .unwrap(); - insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###" + insta::assert_yaml_snapshot!(showscan(&input), @r###" --- - txt: - - type: Missing - - type: Text - value: "Some text\n" - - type: Text - value: "" + - - txt + - - type: Missing + - type: Text + value: "Some text\n" + - type: Text + value: "" "###); } @@ -343,13 +358,13 @@ mod tests { value: "Some text\n" "###); let mut input = left_right_edit_threedirinput(tmp_dir.path()); - insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###" + insta::assert_yaml_snapshot!(showscan(&input), @r###" --- - txt: - - type: Text - value: "Some text\n" - - type: Missing - - type: Missing + - - txt + - - type: Text + value: "Some text\n" + - type: Missing + - type: Missing "###); let result = input.save(IndexMap::from([string_pair("txt", "somevalue")])); // BUG: We fail to create `right/txt` because `right/` does not exist @@ -367,13 +382,13 @@ mod tests { if path.ends_with("txt") && err.kind() == ErrorKind::NotFound ); - insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###" + insta::assert_yaml_snapshot!(showscan(&input), @r###" --- - txt: - - type: Text - value: "Some text\n" - - type: Missing - - type: Missing + - - txt + - - type: Text + value: "Some text\n" + - type: Missing + - type: Missing "###); } @@ -395,54 +410,54 @@ mod tests { value: "Doesn't matter what goes here\n" "###); let mut input = left_right_edit_threedirinput(tmp_dir.path()); - insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###" + insta::assert_yaml_snapshot!(showscan(&input), @r###" --- - randomfile: - - type: Missing - - type: Missing - - type: Text - value: "Doesn't matter what goes here\n" - txt: - - type: Text - value: "Some text\n" - - type: Missing - - type: Missing + - - randomfile + - - type: Missing + - type: Missing + - type: Text + value: "Doesn't matter what goes here\n" + - - txt + - - type: Text + value: "Some text\n" + - type: Missing + - type: Missing "###); let () = input .save(IndexMap::from([string_pair("txt", "somevalue")])) .unwrap(); - insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###" + insta::assert_yaml_snapshot!(showscan(&input), @r###" --- - randomfile: - - type: Missing - - type: Missing - - type: Text - value: "Doesn't matter what goes here\n" - txt: - - type: Text - value: "Some text\n" - - type: Missing - - type: Text - value: somevalue + - - randomfile + - - type: Missing + - type: Missing + - type: Text + value: "Doesn't matter what goes here\n" + - - txt + - - type: Text + value: "Some text\n" + - type: Missing + - type: Text + value: somevalue "###); // TODO: If the file is missing on RHS, an empty save should mean that the file // should stay (or be) deleted. let () = input .save(IndexMap::from([string_pair("txt", "")])) .unwrap(); - insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###" + insta::assert_yaml_snapshot!(showscan(&input), @r###" --- - randomfile: - - type: Missing - - type: Missing - - type: Text - value: "Doesn't matter what goes here\n" - txt: - - type: Text - value: "Some text\n" - - type: Missing - - type: Text - value: "" + - - randomfile + - - type: Missing + - type: Missing + - type: Text + value: "Doesn't matter what goes here\n" + - - txt + - - type: Text + value: "Some text\n" + - type: Missing + - type: Text + value: "" "###); } }