Skip to content

Commit

Permalink
Merge pull request #47 from markusressel/feature/snapshot-refer
Browse files Browse the repository at this point in the history
add "Refer" column to snapshot browser
  • Loading branch information
markusressel authored Nov 3, 2024
2 parents 1c17cc8 + 19733a0 commit 9f0fe25
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/ui/snapshot_browser/snapshot_browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ var (
Title: "Used",
Alignment: tview.AlignCenter,
}
columnRefer = &table.Column{
Id: 4,
Title: "Refer",
Alignment: tview.AlignCenter,
}
tableColumns = []*table.Column{
columnName, columnDate, columnDiff, columnUsed,
columnName, columnDate, columnDiff, columnUsed, columnRefer,
}
)

Expand Down Expand Up @@ -117,6 +122,8 @@ func (snapshotBrowser *SnapshotBrowserComponent) createLayout() *tview.Pages {
}
} else if column == columnUsed {
cellText = humanize.IBytes(entry.Snapshot.GetUsed())
} else if column == columnRefer {
cellText = humanize.IBytes(entry.Snapshot.GetReferenced())
}
cell := tview.NewTableCell(cellText).
SetTextColor(cellColor).SetAlign(cellAlign)
Expand All @@ -139,6 +146,8 @@ func (snapshotBrowser *SnapshotBrowserComponent) createLayout() *tview.Pages {
result = int(b.DiffState - a.DiffState)
} else if columnToSortBy == columnUsed {
result = int(b.Snapshot.GetUsed() - a.Snapshot.GetUsed())
} else if columnToSortBy == columnRefer {
result = int(b.Snapshot.GetReferenced() - a.Snapshot.GetReferenced())
}
if inverted {
result *= -1
Expand Down
9 changes: 9 additions & 0 deletions internal/zfs/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@ func (s *Snapshot) GetUsed() uint64 {
return used
}

func (s *Snapshot) GetReferenced() uint64 {
referenced, err := strconv.ParseUint(s.internalSnapshot.Properties[golibzfs.DatasetPropReferenced].Value, 10, 64)
if err != nil {
logging.Error("Could not parse referenced property: %s", err.Error())
return 0
}
return referenced
}

func syncFileProperties(dstPath string, stat os.FileInfo) error {
err := os.Chmod(dstPath, stat.Mode())
if err != nil {
Expand Down

0 comments on commit 9f0fe25

Please sign in to comment.