2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-28 15:56:37 +00:00

deduplicate string formatting of snapshot metadata

This removes the spurious ")" bracket at the end and normalizes the
metadata format used by the `ls` command.
This commit is contained in:
Michael Eischer 2024-01-06 20:19:17 +01:00
parent 045aa64558
commit 33b7c84a7a
5 changed files with 6 additions and 6 deletions

View File

@ -131,7 +131,7 @@ func runCopy(ctx context.Context, opts CopyOptions, gopts GlobalOptions, args []
isCopy := false isCopy := false
for _, originalSn := range originalSns { for _, originalSn := range originalSns {
if similarSnapshots(originalSn, sn) { if similarSnapshots(originalSn, sn) {
Verboseff("\nsnapshot %s of %v at %s by %s@%s)\n", sn.ID().Str(), sn.Paths, sn.Time, sn.Username, sn.Hostname) Verboseff("\n%v\n", sn)
Verboseff("skipping source snapshot %s, was already copied to snapshot %s\n", sn.ID().Str(), originalSn.ID().Str()) Verboseff("skipping source snapshot %s, was already copied to snapshot %s\n", sn.ID().Str(), originalSn.ID().Str())
isCopy = true isCopy = true
break break
@ -141,7 +141,7 @@ func runCopy(ctx context.Context, opts CopyOptions, gopts GlobalOptions, args []
continue continue
} }
} }
Verbosef("\nsnapshot %s of %v at %s by %s@%s)\n", sn.ID().Str(), sn.Paths, sn.Time, sn.Username, sn.Hostname) Verbosef("\n%v\n", sn)
Verbosef(" copy started, this may take a while...\n") Verbosef(" copy started, this may take a while...\n")
if err := copyTree(ctx, srcRepo, dstRepo, visitedTrees, *sn.Tree, gopts.Quiet); err != nil { if err := copyTree(ctx, srcRepo, dstRepo, visitedTrees, *sn.Tree, gopts.Quiet); err != nil {
return err return err

View File

@ -207,7 +207,7 @@ func runLs(ctx context.Context, opts LsOptions, gopts GlobalOptions, args []stri
} }
} else { } else {
printSnapshot = func(sn *restic.Snapshot) { printSnapshot = func(sn *restic.Snapshot) {
Verbosef("snapshot %s of %v filtered by %v at %s by %s@%s):\n", sn.ID().Str(), sn.Paths, dirs, sn.Time, sn.Username, sn.Hostname) Verbosef("%v filtered by %v:\n", sn, dirs)
} }
printNode = func(path string, node *restic.Node) { printNode = func(path string, node *restic.Node) {
Printf("%s\n", formatNode(path, node, lsOptions.ListLong, lsOptions.HumanReadable)) Printf("%s\n", formatNode(path, node, lsOptions.ListLong, lsOptions.HumanReadable))

View File

@ -144,7 +144,7 @@ func runRepairSnapshots(ctx context.Context, gopts GlobalOptions, opts RepairOpt
changedCount := 0 changedCount := 0
for sn := range FindFilteredSnapshots(ctx, snapshotLister, repo, &opts.SnapshotFilter, args) { for sn := range FindFilteredSnapshots(ctx, snapshotLister, repo, &opts.SnapshotFilter, args) {
Verbosef("\nsnapshot %s of %v at %s by %s@%s)\n", sn.ID().Str(), sn.Paths, sn.Time, sn.Username, sn.Hostname) Verbosef("\n%v\n", sn)
changed, err := filterAndReplaceSnapshot(ctx, repo, sn, changed, err := filterAndReplaceSnapshot(ctx, repo, sn,
func(ctx context.Context, sn *restic.Snapshot) (restic.ID, error) { func(ctx context.Context, sn *restic.Snapshot) (restic.ID, error) {
return rewriter.RewriteTree(ctx, repo, "/", *sn.Tree) return rewriter.RewriteTree(ctx, repo, "/", *sn.Tree)

View File

@ -290,7 +290,7 @@ func runRewrite(ctx context.Context, opts RewriteOptions, gopts GlobalOptions, a
changedCount := 0 changedCount := 0
for sn := range FindFilteredSnapshots(ctx, snapshotLister, repo, &opts.SnapshotFilter, args) { for sn := range FindFilteredSnapshots(ctx, snapshotLister, repo, &opts.SnapshotFilter, args) {
Verbosef("\nsnapshot %s of %v at %s by %s@%s)\n", sn.ID().Str(), sn.Paths, sn.Time, sn.Username, sn.Hostname) Verbosef("\n%v\n", sn)
changed, err := rewriteSnapshot(ctx, repo, sn, opts) changed, err := rewriteSnapshot(ctx, repo, sn, opts)
if err != nil { if err != nil {
return errors.Fatalf("unable to rewrite snapshot ID %q: %v", sn.ID().Str(), err) return errors.Fatalf("unable to rewrite snapshot ID %q: %v", sn.ID().Str(), err)

View File

@ -96,7 +96,7 @@ func ForAllSnapshots(ctx context.Context, be Lister, loader LoaderUnpacked, excl
} }
func (sn Snapshot) String() string { func (sn Snapshot) String() string {
return fmt.Sprintf("<Snapshot %s of %v at %s by %s@%s>", return fmt.Sprintf("snapshot %s of %v at %s by %s@%s",
sn.id.Str(), sn.Paths, sn.Time, sn.Username, sn.Hostname) sn.id.Str(), sn.Paths, sn.Time, sn.Username, sn.Hostname)
} }