db

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DuplicateInfo

type DuplicateInfo struct {
	Path     string
	FullHash []byte
	Count    int64
}

type DuplicateSet

type DuplicateSet []FileInfo

type FileInfo

type FileInfo struct {
	Path      string
	Size      int64
	ShortHash []byte
	FullHash  []byte
}

type InfoSummary

type InfoSummary struct {
	Files     int64
	Unique    int64
	Duplicate int64
	Overhead  int64
}

type Session

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

A database session, or a transaction.

This is a sort of weird implementation, but it makes the interface/implementation convenient. The same type exposes a bunch of methods that operate on the database, and the object and methods are the same regardless of whether the operations are done within a transaction.

Calling Begin() returns a Session that is a transaction, and calling Commit() on the resultant session (transaction) commits the transaction.

The db field is non-nil for a new session. For an open transaction, db is nil and tx is non-nil. Once Commit() is called on the transaction, both the db and tx are nil (and any method calls on this object will fail).

func New

func New(dataSourceName string, debug bool) (*Session, herror.Interface)

func NewInMemory added in v0.3.2

func NewInMemory() (*Session, herror.Interface)

func (*Session) Add

func (s *Session) Add(info FileInfo) herror.Interface

func (*Session) AllDuplicates

func (s *Session) AllDuplicates(path string) ([]DuplicateSet, herror.Interface)

func (*Session) AllDuplicatesC

func (s *Session) AllDuplicatesC(path string) (<-chan DuplicateSet, herror.Interface)

Returns all known duplicates in the database.

These are necessarily FileInfos with the FullHash field filled out. Each DuplicateSet that is returned always has > 1 element (i.e. it only includes duplicates, not infos where we happen to know the full hash).

path is optional; if "", then all duplicates are returned, otherwise only ones with the given directory prefix

func (*Session) AllInfos

func (s *Session) AllInfos() ([]FileInfo, herror.Interface)

func (*Session) AllInfosC

func (s *Session) AllInfosC() (<-chan FileInfo, herror.Interface)

Returns all infos in the database (regardless of whether they have duplicates).

func (*Session) Begin

func (s *Session) Begin() (*Session, herror.Interface)

func (*Session) Commit

func (s *Session) Commit() herror.Interface

func (*Session) CreateIndexes

func (s *Session) CreateIndexes() herror.Interface

func (*Session) InfosBySize

func (s *Session) InfosBySize(size int64) ([]FileInfo, herror.Interface)

Returns all the infos with the given size.

This includes all infos, even ones where the short hash or full hash is not known.

func (*Session) Lookup

func (s *Session) Lookup(path string) (DuplicateSet, herror.Interface)

Returns info for everything matching the given file.

Returns [] if there isn't a matching file in the database. If the file exists in the database, that file is returned first.

func (*Session) LookupAll

func (s *Session) LookupAll(path string, includeHidden bool) ([]DuplicateInfo, herror.Interface)

func (*Session) LookupAllC

func (s *Session) LookupAllC(path string, includeHidden bool) (<-chan DuplicateInfo, herror.Interface)

Returns all duplicate sets (size > 1) where at least one file is contained under the given path.

func (*Session) Remove

func (s *Session) Remove(path string) herror.Interface

Deletes a file with the given path from the database.

func (*Session) RemoveDir

func (s *Session) RemoveDir(dir string, min, max int64) herror.Interface

Deletes all files matching the given directory prefix from the database, with sizes in the specified range.

A max size of 0 is interpreted as infinity. This does not just match based on prefix, it interprets the prefix as a directory, and only deletes files under the given directory. This means that it won't accidentally match file names (or other directory names) where the prefix is common, e.g. deleting "/a" won't delete file "/aa" or contents under a directory "/aa".

func (*Session) Summary

func (s *Session) Summary() (InfoSummary, herror.Interface)

Jump to

Keyboard shortcuts

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