mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Don't check git for symlinks
Co-authored-by: Jesse Hoobergs <jhoobergs@users.noreply.github.com>
This commit is contained in:
@@ -31,47 +31,6 @@ static CARGO_MANIFEST_DIR: Lazy<PathBuf> = 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)
|
||||
|
||||
Reference in New Issue
Block a user