mirror of
https://github.com/restic/restic.git
synced 2026-08-22 05:23:19 +00:00
Merge pull request #21811 from MichaelEischer/misc-fixes
Address various code smells, outdated comments and nits
This commit is contained in:
@@ -22,6 +22,9 @@ import (
|
||||
"github.com/restic/restic/internal/walker"
|
||||
)
|
||||
|
||||
// errFindDone is returned from the tree walk when all requested tree IDs were found.
|
||||
var errFindDone = errors.New("find: all tree IDs found")
|
||||
|
||||
func newFindCommand(globalOptions *global.Options) *cobra.Command {
|
||||
var opts FindOptions
|
||||
|
||||
@@ -160,7 +163,7 @@ func (s *statefulOutput) PrintPatternJSON(path string, node *data.Node) {
|
||||
findNode: (*findNode)(node),
|
||||
})
|
||||
if err != nil {
|
||||
s.printer.E("Marshall failed: %v", err)
|
||||
s.printer.E("Marshal failed: %v", err)
|
||||
return
|
||||
}
|
||||
if !s.inuse {
|
||||
@@ -219,7 +222,7 @@ func (s *statefulOutput) PrintObjectJSON(kind, id, nodepath, treeID string, sn *
|
||||
Time: sn.Time,
|
||||
})
|
||||
if err != nil {
|
||||
s.printer.E("Marshall failed: %v", err)
|
||||
s.printer.E("Marshal failed: %v", err)
|
||||
return
|
||||
}
|
||||
if !s.inuse {
|
||||
@@ -375,7 +378,7 @@ func (f *Finder) findTree(treeID restic.ID, nodepath string) error {
|
||||
// looking for blobs)
|
||||
if f.itemsFound >= len(f.treeIDs) && f.blobIDs == nil {
|
||||
// Return an error to terminate the Walk
|
||||
return errors.New("OK")
|
||||
return errFindDone
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -688,7 +691,7 @@ func runFind(ctx context.Context, opts FindOptions, gopts global.Options, args [
|
||||
|
||||
for _, sn := range filteredSnapshots {
|
||||
if f.blobIDs != nil || f.treeIDs != nil {
|
||||
if err = f.findIDs(ctx, sn); err != nil && err.Error() != "OK" {
|
||||
if err = f.findIDs(ctx, sn); err != nil && !errors.Is(err, errFindDone) {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
// initMultiSnapshotFilter is used for commands that work on multiple snapshots
|
||||
// MUST be combined with restic.FindFilteredSnapshots or FindFilteredSnapshots
|
||||
// MUST be combined with FindFilteredSnapshots
|
||||
// MUST be followed by finalizeSnapshotFilter after flag parsing
|
||||
func initMultiSnapshotFilter(flags *pflag.FlagSet, filt *data.SnapshotFilter, addHostShorthand bool) {
|
||||
hostShorthand := "H"
|
||||
@@ -24,7 +24,7 @@ func initMultiSnapshotFilter(flags *pflag.FlagSet, filt *data.SnapshotFilter, ad
|
||||
}
|
||||
|
||||
// initSingleSnapshotFilter is used for commands that work on a single snapshot
|
||||
// MUST be combined with restic.FindFilteredSnapshot
|
||||
// MUST be combined with (*data.SnapshotFilter).FindLatest
|
||||
// MUST be followed by finalizeSnapshotFilter after flag parsing
|
||||
func initSingleSnapshotFilter(flags *pflag.FlagSet, filt *data.SnapshotFilter) {
|
||||
flags.StringArrayVarP(&filt.Hosts, "host", "H", nil, "only consider snapshots for this `host`, when snapshot ID \"latest\" is given (can be specified multiple times, use empty string to unset default value) (default: $RESTIC_HOST)")
|
||||
|
||||
@@ -37,6 +37,8 @@ func internalOpenWithLocked(ctx context.Context, gopts global.Options, dryRun bo
|
||||
|
||||
func openWithReadLock(ctx context.Context, gopts global.Options, noLock bool, printer progress.Printer) (context.Context, *repository.Repository, func(), error) {
|
||||
// TODO enforce read-only operations once the locking code has moved to the repository
|
||||
// As in-depth hardening, put the repository into read-only mode if noLock is true
|
||||
// Not possible if the repository has to be locked.
|
||||
return internalOpenWithLocked(ctx, gopts, noLock, false, printer)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user