summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Milde <daniel@milde.cz>2024-02-10 10:07:24 +0100
committerDaniel Milde <daniel@milde.cz>2024-02-12 01:15:29 +0100
commit82f110dbf8d6d6a2e22ade97c631a6adc11b2b88 (patch)
treec0776587df8ccfacb5ad33f311b5207e46285447
parent728500fdd23975e7d43de40ab44f14659262f60a (diff)
docs: comments for public methods
-rw-r--r--internal/common/ui.go1
-rw-r--r--pkg/analyze/storage.go5
-rw-r--r--pkg/analyze/stored.go45
-rw-r--r--report/export.go1
-rw-r--r--stdout/stdout.go1
-rw-r--r--tui/actions.go1
6 files changed, 35 insertions, 19 deletions
diff --git a/internal/common/ui.go b/internal/common/ui.go
index c3987c2..2caefd3 100644
--- a/internal/common/ui.go
+++ b/internal/common/ui.go
@@ -19,6 +19,7 @@ type UI struct {
ConstGC bool
}
+// SetAnalyzer sets analyzer instance
func (ui *UI) SetAnalyzer(a Analyzer) {
ui.Analyzer = a
}
diff --git a/pkg/analyze/storage.go b/pkg/analyze/storage.go
index e0f61ad..49b4634 100644
--- a/pkg/analyze/storage.go
+++ b/pkg/analyze/storage.go
@@ -17,14 +17,17 @@ func init() {
gob.RegisterName("analyze.ParentDir", &ParentDir{})
}
+// DefaultStorage is a default instance of badger storage
var DefaultStorage *Storage
+// Storage represents a badger storage
type Storage struct {
db *badger.DB
storagePath string
topDir string
}
+// NewStorage returns new instance of badger storage
func NewStorage(storagePath, topDir string) *Storage {
st := &Storage{
storagePath: storagePath,
@@ -39,10 +42,12 @@ func (s *Storage) GetTopDir() string {
return s.topDir
}
+// IsOpen returns true if badger DB is open
func (s *Storage) IsOpen() bool {
return s.db != nil
}
+// Open opens badger DB
func (s *Storage) Open() func() {
options := badger.DefaultOptions(s.storagePath)
options.Logger = nil
diff --git a/pkg/analyze/stored.go b/pkg/analyze/stored.go
index ab1c57a..d1a403a 100644
--- a/pkg/analyze/stored.go
+++ b/pkg/analyze/stored.go
@@ -225,6 +225,9 @@ func (f *StoredDir) GetParent() fs.Item {
return dir
}
+// GetFiles returns files in directory
+// If files are already cached, return them
+// Otherwise load them from storage
func (f *StoredDir) GetFiles() fs.Files {
if f.cachedFiles != nil {
return f.cachedFiles
@@ -340,6 +343,8 @@ func (f *StoredDir) UpdateStats(linkedItems fs.HardLinkedItems) {
}
}
+// ParentDir represents parent directory of single file
+// It is used to get path to parent directory of a file
type ParentDir struct {
Path string
}
@@ -347,23 +352,25 @@ type ParentDir struct {
func (p *ParentDir) GetPath() string {
return p.Path
}
-func (p *ParentDir) GetName() string { panic("not implemented") }
-func (p *ParentDir) GetFlag() rune { panic("not implemented") }
-func (p *ParentDir) IsDir() bool { panic("not implemented") }
-func (p *ParentDir) GetSize() int64 { panic("not implemented") }
-func (p *ParentDir) GetType() string { panic("not implemented") }
-func (p *ParentDir) GetUsage() int64 { panic("not implemented") }
-func (p *ParentDir) GetMtime() time.Time { panic("not implemented") }
-func (p *ParentDir) GetItemCount() int { panic("not implemented") }
-func (p *ParentDir) GetParent() fs.Item { panic("not implemented") }
-func (p *ParentDir) SetParent(fs.Item) { panic("not implemented") }
-func (p *ParentDir) GetMultiLinkedInode() uint64 { panic("not implemented") }
-func (p *ParentDir) EncodeJSON(writer io.Writer, topLevel bool) error { panic("not implemented") }
-func (p *ParentDir) GetItemStats(linkedItems fs.HardLinkedItems) (int, int64, int64) {
- panic("not implemented")
+func (p *ParentDir) GetName() string { panic("must not be called") }
+func (p *ParentDir) GetFlag() rune { panic("must not be called") }
+func (p *ParentDir) IsDir() bool { panic("must not be called") }
+func (p *ParentDir) GetSize() int64 { panic("must not be called") }
+func (p *ParentDir) GetType() string { panic("must not be called") }
+func (p *ParentDir) GetUsage() int64 { panic("must not be called") }
+func (p *ParentDir) GetMtime() time.Time { panic("must not be called") }
+func (p *ParentDir) GetItemCount() int { panic("must not be called") }
+func (p *ParentDir) GetParent() fs.Item { panic("must not be called") }
+func (p *ParentDir) SetParent(fs.Item) { panic("must not be called") }
+func (p *ParentDir) GetMultiLinkedInode() uint64 { panic("must not be called") }
+func (p *ParentDir) EncodeJSON(writer io.Writer, topLevel bool) error { panic("must not be called") }
+func (p *ParentDir) UpdateStats(linkedItems fs.HardLinkedItems) { panic("must not be called") }
+func (p *ParentDir) AddFile(fs.Item) { panic("must not be called") }
+func (p *ParentDir) GetFiles() fs.Files { panic("must not be called") }
+func (p *ParentDir) SetFiles(fs.Files) { panic("must not be called") }
+func (f *ParentDir) RemoveFile(item fs.Item) { panic("must not be called") }
+func (p *ParentDir) GetItemStats(
+ linkedItems fs.HardLinkedItems,
+) (int, int64, int64) {
+ panic("must not be called")
}
-func (p *ParentDir) UpdateStats(linkedItems fs.HardLinkedItems) { panic("not implemented") }
-func (p *ParentDir) AddFile(fs.Item) { panic("not implemented") }
-func (p *ParentDir) GetFiles() fs.Files { panic("not implemented") }
-func (p *ParentDir) SetFiles(fs.Files) { panic("not implemented") }
-func (f *ParentDir) RemoveFile(item fs.Item) { panic("not implemented") }
diff --git a/report/export.go b/report/export.go
index 31fcacc..e011933 100644
--- a/report/export.go
+++ b/report/export.go
@@ -75,6 +75,7 @@ func (ui *UI) ReadAnalysis(input io.Reader) error {
return errors.New("Reading analysis is not possible while exporting")
}
+// ReadFromStorage reads analysis data from persistent key-value storage
func (ui *UI) ReadFromStorage(storagePath, path string) error {
storage := analyze.NewStorage(storagePath, path)
closeFn := storage.Open()
diff --git a/stdout/stdout.go b/stdout/stdout.go
index 0a197bc..9697d0e 100644
--- a/stdout/stdout.go
+++ b/stdout/stdout.go
@@ -164,6 +164,7 @@ func (ui *UI) AnalyzePath(path string, _ fs.Item) error {
return nil
}
+// ReadFromStorage reads analysis data from persistent key-value storage
func (ui *UI) ReadFromStorage(storagePath, path string) error {
storage := analyze.NewStorage(storagePath, path)
closeFn := storage.Open()
diff --git a/tui/actions.go b/tui/actions.go
index e911b60..a05e71e 100644
--- a/tui/actions.go
+++ b/tui/actions.go
@@ -136,6 +136,7 @@ func (ui *UI) ReadAnalysis(input io.Reader) error {
return nil
}
+// ReadFromStorage reads analysis data from persistent key-value storage
func (ui *UI) ReadFromStorage(storagePath, path string) error {
storage := analyze.NewStorage(storagePath, path)
closeFn := storage.Open()