Documentation
¶
Index ¶
- Constants
- func ConvertHistoryIndexAndDirName(currentHistoryIndex, indexDirName int) int
- func GetCurrentHistoryIndex(global bool) (int, error)
- func GetCurrentHistoryIndexFilePath(global bool) string
- func GetHistoryPath(id string, global bool) string
- func GetHistoryRootPath(global bool) string
- func GetStoragePath(id string) string
- func GetStorageRootPath() string
- func HistoryLoad(srcFS, dstFS vfs.FileSystem, id string, global bool) error
- func HistoryStore(srcFS, dstFS vfs.FileSystem, id string) error
- func LoadFromTmpHistory() error
- func ManualLoad(id string) error
- func ManualStore(id string) error
- func StoreFromCurrentToHistory() error
- func StoreFromLocalToGlobalHistory() error
- func StoreOrLoadFiles(srcFS, dstFS vfs.FileSystem, src, dst string, filenames ...*FilenameMapping) error
- func StoreToTmpHistory() error
- type FilenameMapping
- type HistoryEntry
- type HistoryInventory
- type StorageEntry
- type StorageInventory
Constants ¶
const ( StoreSubPath = "store" HistroySubPath = "history" CurrentHistoryFileName = "current" HistoryTmpKey = "tmp" )
Variables ¶
This section is empty.
Functions ¶
func ConvertHistoryIndexAndDirName ¶
ConvertHistoryIndexAndDirName converts between the current history index and a history directory name (which is an index too). This is necessary because the history directories are used like a cyclic buffer. The function is symmetrical and can be used to convert in both directions. If the returned index is negative or equal to/greater than the history depth, it means that either the directory is not part of the history or no corresponding directory was found. This can happen as a result of a changed history depth.
func GetCurrentHistoryIndex ¶
GetCurrentHistoryIndex returns the current history index. Returns -1 if the file doesn't exist and an error if the file can't be read or its contents don't parse into an integer.
func GetCurrentHistoryIndexFilePath ¶
GetCurrentHistoryIndexFilePath returns the path to the file containing the current history index.
func GetHistoryPath ¶
GetHistoryPath returns the path to the history directory for the given id.
func GetHistoryRootPath ¶
GetHistoryRootPath returns the path to the root directory for the history.
func GetStoragePath ¶
GetStoragePath returns the path to the storage directory for the given id.
func GetStorageRootPath ¶
func GetStorageRootPath() string
GetStorageRootPath returns the path to the root directory for the storage.
func HistoryLoad ¶
func HistoryLoad(srcFS, dstFS vfs.FileSystem, id string, global bool) error
HistoryLoad loads the configuration from the history.
func HistoryStore ¶
func HistoryStore(srcFS, dstFS vfs.FileSystem, id string) error
HistoryStore stores the current configuration in the history. This is only triggered by internal calls, not by manual calls to the store command.
func LoadFromTmpHistory ¶
func LoadFromTmpHistory() error
LoadFromTmpHistory loads the configuration from the temporary history. This can be used to recover the original configuration after a command has failed.
func ManualLoad ¶
ManualLoad handles a load operation that was caused by a manual call to the load command.
func ManualStore ¶
ManualStore handles a store operation that was caused by a manual call to the store command
func StoreFromCurrentToHistory ¶
func StoreFromCurrentToHistory() error
StoreFromCurrentToHistory copies the current state to the history. This is meant to be called after a command that has changed the configuration has been executed. This updates the current history index.
func StoreFromLocalToGlobalHistory ¶
func StoreFromLocalToGlobalHistory() error
StoreFromLocalToGlobalHistory stores current local history entry as newest global history entry. This is done by creating a symlink in the global history directory that points to the directory in the local history.
func StoreOrLoadFiles ¶
func StoreOrLoadFiles(srcFS, dstFS vfs.FileSystem, src, dst string, filenames ...*FilenameMapping) error
StoreOrLoadFiles takes a source and destination path and a mapping of filenames For each f1:f2 mapping, it copies 'src/f1' to 'dst/f2', if 'src/f1' exists. Otherwise, it removes 'dst/f2', if it exists. If multiple mappings point to the same destination file, latter mappings will overwrite earlier ones, but missing source files will not cause the removal of previously written destination files. The first two arguments must be paths to directories. The dst directory will be created, if it doesn't exist.
func StoreToTmpHistory ¶
func StoreToTmpHistory() error
StoreToTmpHistory stores the current configuration in the temporary history. This is meant to be called before a command that might change the configuration is executed.
Types ¶
type FilenameMapping ¶
FilenameMapping is a small helper struct that represents a mapping from a source filename to a destination filename We use a list of these instead of a map to ensure that the order is preserved. If SymlinkPossible is true, the symlink handling logic is enabled.
func Fnm ¶
func Fnm(src, dst string) *FilenameMapping
Fnm is a helper constructor for FilenameMapping
func Fnmi ¶
func Fnmi(src string) *FilenameMapping
Fnmi is a helper constructor for FilenameMapping, that maps the source filename to itself
func (*FilenameMapping) WithPossibleSymlink ¶
func (f *FilenameMapping) WithPossibleSymlink() *FilenameMapping
type HistoryEntry ¶
type HistoryEntry abstractInventoryEntry[int]
func (*HistoryEntry) String ¶
func (he *HistoryEntry) String() string
type HistoryInventory ¶
type HistoryInventory []*HistoryEntry
HistoryInventory is an internal representation of the history. The file-system history is converted into this for better internal handling and display.
func RenderHistory ¶
func RenderHistory(global bool) (HistoryInventory, error)
RenderHistory converts the file-based history into an internal representation.
func (HistoryInventory) MarshalJSON ¶
func (h HistoryInventory) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (HistoryInventory) String ¶
func (hi HistoryInventory) String() string
String returns a human-readable representation of the history inventory. Reverses the order to print the most recent entries last.
func (HistoryInventory) ToStrings ¶
func (hi HistoryInventory) ToStrings() []string
ToStrings converts the history inventory into a slice of strings for easier display.
type StorageEntry ¶
type StorageEntry abstractInventoryEntry[string]
func (*StorageEntry) String ¶
func (se *StorageEntry) String() string
type StorageInventory ¶
type StorageInventory []*StorageEntry
func RenderStorageInventory ¶
func RenderStorageInventory() (StorageInventory, error)
RenderStorageInventory converts the file-based storage into an internal representation.
func (StorageInventory) MarshalJSON ¶
func (si StorageInventory) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (StorageInventory) String ¶
func (si StorageInventory) String() string