-
Notifications
You must be signed in to change notification settings - Fork 594
fix(cli): fix path printed by "kopia snapshot fix" commands #4638
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4638 +/- ##
==========================================
+ Coverage 75.86% 76.40% +0.53%
==========================================
Files 470 529 +59
Lines 37301 40160 +2859
==========================================
+ Hits 28299 30683 +2384
- Misses 7071 7457 +386
- Partials 1931 2020 +89 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
70b8b69 to
e76141c
Compare
|
Updated to (hopefully) fix lint errors. |
The dirRelativePath variable is actually the path to the file being checked, but was treated as if it was the path to the parent directory, causing the filename to be duplicated in log messages.
e76141c to
b70be5f
Compare
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.
Pull Request Overview
This PR fixes duplicated filenames in the output of kopia snapshot fix commands by using the full file path instead of reconstructing it manually.
- Renamed
dirRelativePathtopathFromRootin bothrewriteEntrymethods. - Updated log and verifier calls to use
pathFromRootdirectly, removing manual concatenation.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| cli/command_snapshot_fix_remove_files.go | Renamed parameter and adjusted log messages to use the full path from the root. |
| cli/command_snapshot_fix_invalid_files.go | Similarly renamed parameter and updated verifier, log, and callback to use full path. |
Comments suppressed due to low confidence (3)
cli/command_snapshot_fix_remove_files.go:30
- [nitpick] Consider renaming
pathFromRootto a more concise name likeentryPathorfilePathto clearly reflect that this is the full file path being processed.
func (c *commandSnapshotFixRemoveFiles) rewriteEntry(ctx context.Context, pathFromRoot string, ent *snapshot.DirEntry) (*snapshot.DirEntry, error) {
cli/command_snapshot_fix_invalid_files.go:35
- [nitpick] Consider renaming
pathFromRootto a concise name likeentryPathorfilePathfor consistency and readability.
func (c *commandSnapshotFixInvalidFiles) rewriteEntry(ctx context.Context, pathFromRoot string, ent *snapshot.DirEntry) (*snapshot.DirEntry, error) {
cli/command_snapshot_fix_remove_files.go:30
- Add unit tests for
rewriteEntryto verify that the correct full file paths are logged when removing files, ensuring this fix is covered by tests.
func (c *commandSnapshotFixRemoveFiles) rewriteEntry(ctx context.Context, pathFromRoot string, ent *snapshot.DirEntry) (*snapshot.DirEntry, error) {
| for _, id := range c.removeObjectIDs { | ||
| if ent.ObjectID.String() == id { | ||
| log(ctx).Infof("will remove file %v", path.Join(dirRelativePath, ent.Name)) | ||
| log(ctx).Infof("will remove file %v", pathFromRoot) |
Copilot
AI
Jun 5, 2025
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.
Use %s instead of %v when formatting a string path in Infof to make the intention explicit and avoid relying on default formatting.
| log(ctx).Infof("will remove file %v", pathFromRoot) | |
| log(ctx).Infof("will remove file %s", pathFromRoot) |
|
|
||
| if matched { | ||
| log(ctx).Infof("will remove file %v", path.Join(dirRelativePath, ent.Name)) | ||
| log(ctx).Infof("will remove file %v", pathFromRoot) |
Copilot
AI
Jun 5, 2025
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.
Use %s instead of %v when formatting a string path in Infof to make the intention explicit and avoid relying on default formatting.
| log(ctx).Infof("will remove file %v", pathFromRoot) | |
| log(ctx).Infof("will remove file %s", pathFromRoot) |
| if err := c.verifier.VerifyFile(ctx, ent.ObjectID, fname); err != nil { | ||
| log(ctx).Warnf("removing invalid file %v due to: %v", fname, err) | ||
| if err := c.verifier.VerifyFile(ctx, ent.ObjectID, pathFromRoot); err != nil { | ||
| log(ctx).Warnf("removing invalid file %v due to: %v", pathFromRoot, err) |
Copilot
AI
Jun 5, 2025
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.
Use %s instead of %v when logging a string path to make the formatting clearer and more intentional.
| log(ctx).Warnf("removing invalid file %v due to: %v", pathFromRoot, err) | |
| log(ctx).Warnf("removing invalid file %s due to: %v", pathFromRoot, err) |
The
dirRelativePathvariable is actually the path to the file being checked, but was treated as if it was the path to the parent directory, causing the filename to be duplicated in log messages. This PR fixes that.Here is the output of
remove-fileson stock Kopia 0.20.1:Evidently, the last path component is duplicated. The paths printed do not actually exist, but the paths printed minus the duplicated last path component do exist.
For demonstration of correctness of the fix, here is the output after adding a log statement to print
dirRelativePathandent.Name:It can be seen that the path is the path of the file being checked, not the parent directory.