mirror of
https://github.com/kopia/kopia.git
synced 2026-07-10 13:45:57 -04:00
fix(cli): fixed snapshot sizes in the snapshot list (#2148)
This is caused by a fix where fs.Directory was incorrectly reporting its size == total size of all files in all subdirectories and `snapshot list` was relying on that. Fixes #2144
This commit is contained in:
@@ -378,8 +378,24 @@ func (c *commandSnapshotList) entryBits(ctx context.Context, m *snapshot.Manifes
|
||||
bits = append(bits, "incomplete:"+m.IncompleteReason)
|
||||
}
|
||||
|
||||
var summary *fs.DirectorySummary
|
||||
|
||||
if dws, ok := ent.(fs.DirectoryWithSummary); ok {
|
||||
s, err := dws.Summary(ctx)
|
||||
if err != nil {
|
||||
log(ctx).Warnw("unable to get directory summary", "name", ent.Name(), "err", err)
|
||||
}
|
||||
|
||||
summary = s
|
||||
}
|
||||
|
||||
totalBytes := ent.Size()
|
||||
if summary != nil {
|
||||
totalBytes = summary.TotalFileSize
|
||||
}
|
||||
|
||||
bits = append(bits,
|
||||
maybeHumanReadableBytes(c.snapshotListShowHumanReadable, ent.Size()),
|
||||
maybeHumanReadableBytes(c.snapshotListShowHumanReadable, totalBytes),
|
||||
ent.Mode().String())
|
||||
if c.shapshotListShowOwner {
|
||||
bits = append(bits,
|
||||
@@ -399,15 +415,13 @@ func (c *commandSnapshotList) entryBits(ctx context.Context, m *snapshot.Manifes
|
||||
bits = append(bits, deltaBytes(ent.Size()-lastTotalFileSize))
|
||||
}
|
||||
|
||||
if dws, ok := ent.(fs.DirectoryWithSummary); ok {
|
||||
if s, _ := dws.Summary(ctx); s != nil {
|
||||
bits = append(bits,
|
||||
fmt.Sprintf("files:%v", s.TotalFileCount),
|
||||
fmt.Sprintf("dirs:%v", s.TotalDirCount))
|
||||
if s.FatalErrorCount > 0 {
|
||||
bits = append(bits, fmt.Sprintf("errors:%v", s.FatalErrorCount))
|
||||
col = errorColor
|
||||
}
|
||||
if summary != nil {
|
||||
bits = append(bits,
|
||||
fmt.Sprintf("files:%v", summary.TotalFileCount),
|
||||
fmt.Sprintf("dirs:%v", summary.TotalDirCount))
|
||||
if summary.FatalErrorCount > 0 {
|
||||
bits = append(bits, fmt.Sprintf("errors:%v", summary.FatalErrorCount))
|
||||
col = errorColor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,4 +47,34 @@ func TestSnapshotList(t *testing.T) {
|
||||
for _, s := range snapshots {
|
||||
require.NotEmpty(t, s.RetentionReasons, "expecting retention reason to be set")
|
||||
}
|
||||
|
||||
lines := e.RunAndExpectSuccess(t, "snapshot", "list")
|
||||
require.Len(t, lines, 5)
|
||||
|
||||
require.Contains(t, lines[1], " 3 B ")
|
||||
require.Contains(t, lines[1], " files:1 dirs:1 ")
|
||||
|
||||
require.Contains(t, lines[2], " 7 B ")
|
||||
require.Contains(t, lines[2], " files:2 dirs:1 ")
|
||||
|
||||
require.Contains(t, lines[3], " 8 B ")
|
||||
require.Contains(t, lines[3], " files:3 dirs:1 ")
|
||||
|
||||
require.Contains(t, lines[4], "+ 1 identical snapshots until")
|
||||
|
||||
lines = e.RunAndExpectSuccess(t, "snapshot", "list", "-l")
|
||||
require.Len(t, lines, 5)
|
||||
|
||||
require.Contains(t, lines[1], " 3 B ")
|
||||
require.Contains(t, lines[1], " files:1 dirs:1 ")
|
||||
|
||||
require.Contains(t, lines[2], " 7 B ")
|
||||
require.Contains(t, lines[2], " files:2 dirs:1 ")
|
||||
|
||||
require.Contains(t, lines[3], " 8 B ")
|
||||
require.Contains(t, lines[3], " files:3 dirs:1 ")
|
||||
|
||||
// identical snapshot is not coalesced
|
||||
require.Contains(t, lines[4], " 8 B ")
|
||||
require.Contains(t, lines[4], " files:3 dirs:1 ")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user