fhd

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

README

fhd

The fhd “File History Data” package is for use by the GUI FileHistory application and the command line fh tool. It provides the underlying functionality that these tools use.

Data Structures

The fhd library keeps all the data in a single file with the .fhd extension. This data is in the form of a key–value store with some values nested key–values in their own right.

The config bucket's format value is the .fhd file format number. And the config bucket's ignore value is a bucket whose keys are filenames or globs to be ignored and whose values are empty.

The states bucket holds the current state. The LastSid is the most recent SID the corresponding file was saved into. The FileKind is B (binary), I (image), or T (text): useful for clients to see if they can offer diffs.

License

Apache-2.0


Documentation

Index

Constants

View Source
const (
	InvalidSID = 0
)

Variables

View Source
var (
	//go:embed Version.dat
	Version string
)

Functions

This section is empty.

Types

type Fhd

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

func New

func New(filename string) (*Fhd, error)

New opens (and creates if necessary) the given .fhd file ready for use.

func (*Fhd) Close

func (me *Fhd) Close() error

Close closes the underlying database.

func (*Fhd) Compact

func (me *Fhd) Compact() error

Compact eliminates wasted space in the .fhd file.

func (*Fhd) Delete

func (me *Fhd) Delete(sid SID, filename string) error

Delete deletes the given file for the given save. If this is the only occurrence of the file, adds the filename to the ignored list.

func (*Fhd) Dump

func (me *Fhd) Dump() error

func (*Fhd) DumpTo

func (me *Fhd) DumpTo(writer io.Writer) error

DumpTo writes data from the underlying database to the writer purely for debugging and testing.

func (*Fhd) Extract

func (me *Fhd) Extract(filename string, writer io.Writer) error

Writes the content of the given filename from the most recently saved change to the given writer.

func (*Fhd) ExtractFile

func (me *Fhd) ExtractFile(filename string) (string, error)

Writes the content of the given filename from the most recently saved change to a new filename, filename#SID.ext, and returns the new filename.

func (*Fhd) ExtractFileForSid

func (me *Fhd) ExtractFileForSid(sid SID, filename string) (string, error)

Writes the content of the given filename from the specified Save (identified by its SID) to new filename, filename#SID.ext, and returns the new filename.

func (*Fhd) ExtractForSid

func (me *Fhd) ExtractForSid(sid SID, filename string,
	writer io.Writer) error

Writes the content of the given filename from the specified Save (identified by its SID) to the given writer.

func (*Fhd) FileFormat

func (me *Fhd) FileFormat() (int, error)

Format returns the underlying database's file format number.

func (*Fhd) Filename

func (me *Fhd) Filename() string

Filename returns the underlying database's filename.

func (*Fhd) Ignore

func (me *Fhd) Ignore(filenames ...string) error

Ignore adds the given files or globs to the ignored list.

func (*Fhd) Ignored

func (me *Fhd) Ignored() ([]string, error)

Ignored returns the list of every ignored filename or glob.

func (*Fhd) Monitor

func (me *Fhd) Monitor(filenames ...string) (SaveResult, error)

Monitor adds the given files to be monitored _and_ does a Save. Returns the new Save ID (SID) and sets of missing and ignored files (which aren't monitored).

func (*Fhd) MonitorWithComment

func (me *Fhd) MonitorWithComment(comment string,
	filenames ...string) (SaveResult, error)

MonitorWithComment adds the given files to be monitored _and_ does an initial Save with the given comment. Returns the new Save ID (SID) and sets of missing and ignored files (which aren't monitored).

func (*Fhd) Monitored

func (me *Fhd) Monitored() ([]*StateItem, error)

Monitored returns the list of every monitored file.

func (*Fhd) Purge

func (me *Fhd) Purge(filename string) error

Purges deletes every save of the given file and adds the filename to the ignored list.

func (*Fhd) Rename

func (me *Fhd) Rename(oldFilename, newFilename string) (SaveResult, error)

Rename oldFilename to newFilename. This is merely a convenience for fhd.Unmonitor(oldFilename) followed by fhd.Monitor(newFilename).

func (*Fhd) Save

func (me *Fhd) Save(comment string) (SaveResult, error)

Save saves a snapshot of every monitored file that's changed and returns the corresponding SaveResult with the new save ID (SID) and sets of any missing and ignored files (which have now become unmonitored—or ignored).

func (*Fhd) SaveCount

func (me *Fhd) SaveCount() int

SaveCount returns the number of saved files in the most recent save.

func (*Fhd) SaveCountForSid

func (me *Fhd) SaveCountForSid(sid SID) int

SaveCountForSid returns the number of saved files in the specified save.

func (*Fhd) SaveInfoItemForSid

func (me *Fhd) SaveInfoItemForSid(sid SID) SaveInfoItem

SaveInfoItemForSid returns the SaveInfoItem for the given SID or an invalid SaveInfoItem on error.

func (*Fhd) Sid

func (me *Fhd) Sid() SID

Sid returns the most recent Save ID (SID) or InvalidSID on error.

func (*Fhd) Sids

func (me *Fhd) Sids() ([]SID, error)

Returns all the Save IDs (SIDs) from most- to least-recent.

func (*Fhd) SidsForFilename

func (me *Fhd) SidsForFilename(filename string) ([]SID, error)

Returns all the SIDs for the given filename from most- to least-recent.

func (*Fhd) StateForFilename

func (me *Fhd) StateForFilename(filename string) (StateVal, error)

Returns the most recent StateVal for the given filename.

func (*Fhd) States

func (me *Fhd) States() ([]*StateItem, error)

States returns the monitoring state of every monitored and unmonitored file and the SID of the last save it was saved into.

func (*Fhd) String

func (me *Fhd) String() string

func (*Fhd) Unignore

func (me *Fhd) Unignore(filenames ...string) error

Unignore deletes the given filenames or globs from the ignored list. But it never deletes "*.fhd".

func (*Fhd) Unmonitor

func (me *Fhd) Unmonitor(filenames ...string) error

Unmonitor sets the state of every given file to unmonitored if it is being monitored and preserves its SID. For any file that isn't already monitored, adds it to the ignored list.

func (*Fhd) Unmonitored

func (me *Fhd) Unmonitored() ([]*StateItem, error)

Unmonitored returns the list of every unmonitored file. These are files that have been monitored in the past but have been set to be unmonitored.

type SID

type SID uint32 // allows for 4 billion saves

func (SID) IsValid

func (me SID) IsValid() bool

type SaveInfoItem

type SaveInfoItem struct {
	Sid SID
	SaveInfoVal
}

func (*SaveInfoItem) IsValid

func (me *SaveInfoItem) IsValid() bool

func (*SaveInfoItem) String

func (me *SaveInfoItem) String() string

type SaveInfoVal

type SaveInfoVal struct {
	When    time.Time
	Comment string
}

type SaveResult

type SaveResult struct {
	SaveInfoItem
	MissingFiles gset.Set[string]
	IgnoredFiles gset.Set[string]
}

type StateItem

type StateItem struct {
	Filename string
	StateVal
}

func (StateItem) String

func (me StateItem) String() string

type StateVal

type StateVal struct {
	LastSid   SID // Most recent SID the corresponding file was saved into
	Monitored bool
	FileKind  fileKind
}

func (StateVal) String

func (me StateVal) String() string

Jump to

Keyboard shortcuts

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