-
Notifications
You must be signed in to change notification settings - Fork 25
Refactor path validation and optimize performance #18
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,47 +6,55 @@ pub(crate) struct CopyFilter; | |
|
|
||
| impl CopyFilter { | ||
| pub(crate) fn excludes(self, path: &Path) -> bool { | ||
| let parts = path | ||
| .components() | ||
| .filter_map(|component| match component { | ||
| Component::Normal(part) => Some(part), | ||
| _ => None, | ||
| }) | ||
| .collect::<Vec<_>>(); | ||
| let mut parts = path.components().filter_map(|component| match component { | ||
| Component::Normal(part) => Some(part), | ||
| _ => None, | ||
| }); | ||
|
|
||
| parts.iter().any(|part| excludes_component(part)) | ||
| || parts | ||
| .windows(2) | ||
| .any(|parts| matches_yarn_artifact(parts[0], parts[1])) | ||
| let first = match parts.next() { | ||
| Some(p) => p, | ||
| None => return false, | ||
| }; | ||
|
|
||
| if excludes_component(first) { | ||
| return true; | ||
| } | ||
|
|
||
| let mut prev = first; | ||
| parts.any(|part| { | ||
| let result = excludes_component(part) || matches_yarn_artifact(prev, part); | ||
| prev = part; | ||
| result | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| fn excludes_component(part: &OsStr) -> bool { | ||
| [ | ||
| "node_modules", | ||
| ".pnpm-store", | ||
| "target", | ||
| ".venv", | ||
| "venv", | ||
| ".tox", | ||
| ".nox", | ||
| "__pycache__", | ||
| ".pytest_cache", | ||
| ".mypy_cache", | ||
| ".ruff_cache", | ||
| ".next", | ||
| ".nuxt", | ||
| ".svelte-kit", | ||
| ".turbo", | ||
| ".vite", | ||
| ".parcel-cache", | ||
| ".cache", | ||
| "dist", | ||
| "build", | ||
| "coverage", | ||
| ] | ||
| .into_iter() | ||
| .any(|excluded| part == excluded) | ||
| let Some(s) = part.to_str() else { return false }; | ||
| matches!( | ||
| s, | ||
| "node_modules" | ||
| | "target" | ||
| | ".pnpm-store" | ||
| | ".venv" | ||
| | "venv" | ||
| | ".tox" | ||
| | ".nox" | ||
| | "__pycache__" | ||
| | ".pytest_cache" | ||
| | ".mypy_cache" | ||
| | ".ruff_cache" | ||
| | ".next" | ||
| | ".nuxt" | ||
| | ".svelte-kit" | ||
| | ".turbo" | ||
| | ".vite" | ||
| | ".parcel-cache" | ||
| | ".cache" | ||
| | "dist" | ||
| | "build" | ||
| | "coverage" | ||
| ) | ||
|
Comment on lines
+33
to
+57
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
| } | ||
|
|
||
| fn matches_yarn_artifact(first: &OsStr, second: &OsStr) -> bool { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -207,9 +207,6 @@ impl Manager { | |
| None => default_storage(&root.path)?, | ||
| }; | ||
| let name = RiftName::from_optional(input.name)?; | ||
| if destination_parent.join(name.as_str()).starts_with(&from) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should keep the early check that stops copying into the source itself |
||
| return Err(Error::InsideSource(destination_parent.join(name.as_str()))); | ||
| } | ||
| fs::create_dir_all(&destination_parent)?; | ||
| let destination_parent = fs::canonicalize(destination_parent)?; | ||
| let destination = destination_parent.join(name.as_str()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prolly not meaningful difference in perf so i'd prefer to keep the current pretty impl