analyze

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const EmptyDirSize int64 = 512

EmptyDirSize is the apparent size gdu assigns to a directory that has no counted children. It is a fixed sentinel (not the real filesystem block size) written by updateStats, SimpleDir.UpdateStats and the parallel top-dir analyzer, and recognised again on import. Keep every producer and consumer of this value referencing this constant so they can never drift apart.

Variables

This section is empty.

Functions

func CollectTopFiles

func CollectTopFiles(dir fs.Item, count int) fs.Files

Types

type BaseAnalyzer

type BaseAnalyzer struct {
	// contains filtered or unexported fields
}

BaseAnalyzer provides common logic for all analyzers

func (*BaseAnalyzer) Cancel added in v0.3.0

func (a *BaseAnalyzer) Cancel()

Cancel stops scheduling new scan work. In-flight filesystem operations are allowed to finish so the caller can safely use the partial directory tree.

func (*BaseAnalyzer) GetCurrentDir added in v0.3.0

func (a *BaseAnalyzer) GetCurrentDir() fs.Item

GetCurrentDir returns an independent snapshot of the directory tree built so far, or nil if no analysis has started yet. Callers may aggregate or navigate the snapshot without mutating the live scan state.

func (*BaseAnalyzer) GetDone

func (a *BaseAnalyzer) GetDone() common.SignalGroup

GetDone returns channel for checking when analysis is done

func (*BaseAnalyzer) GetProgress

func (a *BaseAnalyzer) GetProgress() common.CurrentProgress

func (*BaseAnalyzer) Init

func (a *BaseAnalyzer) Init()

Init initializes the BaseAnalyzer

func (*BaseAnalyzer) IsCancelled added in v0.3.0

func (a *BaseAnalyzer) IsCancelled() bool

IsCancelled reports whether the current scan has been cancelled.

func (*BaseAnalyzer) ResetProgress

func (a *BaseAnalyzer) ResetProgress()

ResetProgress prepares the analyzer for a new scan. Call it only after the previous scan has completed and before exposing the new scan to cancellation.

func (*BaseAnalyzer) SetArchiveBrowsing

func (a *BaseAnalyzer) SetArchiveBrowsing(v bool)

SetArchiveBrowsing sets whether browsing of zip/jar/tar archives is enabled

func (*BaseAnalyzer) SetFileTypeFilter

func (a *BaseAnalyzer) SetFileTypeFilter(filter common.ShouldFileBeIgnored)

SetFileTypeFilter sets the file type filter function

func (a *BaseAnalyzer) SetFollowSymlinks(v bool)

SetFollowSymlinks sets whether symlink to files should be followed

func (*BaseAnalyzer) SetShowAnnexedSize

func (a *BaseAnalyzer) SetShowAnnexedSize(v bool)

SetShowAnnexedSize sets whether to use annexed size of git-annex files

func (*BaseAnalyzer) SetTimeFilter

func (a *BaseAnalyzer) SetTimeFilter(matchesTimeFilterFn common.TimeFilter)

SetTimeFilter sets the time filter function for file inclusion

func (*BaseAnalyzer) UpdateProgress

func (a *BaseAnalyzer) UpdateProgress()

UpdateProgress updates progress

type Dir

type Dir struct {
	*File
	BasePath  string
	Files     fs.Files
	ItemCount int64
	// contains filtered or unexported fields
}

Dir struct

func (*Dir) AddFile

func (f *Dir) AddFile(item fs.Item)

AddFile add item to files

func (*Dir) EncodeJSON

func (f *Dir) EncodeJSON(writer io.Writer, topLevel bool, attributes fs.JSONAttributes) error

EncodeJSON writes JSON representation of dir

func (*Dir) GetFiles

func (f *Dir) GetFiles(sortBy fs.SortBy, order fs.SortOrder) iter.Seq[fs.Item]

GetFiles returns all files in directory as a sorted iterator

func (*Dir) GetFilesLocked

func (f *Dir) GetFilesLocked(sortBy fs.SortBy, order fs.SortOrder) iter.Seq[fs.Item]

GetFilesLocked returns all files in directory as a sorted iterator It is safe to call this function from multiple goroutines

func (*Dir) GetFlag added in v0.3.0

func (f *Dir) GetFlag() rune

GetFlag returns the current directory flag.

func (*Dir) GetItemCount

func (f *Dir) GetItemCount() int64

GetItemCount returns number of files in dir

func (*Dir) GetItemStats

func (f *Dir) GetItemStats(linkedItems fs.HardLinkedItems, filteringFiles bool) (itemCount, size, usage int64)

GetItemStats returns item count, apparent usage and real usage of this dir

func (*Dir) GetMtime added in v0.3.0

func (f *Dir) GetMtime() time.Time

GetMtime returns the current modification time.

func (*Dir) GetPath

func (f *Dir) GetPath() string

GetPath returns absolute path of the file

func (*Dir) GetSize added in v0.3.0

func (f *Dir) GetSize() int64

GetSize returns the current apparent size.

func (*Dir) GetType

func (f *Dir) GetType() string

GetType returns name type of item

func (*Dir) GetUsage added in v0.3.0

func (f *Dir) GetUsage() int64

GetUsage returns the current disk usage.

func (*Dir) HasEmptyDirPlaceholderStats added in v0.3.0

func (f *Dir) HasEmptyDirPlaceholderStats() bool

HasEmptyDirPlaceholderStats reports whether this directory's stats are indistinguishable from the placeholder updateStats produces for a directory with no counted children (see EmptyDirSize). Such stats carry no information worth pinning from an import: recomputation reproduces exactly the same values, so callers should let updateStats run rather than preserving them.

The items == 1 check is load-bearing: a depth-truncated directory that held real content always exports with ItemCount >= 2, so it can never be mistaken for a placeholder and its stats are always preserved.

func (*Dir) IsDir

func (f *Dir) IsDir() bool

IsDir returns true for dir

func (*Dir) RLock

func (f *Dir) RLock() func()

RLock read locks dir

func (*Dir) RemoveFile

func (f *Dir) RemoveFile(item fs.Item)

RemoveFile removes item from dir, updates size and item count

func (*Dir) RemoveFileByName

func (f *Dir) RemoveFileByName(name string)

RemoveFileByName removes item by name from dir

func (*Dir) SetFlag added in v0.3.0

func (f *Dir) SetFlag(flag rune)

SetFlag updates the directory flag while preserving snapshot consistency.

func (*Dir) SetStatsFromJSON added in v0.3.0

func (f *Dir) SetStatsFromJSON()

SetStatsFromJSON marks directory statistics decoded from an export as authoritative.

func (*Dir) UpdateStats

func (f *Dir) UpdateStats(linkedItems fs.HardLinkedItems)

func (*Dir) UpdateStatsWithFileFiltering added in v0.3.0

func (f *Dir) UpdateStatsWithFileFiltering(linkedItems fs.HardLinkedItems)

type File

type File struct {
	Mtime   time.Time
	Parent  fs.Item
	Name    string
	Symlink string
	Size    int64
	Usage   int64
	Mli     uint64
	Flag    rune
}

File struct

func CreateFileItem added in v0.3.0

func CreateFileItem(name string, info os.FileInfo) *File

CreateFileItem creates a File from an os.FileInfo with correct platform-specific attributes

func (*File) AddFile

func (f *File) AddFile(item fs.Item)

AddFile panics on file

func (*File) EncodeJSON

func (f *File) EncodeJSON(writer io.Writer, _ bool, attributes fs.JSONAttributes) error

EncodeJSON writes JSON representation of file

func (*File) GetFiles

func (f *File) GetFiles(sortBy fs.SortBy, order fs.SortOrder) iter.Seq[fs.Item]

GetFiles returns all files in directory

func (*File) GetFilesLocked

func (f *File) GetFilesLocked(sortBy fs.SortBy, order fs.SortOrder) iter.Seq[fs.Item]

GetFilesLocked returns all files in directory

func (*File) GetFlag

func (f *File) GetFlag() rune

GetFlag returns flag of the file

func (*File) GetItemCount

func (f *File) GetItemCount() int64

GetItemCount returns 1 for file

func (*File) GetItemStats

func (f *File) GetItemStats(linkedItems fs.HardLinkedItems, filteringFiles bool) (itemCount, size, usage int64)

GetItemStats returns 1 as count of items, apparent usage and real usage of this file

func (*File) GetMtime

func (f *File) GetMtime() time.Time

GetMtime returns mtime of the file

func (*File) GetMultiLinkedInode

func (f *File) GetMultiLinkedInode() uint64

GetMultiLinkedInode returns inode number of multilinked file

func (*File) GetName

func (f *File) GetName() string

GetName returns name of dir

func (*File) GetParent

func (f *File) GetParent() fs.Item

GetParent returns parent dir

func (*File) GetPath

func (f *File) GetPath() string

GetPath returns absolute Get of the file

func (*File) GetSize

func (f *File) GetSize() int64

GetSize returns size of the file

func (*File) GetSymlinkTarget added in v0.3.0

func (f *File) GetSymlinkTarget() string

GetSymlinkTarget returns the target of a symlink, or empty string

func (*File) GetType

func (f *File) GetType() string

GetType returns name type of item

func (*File) GetUsage

func (f *File) GetUsage() int64

GetUsage returns usage of the file

func (*File) IsDir

func (f *File) IsDir() bool

IsDir returns false for file

func (*File) RLock

func (f *File) RLock() func()

RLock panics on file

func (*File) RemoveFile

func (f *File) RemoveFile(item fs.Item)

RemoveFile panics on file

func (*File) RemoveFileByName

func (f *File) RemoveFileByName(name string)

RemoveFileByName panics on file

func (*File) SetParent

func (f *File) SetParent(parent fs.Item)

SetParent sets parent dir

func (*File) UpdateStats

func (f *File) UpdateStats(linkedItems fs.HardLinkedItems)

UpdateStats does nothing on file

func (*File) UpdateStatsWithFileFiltering added in v0.3.0

func (f *File) UpdateStatsWithFileFiltering(linkedItems fs.HardLinkedItems)

type ParallelAnalyzer

type ParallelAnalyzer struct {
	BaseAnalyzer
}

ParallelAnalyzer implements Analyzer

func CreateAnalyzer

func CreateAnalyzer() *ParallelAnalyzer

CreateAnalyzer returns Analyzer

func (*ParallelAnalyzer) AnalyzeDir

func (a *ParallelAnalyzer) AnalyzeDir(
	path string, ignore common.ShouldDirBeIgnored, fileTypeFilter common.ShouldFileBeIgnored,
) fs.Item

AnalyzeDir analyzes given path

type ParallelStableOrderAnalyzer

type ParallelStableOrderAnalyzer struct {
	BaseAnalyzer
}

ParallelStableOrderAnalyzer implements Analyzer

func CreateStableOrderAnalyzer

func CreateStableOrderAnalyzer() *ParallelStableOrderAnalyzer

CreateStableOrderAnalyzer returns parallel Analyzer which keeps stable order of files

func (*ParallelStableOrderAnalyzer) AnalyzeDir

func (a *ParallelStableOrderAnalyzer) AnalyzeDir(
	path string, ignore common.ShouldDirBeIgnored, fileTypeFilter common.ShouldFileBeIgnored,
) fs.Item

AnalyzeDir analyzes given path

type ParentDir

type ParentDir struct {
	Path string
}

ParentDir represents parent directory of single file It is used to get path to parent directory of a file

func (*ParentDir) AddFile

func (p *ParentDir) AddFile(fs.Item)

func (*ParentDir) EncodeJSON

func (p *ParentDir) EncodeJSON(io.Writer, bool, fs.JSONAttributes) error

func (*ParentDir) GetFiles

func (p *ParentDir) GetFiles(fs.SortBy, fs.SortOrder) iter.Seq[fs.Item]

func (*ParentDir) GetFilesLocked

func (p *ParentDir) GetFilesLocked(fs.SortBy, fs.SortOrder) iter.Seq[fs.Item]

func (*ParentDir) GetFlag

func (p *ParentDir) GetFlag() rune

func (*ParentDir) GetItemCount

func (p *ParentDir) GetItemCount() int64

func (*ParentDir) GetItemStats

func (p *ParentDir) GetItemStats(
	linkedItems fs.HardLinkedItems, filteringFiles bool,
) (itemCount, size, usage int64)

func (*ParentDir) GetMtime

func (p *ParentDir) GetMtime() time.Time

func (*ParentDir) GetMultiLinkedInode

func (p *ParentDir) GetMultiLinkedInode() uint64

func (*ParentDir) GetName

func (p *ParentDir) GetName() string

func (*ParentDir) GetParent

func (p *ParentDir) GetParent() fs.Item

func (*ParentDir) GetPath

func (p *ParentDir) GetPath() string

func (*ParentDir) GetSize

func (p *ParentDir) GetSize() int64

func (*ParentDir) GetType

func (p *ParentDir) GetType() string

func (*ParentDir) GetUsage

func (p *ParentDir) GetUsage() int64

func (*ParentDir) IsDir

func (p *ParentDir) IsDir() bool

func (*ParentDir) RLock

func (p *ParentDir) RLock() func()

func (*ParentDir) RemoveFile

func (p *ParentDir) RemoveFile(item fs.Item)

func (*ParentDir) RemoveFileByName

func (p *ParentDir) RemoveFileByName(name string)

func (*ParentDir) SetParent

func (p *ParentDir) SetParent(fs.Item)

func (*ParentDir) UpdateStats

func (p *ParentDir) UpdateStats(linkedItems fs.HardLinkedItems)

func (*ParentDir) UpdateStatsWithFileFiltering added in v0.3.0

func (p *ParentDir) UpdateStatsWithFileFiltering(linkedItems fs.HardLinkedItems)

type SequentialAnalyzer

type SequentialAnalyzer struct {
	BaseAnalyzer
}

SequentialAnalyzer implements Analyzer

func CreateSeqAnalyzer

func CreateSeqAnalyzer() *SequentialAnalyzer

CreateSeqAnalyzer returns Analyzer

func (*SequentialAnalyzer) AnalyzeDir

func (a *SequentialAnalyzer) AnalyzeDir(
	path string, ignore common.ShouldDirBeIgnored, fileTypeFilter common.ShouldFileBeIgnored,
) fs.Item

AnalyzeDir analyzes given path

type SimpleDir

type SimpleDir struct {
	SimpleFile
	Files    []SimpleFile
	BasePath string
}

func (*SimpleDir) AddFile

func (d *SimpleDir) AddFile(fs.Item)

func (*SimpleDir) EncodeJSON

func (d *SimpleDir) EncodeJSON(io.Writer, bool, fs.JSONAttributes) error

func (*SimpleDir) GetFiles

func (d *SimpleDir) GetFiles(sortBy fs.SortBy, order fs.SortOrder) iter.Seq[fs.Item]

func (*SimpleDir) GetFilesLocked

func (d *SimpleDir) GetFilesLocked(fs.SortBy, fs.SortOrder) iter.Seq[fs.Item]

func (*SimpleDir) GetFlag

func (d *SimpleDir) GetFlag() rune

func (*SimpleDir) GetItemCount

func (d *SimpleDir) GetItemCount() int64

func (*SimpleDir) GetItemStats

func (d *SimpleDir) GetItemStats(linkedItems fs.HardLinkedItems, filteringFiles bool) (itemCount, size, usage int64)

func (*SimpleDir) GetMtime

func (d *SimpleDir) GetMtime() time.Time

func (*SimpleDir) GetMultiLinkedInode

func (d *SimpleDir) GetMultiLinkedInode() uint64

func (*SimpleDir) GetName

func (d *SimpleDir) GetName() string

func (*SimpleDir) GetParent

func (d *SimpleDir) GetParent() fs.Item

func (*SimpleDir) GetPath

func (d *SimpleDir) GetPath() string

func (*SimpleDir) GetSize

func (d *SimpleDir) GetSize() int64

func (*SimpleDir) GetType

func (d *SimpleDir) GetType() string

func (*SimpleDir) GetUsage

func (d *SimpleDir) GetUsage() int64

func (*SimpleDir) IsDir

func (d *SimpleDir) IsDir() bool

func (*SimpleDir) RLock

func (d *SimpleDir) RLock() func()

func (*SimpleDir) RemoveFile

func (d *SimpleDir) RemoveFile(fs.Item)

func (*SimpleDir) RemoveFileByName

func (d *SimpleDir) RemoveFileByName(name string)

func (*SimpleDir) SetParent

func (d *SimpleDir) SetParent(parent fs.Item)

func (*SimpleDir) UpdateStats

func (d *SimpleDir) UpdateStats(linkedItems fs.HardLinkedItems)

func (*SimpleDir) UpdateStatsWithFileFiltering added in v0.3.0

func (d *SimpleDir) UpdateStatsWithFileFiltering(linkedItems fs.HardLinkedItems)

type SimpleFile

type SimpleFile struct {
	Name      string
	Symlink   string
	Flag      rune
	Size      int64
	Usage     int64
	ItemCount int64
	IsDir     bool
}

type SqliteAnalyzer

type SqliteAnalyzer struct {
	BaseAnalyzer
	// contains filtered or unexported fields
}

SqliteAnalyzer implements Analyzer using SQLite storage

func CreateSqliteAnalyzer

func CreateSqliteAnalyzer(dbPath string) (*SqliteAnalyzer, error)

CreateSqliteAnalyzer creates a new SQLite analyzer

func (*SqliteAnalyzer) AnalyzeDir

func (a *SqliteAnalyzer) AnalyzeDir(
	path string, ignore common.ShouldDirBeIgnored, fileTypeFilter common.ShouldFileBeIgnored,
) fs.Item

AnalyzeDir analyzes the given path and stores results in SQLite. If the database already contains data, it loads from the database instead of re-scanning.

type SqliteItem

type SqliteItem struct {
	// contains filtered or unexported fields
}

SqliteItem represents a file or directory stored in SQLite

func (*SqliteItem) AddFile

func (i *SqliteItem) AddFile(item fs.Item)

AddFile adds a child file (no-op for SQLite items - children are in DB)

func (*SqliteItem) EncodeJSON

func (i *SqliteItem) EncodeJSON(writer io.Writer, topLevel bool, attributes fs.JSONAttributes) error

EncodeJSON encodes the item to JSON

func (*SqliteItem) GetFiles

func (i *SqliteItem) GetFiles(sortBy fs.SortBy, order fs.SortOrder) iter.Seq[fs.Item]

GetFiles returns children as a sorted iterator

func (*SqliteItem) GetFilesLocked

func (i *SqliteItem) GetFilesLocked(sortBy fs.SortBy, order fs.SortOrder) iter.Seq[fs.Item]

GetFilesLocked returns children with locking

func (*SqliteItem) GetFlag

func (i *SqliteItem) GetFlag() rune

GetFlag returns the flag of the item

func (*SqliteItem) GetItemCount

func (i *SqliteItem) GetItemCount() int64

GetItemCount returns the item count

func (*SqliteItem) GetItemStats

func (i *SqliteItem) GetItemStats(linkedItems fs.HardLinkedItems, filteringFiles bool) (itemCount, size, usage int64)

GetItemStats returns item statistics - hard links already handled during scan

func (*SqliteItem) GetMtime

func (i *SqliteItem) GetMtime() time.Time

GetMtime returns the modification time

func (*SqliteItem) GetMultiLinkedInode

func (i *SqliteItem) GetMultiLinkedInode() uint64

GetMultiLinkedInode returns the multi-linked inode number

func (*SqliteItem) GetName

func (i *SqliteItem) GetName() string

GetName returns the name of the item

func (*SqliteItem) GetParent

func (i *SqliteItem) GetParent() fs.Item

GetParent returns the parent item

func (*SqliteItem) GetParentLocked

func (i *SqliteItem) GetParentLocked() *SqliteItem

GetParentLocked returns the in-memory parent without hitting the database. Used inside RemoveFile where storage.m is already write-locked.

func (*SqliteItem) GetPath

func (i *SqliteItem) GetPath() string

GetPath returns the full path of the item

func (*SqliteItem) GetSize

func (i *SqliteItem) GetSize() int64

GetSize returns the apparent size

func (*SqliteItem) GetType

func (i *SqliteItem) GetType() string

GetType returns the type of the item

func (*SqliteItem) GetUsage

func (i *SqliteItem) GetUsage() int64

GetUsage returns the disk usage

func (*SqliteItem) IsDir

func (i *SqliteItem) IsDir() bool

IsDir returns true if the item is a directory

func (*SqliteItem) RLock

func (i *SqliteItem) RLock() func()

RLock returns a no-op unlock function

func (*SqliteItem) RemoveFile

func (i *SqliteItem) RemoveFile(item fs.Item)

RemoveFile removes a child file, updating both in-memory stats and the database in one pass.

func (*SqliteItem) RemoveFileByName

func (i *SqliteItem) RemoveFileByName(name string)

RemoveFileByName removes a child by name

func (*SqliteItem) SetParent

func (i *SqliteItem) SetParent(parent fs.Item)

SetParent sets the parent item

func (*SqliteItem) UpdateStats

func (i *SqliteItem) UpdateStats(linkedItems fs.HardLinkedItems)

UpdateStats is a no-op for SqliteItem - hard links are handled during scan

func (*SqliteItem) UpdateStatsWithFileFiltering added in v0.3.0

func (i *SqliteItem) UpdateStatsWithFileFiltering(linkedItems fs.HardLinkedItems)

type SqliteStorage

type SqliteStorage struct {
	// contains filtered or unexported fields
}

SqliteStorage represents SQLite database storage

func NewSqliteStorage

func NewSqliteStorage(dbPath string) (*SqliteStorage, error)

NewSqliteStorage creates a new SQLite storage and initializes the schema

func (*SqliteStorage) BeginBulkInsert

func (s *SqliteStorage) BeginBulkInsert() error

BeginBulkInsert starts a transaction and prepares statements for bulk insertion

func (*SqliteStorage) ClearItems

func (s *SqliteStorage) ClearItems() error

ClearItems removes all items from the database

func (*SqliteStorage) Close

func (s *SqliteStorage) Close() error

Close closes the database connection

func (*SqliteStorage) EndBulkInsert

func (s *SqliteStorage) EndBulkInsert() error

EndBulkInsert commits the transaction and closes prepared statements

func (*SqliteStorage) GetChildByName

func (s *SqliteStorage) GetChildByName(parentID int64, name string) (*SqliteItem, error)

GetChildByName returns a child item by its name and parent ID

func (*SqliteStorage) GetChildren

func (s *SqliteStorage) GetChildren(parentID int64) ([]*SqliteItem, error)

GetChildren returns all children of a given parent ID

func (*SqliteStorage) GetItemByID

func (s *SqliteStorage) GetItemByID(id int64) (*SqliteItem, error)

GetItemByID returns an item by its ID

func (*SqliteStorage) GetMetadata

func (s *SqliteStorage) GetMetadata(key string) (string, error)

GetMetadata retrieves a metadata value by key

func (*SqliteStorage) GetRootItem

func (s *SqliteStorage) GetRootItem() (*SqliteItem, error)

GetRootItem returns the root item (item with no parent)

func (*SqliteStorage) HasData

func (s *SqliteStorage) HasData() bool

HasData returns true if the database contains analysis data

func (*SqliteStorage) HasInode

func (s *SqliteStorage) HasInode(mli uint64) bool

HasInode returns true if a file with the given inode already exists in the database

func (*SqliteStorage) InsertItem

func (s *SqliteStorage) InsertItem(
	parentID *int64, name string, isDir bool, size, usage int64, mtime time.Time, itemCount int64, mli uint64, flag rune,
) (int64, error)

InsertItem inserts a file/directory item into the database

func (*SqliteStorage) RemoveItemAndUpdateStats

func (s *SqliteStorage) RemoveItemAndUpdateStats(id, size, usage, itemCount int64) error

RemoveItemAndUpdateStats removes an item and updates all its ancestors' stats in the database

func (*SqliteStorage) SetMetadata

func (s *SqliteStorage) SetMetadata(key, value string) error

SetMetadata stores a metadata key-value pair

func (*SqliteStorage) UpdateItem

func (s *SqliteStorage) UpdateItem(id, size, usage, itemCount int64, flag rune) error

UpdateItem updates an existing item's stats

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

Storage represents a badger storage

var DefaultStorage *Storage

DefaultStorage is a default instance of badger storage

func NewStorage

func NewStorage(storagePath, topDir string) *Storage

NewStorage returns new instance of badger storage

func (*Storage) GetDirForPath

func (s *Storage) GetDirForPath(path string) (item fs.Item, err error)

GetDirForPath returns Dir for given path

func (*Storage) GetTopDir

func (s *Storage) GetTopDir() string

GetTopDir returns top directory

func (*Storage) IsOpen

func (s *Storage) IsOpen() bool

IsOpen returns true if badger DB is open

func (*Storage) LoadDir

func (s *Storage) LoadDir(dir fs.Item) error

LoadDir saves item info into badger DB

func (*Storage) Open

func (s *Storage) Open() func()

Open opens badger DB

func (*Storage) StoreDir

func (s *Storage) StoreDir(dir fs.Item) error

StoreDir saves item info into badger DB

type StoredAnalyzer

type StoredAnalyzer struct {
	BaseAnalyzer
	// contains filtered or unexported fields
}

StoredAnalyzer implements Analyzer

func CreateStoredAnalyzer

func CreateStoredAnalyzer(storagePath string) *StoredAnalyzer

CreateStoredAnalyzer returns Analyzer

func (*StoredAnalyzer) AnalyzeDir

func (a *StoredAnalyzer) AnalyzeDir(
	path string, ignore common.ShouldDirBeIgnored, fileTypeFilter common.ShouldFileBeIgnored,
) fs.Item

AnalyzeDir analyzes given path

type StoredDir

type StoredDir struct {
	*Dir
	// contains filtered or unexported fields
}

StoredDir implements Dir item stored on disk

func (*StoredDir) GetFiles

func (f *StoredDir) GetFiles(sortBy fs.SortBy, order fs.SortOrder) iter.Seq[fs.Item]

GetFiles returns files in directory as a sorted iterator If files are already cached, use them Otherwise load them from storage

func (*StoredDir) GetItemStats

func (f *StoredDir) GetItemStats(linkedItems fs.HardLinkedItems, filteringFiles bool) (itemCount, size, usage int64)

GetItemStats returns item count, apparent usage and real usage of this dir

func (*StoredDir) GetParent

func (f *StoredDir) GetParent() fs.Item

GetParent returns parent dir

func (*StoredDir) RemoveFile

func (f *StoredDir) RemoveFile(item fs.Item)

RemoveFile removes file from stored directory It also updates size and item count of parent directories

func (*StoredDir) RemoveFileByName

func (f *StoredDir) RemoveFileByName(name string)

RemoveFileByName removes file by name from stored directory

func (*StoredDir) UpdateStats

func (f *StoredDir) UpdateStats(linkedItems fs.HardLinkedItems)

UpdateStats recursively updates size and item count

func (*StoredDir) UpdateStatsWithFileFiltering added in v0.3.0

func (f *StoredDir) UpdateStatsWithFileFiltering(linkedItems fs.HardLinkedItems)

type TarDir

type TarDir struct {
	*Dir
	// contains filtered or unexported fields
}

TarDir represents a directory structure inside a tar archive

func (*TarDir) EncodeJSON

func (td *TarDir) EncodeJSON(writer io.Writer, topLevel bool, attributes fs.JSONAttributes) error

EncodeJSON encodes tar directory to JSON

func (*TarDir) GetPath

func (td *TarDir) GetPath() string

GetPath returns the virtual path for tar directory

func (*TarDir) GetType

func (td *TarDir) GetType() string

GetType returns type of tar directory

func (*TarDir) IsDir

func (td *TarDir) IsDir() bool

IsDir returns true for TarDir

type TarFile

type TarFile struct {
	*File
	// contains filtered or unexported fields
}

TarFile represents a file inside a tar archive

func (*TarFile) EncodeJSON

func (tf *TarFile) EncodeJSON(writer io.Writer, topLevel bool, attributes fs.JSONAttributes) error

EncodeJSON encodes tar file to JSON

func (*TarFile) GetPath

func (tf *TarFile) GetPath() string

GetPath returns the virtual path for tar file

func (*TarFile) GetType

func (tf *TarFile) GetType() string

GetType returns type of tar file

type TopDir

type TopDir struct {
	Name      string
	Size      atomic.Int64
	Usage     atomic.Int64
	ItemCount atomic.Int64
	Flag      rune
	// contains filtered or unexported fields
}

func (*TopDir) AddUsage

func (d *TopDir) AddUsage(size, usage, itemCount int64)

func (*TopDir) GetUsage

func (d *TopDir) GetUsage() (size, usage, itemCount int64)

func (*TopDir) SetFlag

func (d *TopDir) SetFlag(flag rune)

type TopDirAnalyzer

type TopDirAnalyzer struct {
	BaseAnalyzer
	// contains filtered or unexported fields
}

TopDirAnalyzer implements Analyzer It doesn't return the full directory structure, only the top level directory, thus is suitable only for non-interactive mode. It tries to use only stack for storing state and results.

func CreateTopDirAnalyzer

func CreateTopDirAnalyzer() *TopDirAnalyzer

CreateTopDirAnalyzer returns Analyzer

func (*TopDirAnalyzer) AnalyzeDir

func (a *TopDirAnalyzer) AnalyzeDir(
	path string, ignore common.ShouldDirBeIgnored, fileTypeFilter common.ShouldFileBeIgnored,
) fs.Item

AnalyzeDir analyzes given path

type TopList

type TopList struct {
	Items   fs.Files
	Count   int
	MinSize int64
}

TopList is a list of top largest files

func NewTopList

func NewTopList(count int) *TopList

NewTopList creates new TopList

func (*TopList) Add

func (tl *TopList) Add(file fs.Item)

Add adds file to the list

type WaitGroup

type WaitGroup struct {
	// contains filtered or unexported fields
}

A WaitGroup waits for a collection of goroutines to finish. In contrast to sync.WaitGroup Add method can be called from a goroutine.

func (*WaitGroup) Add

func (s *WaitGroup) Add(value int)

Add increments value

func (*WaitGroup) Done

func (s *WaitGroup) Done()

Done decrements the value by one, if value is 0, lock is released

func (*WaitGroup) Init

func (s *WaitGroup) Init() *WaitGroup

Init prepares the WaitGroup for usage, locks

func (*WaitGroup) Wait

func (s *WaitGroup) Wait()

Wait blocks until value is 0

type ZipDir

type ZipDir struct {
	*Dir
	// contains filtered or unexported fields
}

ZipDir represents a directory structure inside a zip file

func (*ZipDir) EncodeJSON

func (zd *ZipDir) EncodeJSON(writer io.Writer, topLevel bool, attributes fs.JSONAttributes) error

EncodeJSON encodes zip directory to JSON

func (*ZipDir) GetPath

func (zd *ZipDir) GetPath() string

GetPath returns the virtual path for zip directory

func (*ZipDir) GetType

func (zd *ZipDir) GetType() string

GetType returns type of zip directory

func (*ZipDir) IsDir

func (zd *ZipDir) IsDir() bool

IsDir returns true for ZipDir

type ZipFile

type ZipFile struct {
	*File
	// contains filtered or unexported fields
}

ZipFile represents a file inside a zip archive

func (*ZipFile) EncodeJSON

func (zf *ZipFile) EncodeJSON(writer io.Writer, topLevel bool, attributes fs.JSONAttributes) error

EncodeJSON encodes zip file to JSON

func (*ZipFile) GetPath

func (zf *ZipFile) GetPath() string

GetPath returns the virtual path for zip file

func (*ZipFile) GetType

func (zf *ZipFile) GetType() string

GetType returns type of zip file

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL