store

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2018 License: BSD-3-Clause Imports: 12 Imported by: 2

Documentation

Overview

Package store manages the files that are used to hold sure data.

Sure data is stored in a small number of files, referred to as sure files. The features used will determine which of these files is used for a given operation.

The most basic operation is to store the data in a pair of files. These will have names:

2sure.dat.gz
2sure.bak.gz

with .dat.gz representing the most recent scan, and .bak.gz representing the previous one. Earlier scans are discarded. During operation, the store will write to a temporary file 2sure.nn.gz, where nn is an incrementing integer, starting with 0. This is done because it is unsafe to overwrite files as root, and sure is often run as root. The store will use the lowest numbered file that does not exist, and remove it when it is finished. The use of the number prevents failure if a file is somehow left behind.

The options available to the basic store are that the files may or may not be compressed (with or without the .gz suffix), the path that the files should be stored in (a general default is the base of the tree being scanned), and the prefix ("2sure") part of the name.

When the backups are stored as weave files, the same file names are used (the software can tell by reading the files if they are weave format). The primary difference being that the ".dat.gz" file will hold all of the previous versions. The ".bak.gz" is redundant in this case, but one version is kept around for safety. This format is generally more useful to accompany backups, for example, where the backup may have multiple versions stored in it, and these can be kept in the surefile store as well.

In order to write the weave versions, the user must provide one or more tags to distinguish the particular version being written.

Index

Constants

View Source
const (
	DeltaLatest = -1 // The most recent version.
	DeltaPrior  = -2 // The second to most recent version.
)

Magic delta numbers to refer to previous deltas TODO: Interpret these the same as slices in python to be more flexible.

Variables

This section is empty.

Functions

This section is empty.

Types

type InvalidName

type InvalidName string

InvalidName is an error returned if the name contains an unknown extension.

func (InvalidName) Error

func (n InvalidName) Error() string

type NotDir

type NotDir string

NotDir is an error returned when the name doesn't describe an existing path.

func (NotDir) Error

func (n NotDir) Error() string

type Store

type Store struct {
	Path  string            // The directory where the surefiles will be written.
	Base  string            // The initial part of the name.
	Ext   string            // The extension to use "normally dat"
	Plain bool              // Plain indicates the files should not be compressed.
	Tags  map[string]string // For delta stores, indicates tags for next delta written.
	Name  string            // The name used to describe this capture.
}

The Store represents the current surefile store. The default values will result in a the files "./2sure.dat.gz" and the likes being used.

func (*Store) BackupFile

func (s *Store) BackupFile() string

BackupFile returns the name of the backup file.

func (*Store) FixTags

func (s *Store) FixTags()

FixTags adjusts the tags appropriately after any options from the user have been processed. If 'name' is not given, it will have the same value as time. The name will be deleted from the tags, and placed into the Name value in the struct.

func (*Store) GetDelta

func (s *Store) GetDelta(num int) (int, error)

GetDelta canonicalizes a delta number. Returns an error if there was no delta to read.

func (*Store) IsCompressed

func (s *Store) IsCompressed() bool

IsCompressed returns whether or not this store is compressed.

func (*Store) MainFile

func (s *Store) MainFile() string

MainFile return the main file name.

func (*Store) Parse

func (s *Store) Parse(name string) error

Parse attempts to determine the parameters of the Store structure based on a user-specified path. The path specified can be the path to a directory. In this case, we will look at possible filenames to determine the other parameters. The path can also give a filename of one of the surefiles, and we will derive the name information from that.

If the error result is nil, the Store will have the parameters set according to user preferences. Otherwise, the error will give details, and the Store will remain unchanged.

func (*Store) ReadBak

func (s *Store) ReadBak() (*sure.Tree, error)

ReadBak reads a tree from the backup file.

func (*Store) ReadDat

func (s *Store) ReadDat() (*sure.Tree, error)

ReadDat reads a tree from the data file.

func (*Store) ReadDelta

func (s *Store) ReadDelta(num int) (*sure.Tree, error)

ReadDelta reads a given delta number. The delta can be a number retrieved from the header, or it can be one of the above DeltaLatest, or DeltaPrior constants to read specific recent or nearly recent versions.

func (*Store) ReadHeader

func (s *Store) ReadHeader() (*weave.Header, error)

ReadHeader attempts to read the header from the storefile.

func (*Store) Set

func (s *Store) Set(value string) error

Set sets the name of this store. Used to parse the command line.

func (*Store) String

func (s *Store) String() string

func (*Store) TempFile

func (s *Store) TempFile(num int, compressed bool) string

TempFile is used by the naming convention to generate temp files. We just use the number as the extension.

func (*Store) Type

func (s *Store) Type() string

Type returns a short description of the type of the store. Used by the command parsing to print help.

func (*Store) Write

func (s *Store) Write(tree *sure.Tree) error

Write writes a new version to the surefile.

func (*Store) WriteDelta

func (s *Store) WriteDelta(tree *sure.Tree, base int) error

WriteDelta writes a new delta to the surefile, knowing the previous version.

type Tags

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

Tags wraps the store as a 'Value' to use the tags as a command line argument.

func NewTags

func NewTags(store *Store) Tags

NewTags create a new Tags struct, wrapping a given store.

func (Tags) Set

func (t Tags) Set(value string) error

Set adds a new tag, from the command line parsing. Must be of the form key=value.

func (Tags) String

func (t Tags) String() string

func (Tags) Type

func (t Tags) Type() string

Type returns a descriptive name for this type, for help messages.

Jump to

Keyboard shortcuts

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