diff --git a/rust/file_utils/src/safe_file_creator.rs b/rust/file_utils/src/safe_file_creator.rs index 75cf2b2c..eddce1a5 100644 --- a/rust/file_utils/src/safe_file_creator.rs +++ b/rust/file_utils/src/safe_file_creator.rs @@ -70,16 +70,6 @@ impl SafeFileCreator { if let Some(metadata) = self.original_metadata.as_ref() { set_file_metadata(&self.dest_path, metadata, false)?; } - let original_permissions = if self.dest_path.exists() { - Some(fs::metadata(&self.dest_path)?.permissions()) - } else { - None - }; - - // Set the original file's permissions to the new file if they exist - if let Some(permissions) = original_permissions { - fs::set_permissions(&self.dest_path, permissions.clone())?; - } Ok(()) } @@ -140,11 +130,6 @@ mod tests { .read_to_string(&mut contents) .unwrap(); assert_eq!(contents.trim(), "Hello, world!"); - - // Verify file permissions - let metadata = fs::metadata(&dest_path).unwrap(); - let permissions = metadata.permissions(); - assert_eq!(permissions.mode() & 0o777, 0o644); // Assuming default creation mode } #[test] diff --git a/rust/gitxetcore/Cargo.toml b/rust/gitxetcore/Cargo.toml index 96869423..5f215ea7 100644 --- a/rust/gitxetcore/Cargo.toml +++ b/rust/gitxetcore/Cargo.toml @@ -79,7 +79,7 @@ nfsserve = "0.10" atty = "0.2" libc = "0.2" itertools = "0.10.5" -shellish_parse = "2.2" +snailquote = "0.3.1" ring = "0.16.20" humantime = "2.1.0" toml = "0.5" diff --git a/rust/gitxetcore/src/git_integration/git_file_tools.rs b/rust/gitxetcore/src/git_integration/git_file_tools.rs index f2d124fb..d319d168 100644 --- a/rust/gitxetcore/src/git_integration/git_file_tools.rs +++ b/rust/gitxetcore/src/git_integration/git_file_tools.rs @@ -233,7 +233,7 @@ pub fn decode_git_string(s_in: &str) -> String { return s_in.to_owned(); } - // Are there any actually unicode characters here? + // Are there any actually unicode charcters here? let mut i = match s_in.find('\\') { Some(idx) => idx, None => { @@ -289,24 +289,14 @@ pub fn decode_git_string(s_in: &str) -> String { }; // this unescapes all the rest of the \t, \\, etc. - if s_utf8.len() <= 1 { - s_utf8.to_owned() - } else { - match shellish_parse::parse(&s_utf8[1..], false) { - Ok(s) => { - if !s.is_empty() { - s[0].clone() - } else { - s_utf8.to_owned() - } - } - Err(e) => { - warn!( - "Error interpreting raw git string {} from git: {:?}.", - &s_utf8, e - ); - s_utf8.to_owned() - } + match snailquote::unescape(s_utf8) { + Ok(s) => s, + Err(e) => { + warn!( + "Error interpreting raw git string {} from git: {:?}.", + &s_utf8, e + ); + s_utf8.to_owned() } } } @@ -462,20 +452,4 @@ mod git_file_tools_tests { assert_eq!(out_list(None, false)?, files); Ok(()) } - - #[tokio::test(flavor = "multi_thread")] - async fn test_decode_git_string() -> Result<()> { - // let strange_file_name = r#""\303\273n\303\255c\303\265d\303\251"#; - let strange_file_name = r#""another\tstrange\tfile.dat"#; - assert_eq!( - decode_git_string(strange_file_name), - String::from("another\tstrange\tfile.dat") - ); - let strange_file_name = r#""\\backslash\\\\"#; - assert_eq!( - decode_git_string(strange_file_name), - String::from("\\backslash\\\\") - ); - Ok(()) - } } diff --git a/rust/gitxetcore/src/git_integration/git_xet_repo.rs b/rust/gitxetcore/src/git_integration/git_xet_repo.rs index 4a4f132e..6569193c 100644 --- a/rust/gitxetcore/src/git_integration/git_xet_repo.rs +++ b/rust/gitxetcore/src/git_integration/git_xet_repo.rs @@ -126,13 +126,19 @@ impl GitXetRepo { .map(|(_name, url)| url) .collect()) } + pub fn open(config: XetConfig) -> Result { + let repo_path = config.repo_path()?.clone(); + Self::open_at(config, repo_path) + } /// Open the repository, assuming that the current directory is itself in the repository. /// /// If we are running in a way that is not associated with a repo, then the XetConfig path /// will not show we are in a repo. - pub fn open(config: XetConfig) -> Result { - let repo = open_libgit2_repo(config.repo_path()?)?; + pub fn open_at(mut config: XetConfig, repo_path: PathBuf) -> Result { + let repo = open_libgit2_repo(&repo_path)?; + config.repo_path_if_present = Some(repo_path); + let config = config; let git_dir = repo.path().to_path_buf(); let repo_dir = repo_dir_from_repo(&repo);