From 353183dc794c49bb23371f945cd15991307df228 Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Sat, 1 May 2021 13:35:03 -0500 Subject: [PATCH] Don't check git for symlinks Co-authored-by: Jesse Hoobergs --- derive/src/compile_bytecode.rs | 53 +++++----------------------------- 1 file changed, 7 insertions(+), 46 deletions(-) diff --git a/derive/src/compile_bytecode.rs b/derive/src/compile_bytecode.rs index 29c9497d7..e6f3b7c7a 100644 --- a/derive/src/compile_bytecode.rs +++ b/derive/src/compile_bytecode.rs @@ -31,47 +31,6 @@ static CARGO_MANIFEST_DIR: Lazy = Lazy::new(|| { PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is not present")) }); -fn is_git_symlink(path: &Path) -> bool { - use std::io::{BufRead, BufReader}; - use std::process::{Command, Stdio}; - let res = path.parent().and_then(|dir| { - let git_root = Command::new("git") - .arg("-C") - .arg(dir) - .arg("rev-parse") - .arg("--show-toplevel") - .output() - .ok()? - .stdout; - let git_root = Path::new(std::str::from_utf8(&git_root).unwrap().trim()); - let child = Command::new("git") - .arg("-C") - .arg(git_root) - .arg("ls-files") - .arg("-s") - .stdin(Stdio::null()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .ok()?; - let stdout = BufReader::new(child.stdout.unwrap()); - let lines = stdout - .lines() - .filter_map(|line| line.ok()) - .filter(|line| line.starts_with("120000")); - let path = path.canonicalize().ok()?; - for line in lines { - let link_path = line.splitn(2, '\t').nth(1).unwrap(); - let link_path = git_root.join(link_path).canonicalize().ok()?; - if link_path == path { - return Some(true); - } - } - Some(false) - }); - res.unwrap_or(false) -} - enum CompilationSourceKind { /// Source is a File (Path) File(PathBuf), @@ -158,9 +117,7 @@ impl CompilationSource { let mut code_map = HashMap::new(); let paths = fs::read_dir(path) .or_else(|e| { - // handle git symlinks - git for windows will make it just a text file containing - // the target - if cfg!(windows) && is_git_symlink(path) { + if cfg!(windows) { if let Ok(real_path) = fs::read_to_string(path.canonicalize().unwrap()) { return fs::read_dir(real_path.trim()); } @@ -210,10 +167,14 @@ impl CompilationSource { }) }; let code = compile_path(&path).or_else(|e| { - if cfg!(windows) && is_git_symlink(&path) { + if cfg!(windows) { if let Ok(real_path) = fs::read_to_string(path.canonicalize().unwrap()) { let joined = path.parent().unwrap().join(real_path.trim()); - return compile_path(&joined); + if joined.exists() { + return compile_path(&joined); + } else { + return Err(e); + } } } Err(e)