local

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package local tracks files by writing to JSON files in the dotfile directory.

For every new file that is tracked a new .json file is created. For each commit on a tracked file, a new file is created with the same name as the hash.

Example: ~/.emacs.d/init.el is added with alias "emacs". Supposing Storage.dir is ~/.config/dotfile, then the following files are created:

~/.config/dotfile/emacs.json ~/.config/dotfile/emacs/8f94c7720a648af9cf9dab33e7f297d28b8bf7cd

The emacs.json file would look something like this:

{
  "path": "~/.emacs.d/init.el",
  "revision": "8f94c7720a648af9cf9dab33e7f297d28b8bf7cd"
  "commits": [{
    "hash": "8f94c7720a648af9cf9dab33e7f297d28b8bf7cd",
    "timestamp": 1558896290,
    "message": "Initial commit"
  }]
}

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotTracked is returned when the current alias in storage is not tracked.
	ErrNotTracked = errors.New("file not tracked")
	// ErrNoData is returned when a method expects non nil file data.
	ErrNoData = errors.New("tracking data not loaded")
)

Functions

func DefaultConfigPath added in v1.0.0

func DefaultConfigPath() (string, error)

DefaultConfigPath returns the default config file.

func DefaultStorageDir added in v1.0.0

func DefaultStorageDir() (storageDir string, err error)

DefaultStorageDir returns the default location for storing dotfile information. Creates the location when it does not exist.

func List added in v1.0.0

func List(storageDir string, path bool) ([]string, error)

List returns a slice of aliases for all locally tracked files. When the file has uncommitted changes an asterisks is added to the end.

func ListAliases added in v1.0.3

func ListAliases(storageDir string) func() []string

ListAliases returns a funtion that lists all aliases in the storage directory.

func SetConfig added in v1.0.0

func SetConfig(path, key, value string) error

SetConfig sets a value in the dotfile config json file.

Types

type Config added in v1.0.0

type Config struct {
	Remote   string `json:"remote"`
	Username string `json:"username"`
	Token    string `json:"token"`
}

Config contains local user settings for dotfile.

func ReadConfig added in v1.0.0

func ReadConfig(path string) (*Config, error)

ReadConfig reads the user's config. Creates a default file when it doesn't yet exist.

func (*Config) String added in v1.0.0

func (c *Config) String() string

type Storage

type Storage struct {
	Alias    string                // The name of the file that is being tracked.
	Dir      string                // The path to the folder where data will be stored.
	FileData *dotfile.TrackingData // The current file that storage is tracking.
}

Storage provides methods for manipulating tracked files on the file system.

func InitializeFile added in v1.0.0

func InitializeFile(storageDir, path, alias string) (*Storage, error)

InitializeFile sets up a new file to be tracked. When alias is empty its generated from path. Returns a Storage that is loaded with the new file.

func (*Storage) DirtyContent added in v1.0.0

func (s *Storage) DirtyContent() ([]byte, error)

DirtyContent reads the current content of the tracked file. Returns nil when the file no longer exists.

func (*Storage) Forget added in v1.0.0

func (s *Storage) Forget() error

Forget removes all tracking information for alias.

func (*Storage) HasCommit

func (s *Storage) HasCommit(hash string) (exists bool, err error)

HasCommit return whether the file has a commit with hash.

func (*Storage) JSON added in v1.0.0

func (s *Storage) JSON() ([]byte, error)

JSON returns the tracked files json.

func (*Storage) Move added in v1.0.0

func (s *Storage) Move(newPath string, parentDirs bool) error

Move moves the file currently tracked by storage.

func (*Storage) Path added in v1.0.0

func (s *Storage) Path() (string, error)

Path gets the full path to the file. Utilizes $HOME to convert paths with ~ to absolute.

func (*Storage) Pull added in v1.0.0

func (s *Storage) Pull(client *dotfileclient.Client) error

Pull retrieves a file's commits from a dotfile server. Updates the local file with the new content from remote. FileData does not need to be set; its possible to pull a file that does not yet exist.

func (*Storage) Push added in v1.0.0

func (s *Storage) Push(client *dotfileclient.Client) error

Push pushes a file's commits to a remote dotfile server. Updates the remote file with the new content from local.

func (*Storage) Remove added in v1.0.0

func (s *Storage) Remove() error

Remove deletes the file that is tracked and all its data.

func (*Storage) RemoveCommits added in v1.0.0

func (s *Storage) RemoveCommits() error

RemoveCommits removes all commits except for the current.

func (*Storage) Rename added in v1.0.0

func (s *Storage) Rename(newAlias string) error

Rename changes a files alias.

func (*Storage) Revert

func (s *Storage) Revert(buff *bytes.Buffer, hash string) error

Revert writes files with buff and sets it current revision to hash.

func (*Storage) Revision added in v1.0.0

func (s *Storage) Revision(hash string) ([]byte, error)

Revision returns the files state at hash.

func (*Storage) SaveCommit

func (s *Storage) SaveCommit(buff *bytes.Buffer, c *dotfile.Commit) error

SaveCommit saves a commit to the file system. Creates a new directory when its the first commit. Updates the file's revision field to point to the new hash.

func (*Storage) SetTrackingData added in v1.0.0

func (s *Storage) SetTrackingData() error

SetTrackingData reads the tracking data from the filesystem into FileData.

Jump to

Keyboard shortcuts

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