follow symlinks#110
Conversation
Reviewer's GuideThis PR implements recursive symlink-aware traversal by refactoring directory scanning, introduces an IsDir helper to follow symlinks, updates tests and test data for symlinked files, adjusts assertions to handle duplicate entries, updates CLI usage and docs to mention symlink support and adds a --copy flag, and bumps the version to 1.2.0. Sequence diagram for symlink-aware recursive directory traversalsequenceDiagram
participant Caller
participant "Snaggle()"
participant "internal.IsDir()"
participant "snagdir()"
participant "snagfile()"
Caller->>"Snaggle()": Call with path
"Snaggle()"->>"internal.IsDir()": Check if path is directory (follows symlinks)
alt IsDir returns true
"Snaggle()"->>"snagdir()": Traverse directory
loop For each file in directory
"snagdir()"->>"internal.IsDir()": Check if file is directory (follows symlinks)
alt IsDir returns true and recursive
"snagdir()"->>"snagdir()": Recurse into subdirectory
else IsDir returns false
"snagdir()"->>"snagfile()": Process file
end
end
else IsDir returns false
"Snaggle()"->>"snagfile()": Process file
end
Class diagram for new and updated directory traversal helpersclassDiagram
class internal {
+IsDir(path string) bool
}
class Snaggle {
+Snaggle(path string, root string, opts ...Option) error
}
class snagdir {
+snagdir(dir string) error
}
class snagfile {
+snagfile(path string) error
}
Snaggle --> snagdir : uses
Snaggle --> snagfile : uses
snagdir --> internal : uses IsDir
snagdir --> snagfile : uses
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #110 +/- ##
==========================================
- Coverage 76.59% 76.27% -0.32%
==========================================
Files 13 13
Lines 752 763 +11
==========================================
+ Hits 576 582 +6
- Misses 119 123 +4
- Partials 57 58 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- Add guards against symlink cycles in snagdir to avoid infinite recursion when following circular symlinks.
- internal.IsDir silently ignores errors from os.Stat and EvalSymlinks; propagate or handle errors explicitly to prevent panics or hidden failures.
- Error handling in the new directory traversal is inconsistent (some errors are returned raw, others wrapped in SnaggleError/InvocationError); consider unifying error wrapping for consistency.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Add guards against symlink cycles in snagdir to avoid infinite recursion when following circular symlinks.
- internal.IsDir silently ignores errors from os.Stat and EvalSymlinks; propagate or handle errors explicitly to prevent panics or hidden failures.
- Error handling in the new directory traversal is inconsistent (some errors are returned raw, others wrapped in SnaggleError/InvocationError); consider unifying error wrapping for consistency.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
closes #93
Summary by Sourcery
Add support for following symbolic links when recursively snagging directories and files, including updates to the CLI usage, internal traversal logic, tests, and documentation.
New Features:
Enhancements:
Documentation:
Tests:
Chores: