Release URBM 2026.06.15.r011
This commit is contained in:
@@ -2,6 +2,7 @@ package restic
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -217,13 +218,27 @@ func (r *Runner) stats(ctx context.Context, repo model.Repository, args []string
|
||||
if err := r.run(ctx, repo, args, nil, &output); err != nil {
|
||||
return Stats{}, err
|
||||
}
|
||||
var stats Stats
|
||||
if err := json.Unmarshal(output, &stats); err != nil {
|
||||
stats, err := decodeStats(output)
|
||||
if err != nil {
|
||||
return Stats{}, fmt.Errorf("decode repository stats: %w", err)
|
||||
}
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
func decodeStats(output []byte) (Stats, error) {
|
||||
for index := len(output) - 1; index >= 0; index-- {
|
||||
if output[index] != '{' {
|
||||
continue
|
||||
}
|
||||
var stats Stats
|
||||
decoder := json.NewDecoder(bytes.NewReader(output[index:]))
|
||||
if err := decoder.Decode(&stats); err == nil {
|
||||
return stats, nil
|
||||
}
|
||||
}
|
||||
return Stats{}, errors.New("no valid statistics object in Restic output")
|
||||
}
|
||||
|
||||
func (r *Runner) List(ctx context.Context, repo model.Repository, snapshot, path string) ([]map[string]any, error) {
|
||||
args := []string{"ls", snapshot, "--json"}
|
||||
if path != "" {
|
||||
|
||||
@@ -130,6 +130,31 @@ func TestStatsUsesRequestedRepositoryCountingMode(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatsIgnoresProgressBeforePrettyPrintedJSON(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
script := filepath.Join(dir, "restic")
|
||||
body := `#!/bin/sh
|
||||
printf '%s\n' '[0:00] 100.00% 12 / 12 index files loaded'
|
||||
printf '%s\n' '{'
|
||||
printf '%s\n' ' "total_size": 8192,'
|
||||
printf '%s\n' ' "total_file_count": 24,'
|
||||
printf '%s\n' ' "total_blob_count": 16'
|
||||
printf '%s\n' '}'
|
||||
`
|
||||
if err := os.WriteFile(script, []byte(body), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
runner := &Runner{Binary: script, RuntimeDir: dir, Secrets: fakeSecrets{"password": "secret"}}
|
||||
repo := model.Repository{Type: model.RepositoryLocal, Location: "/repo", PasswordRef: "password"}
|
||||
stats, err := runner.Stats(context.Background(), repo, "raw-data")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if stats.TotalSize != 8192 || stats.TotalFileCount != 24 || stats.TotalBlobCount != 16 {
|
||||
t.Fatalf("unexpected stats: %+v", stats)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatsUnlocksStaleRepositoryLockAndRetries(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
logPath := filepath.Join(dir, "commands")
|
||||
|
||||
Reference in New Issue
Block a user