Skip to content

Remove absolute path guessing. #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions src/path_rewriting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,6 @@ fn apply_mapping(mapping: &Option<Value>, path: &str) -> PathBuf {
PathBuf::from(path)
}

// If the join of the source and the relative path is a file, return it.
// Otherwise, remove common part between the source's end and the relative
// path's start.
fn guess_abs_path(prefix_dir: &PathBuf, path: &PathBuf) -> PathBuf {
let full_path = prefix_dir.join(path);
if full_path.is_file() {
return full_path;
}
for ancestor in path.ancestors() {
if prefix_dir.ends_with(ancestor) && !ancestor.as_os_str().is_empty() {
return prefix_dir.join(path.strip_prefix(ancestor).unwrap().to_path_buf());
}
}
full_path
}

// Remove prefix from the source file's path.
fn remove_prefix(prefix_dir: &Option<PathBuf>, path: PathBuf) -> PathBuf {
if let Some(prefix_dir) = prefix_dir {
Expand Down Expand Up @@ -136,12 +120,9 @@ fn get_abs_path(source_dir: &Option<PathBuf>, rel_path: PathBuf) -> Option<(Path
rel_path.clone()
} else if let Some(ref source_dir) = source_dir {
if !cfg!(windows) {
guess_abs_path(&source_dir, &rel_path)
source_dir.join(&rel_path)
} else {
guess_abs_path(
&source_dir,
&PathBuf::from(&rel_path.to_str().unwrap().replace("/", "\\")),
)
source_dir.join(&rel_path.to_str().unwrap().replace("/", "\\"))
}
} else {
rel_path.clone()
Expand Down