fsi

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package fsi defines qri file system integration: representing a dataset as files in a directory on a user's computer. Using fsi, users can edit files as an interface for working with qri datasets.

A dataset is "linked" to a directory through a `.qri_ref` dotfile that connects the folder to a version history stored in the local qri repository.

files in a linked directory follow naming conventions that map to components of a dataset. eg: a file named "meta.json" in a linked directory maps to the dataset meta component. This mapping can be used to construct a dataset for read and write actions

Index

Constants

View Source
const PathPrefix = "/fsi"

PathPrefix indicates paths that are using file system integration

Variables

View Source
var (
	// STUnmodified is "no status"
	STUnmodified = "unmodified"
	// STAdd is an added component
	STAdd = "add"
	// STChange is a modified component
	STChange = "modified"
	// STRemoved is a removed component
	STRemoved = "removed"
	// STParseError is a component that didn't parse
	STParseError = "parse error"
	// STMissing is a component that is missing
	STMissing = "missing"
	// STConflictError is a component with a conflict
	STConflictError = "conflict error"
	// ErrWorkingDirectoryDirty is the error for when the working directory is not clean
	ErrWorkingDirectoryDirty = fmt.Errorf("working directory is dirty")
)
View Source
var (

	// ErrNoLink is the err implementers should return when we are expecting the
	// dataset to have a file system link, but fsiPath is empty
	ErrNoLink = fmt.Errorf("dataset is not linked to the filesystem")
)
View Source
var PrepareToWrite = func(comp component.Component) {

}

PrepareToWrite is called before init writes the components to the filesystem. Used by tests.

Functions

func DeleteComponent added in v0.9.1

func DeleteComponent(comp component.Component, name string, dirPath string) error

DeleteComponent deletes the component with the given name from the directory

func DeleteComponentFiles added in v0.9.2

func DeleteComponentFiles(dir string) error

DeleteComponentFiles deletes all component files in the directory. Should only be used if removing an entire dataset, or if the dataset is about to be rewritten back to the filesystem.

func DeleteDatasetFiles

func DeleteDatasetFiles(dirPath string) error

DeleteDatasetFiles removes mapped files from a directory. if the result of deleting all files leaves the directory empty, it will remove the directory as well

func FilesystemPathToLocal added in v0.9.10

func FilesystemPathToLocal(qfsPath string) string

FilesystemPathToLocal converts a qfs.Filesystem path that has an /fsi prefix to a local path

func GetBody

func GetBody(dirPath string, offset, limit int, all bool) (interface{}, error)

GetBody is an FSI version of base.GetBody

func GetLinkedFilesysRef

func GetLinkedFilesysRef(dir string) (dsref.Ref, bool)

GetLinkedFilesysRef returns whether a directory is linked to a dataset in your repo, and a reference to that dataset

func GetProblems added in v0.9.1

func GetProblems(comp component.Component) string

GetProblems returns the problem messages on a component collection

func IsFSIPath added in v0.9.13

func IsFSIPath(path string) bool

IsFSIPath is a utility function that returns whether the given path is a local filesystem path

func ReadBodyBytes added in v0.10.0

func ReadBodyBytes(dirPath string, format dataset.DataFormat, fcfg dataset.FormatConfig, offset, limit int, all bool) ([]byte, error)

ReadBodyBytes is an FSI version of base.ReadBodyBytes

func ReadDir

func ReadDir(dir string) (*dataset.Dataset, error)

ReadDir reads the component files in the directory, and returns a dataset

func RepoPath

func RepoPath(repoPath string) string

RepoPath returns the standard path to an FSI file for a given file-system repo location

func SplitDirByExist added in v0.10.0

func SplitDirByExist(fullpath string) (string, string)

SplitDirByExist splits a path into the part that exists, and the part that is missing

func WriteComponent added in v0.9.1

func WriteComponent(comp component.Component, name string, dirPath string) (string, error)

WriteComponent writes the component with the given name to the directory

func WriteComponents

func WriteComponents(ds *dataset.Dataset, dirPath string, fs qfs.Filesystem) error

WriteComponents writes components of the dataset to the given path, as individual files.

Types

type FSI

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

FSI is a repo-side struct for coordinating file system integration

func NewFSI

func NewFSI(r repo.Repo, pub event.Publisher) *FSI

NewFSI creates an FSI instance from a path to a links flatbuffer file

func (*FSI) CalculateStateTransition

func (fsi *FSI) CalculateStateTransition(ctx context.Context, prev, next component.Component) (changes []StatusItem, err error)

CalculateStateTransition calculates the differences between two versions of a dataset.

func (*FSI) CanInitDatasetWorkDir added in v0.9.9

func (fsi *FSI) CanInitDatasetWorkDir(dir, bodyPath string) error

CanInitDatasetWorkDir returns nil if the directory can init a dataset, or an error if not

func (fsi *FSI) CreateLink(ctx context.Context, dirPath string, ref dsref.Ref) (vi *dsref.VersionInfo, rollback func(), err error)

CreateLink links a working directory to an existing dataset. Returning updated VersionInfo and a rollback function if no error occurs

func (*FSI) EnsureRefNotLinked added in v0.9.8

func (fsi *FSI) EnsureRefNotLinked(ref dsref.Ref) error

EnsureRefNotLinked checks if a ref already has an existing link on the file system

func (*FSI) InitDataset

func (fsi *FSI) InitDataset(ctx context.Context, p InitParams) (ref dsref.Ref, err error)

InitDataset creates a new dataset

func (*FSI) IsWorkingDirectoryClean added in v0.9.2

func (fsi *FSI) IsWorkingDirectoryClean(ctx context.Context, dir string) error

IsWorkingDirectoryClean returns nil if the directory is clean, or ErrWorkingDirectoryDirty if it is dirty

func (fsi *FSI) ListLinks(offset, limit int) ([]dsref.VersionInfo, error)

ListLinks returns a list of linked datasets and their connected directories

func (*FSI) ModifyLinkDirectory added in v0.9.2

func (fsi *FSI) ModifyLinkDirectory(ctx context.Context, dirPath string, ref dsref.Ref) (*dsref.VersionInfo, error)

ModifyLinkDirectory changes the FSIPath in the repo so that it is linked to the directory. Does not affect the .qri-ref linkfile in the working directory. Called when the command-line interface or filesystem watcher detects that a working folder has been moved. TODO(dlong): Add a filesystem watcher that behaves as described TODO(dlong): Perhaps add a `qri mv` command that explicitly changes a working directory location

func (*FSI) ModifyLinkReference added in v0.9.2

func (fsi *FSI) ModifyLinkReference(dirPath string, ref dsref.Ref) (string, error)

ModifyLinkReference changes the reference that is in .qri-ref linkfile in the working directory. Does not affect the ref in the repo. Called when a rename command is invoked.

func (*FSI) Remove added in v0.9.7

func (fsi *FSI) Remove(dirPath string) error

Remove attempts to remove the dataset directory

func (*FSI) RemoveAll added in v0.9.7

func (fsi *FSI) RemoveAll(dirPath string) error

RemoveAll attempts to remove the dataset directory but also removes low value files first

func (*FSI) ResolvedPath added in v0.9.9

func (fsi *FSI) ResolvedPath(ref *dsref.Ref) error

ResolvedPath sets the Path value of a reference to the filesystem integration path if one exists, ignoring any prior Path value. If no FSI link exists ResolvedPath will return ErrNoLink

func (*FSI) Status

func (fsi *FSI) Status(ctx context.Context, dir string) (changes []StatusItem, err error)

Status compares status of the current working directory against the dataset's last version

func (*FSI) StatusAtVersion

func (fsi *FSI) StatusAtVersion(ctx context.Context, ref dsref.Ref) (changes []StatusItem, err error)

StatusAtVersion gets changes that happened at a particular version in a dataset's history.

func (fsi *FSI) Unlink(ctx context.Context, dirPath string, ref dsref.Ref) error

Unlink removes the link file (.qri-ref) in the directory, and removes the fsi path from the reference in the refstore

type InitParams

type InitParams struct {
	TargetDir  string `json:"targetDir" qri:"fspath"`
	Name       string `json:"name"`
	Format     string `json:"format"`
	BodyPath   string `json:"bodyPath" qri:"fspath"`
	UseDscache bool   `json:"useDscache"`
}

InitParams encapsulates parameters for fsi.InitDataset

type StatusItem

type StatusItem struct {
	SourceFile string    `json:"sourceFile"`
	Component  string    `json:"component"`
	Type       string    `json:"type"`
	Message    string    `json:"message"`
	Mtime      time.Time `json:"mtime"`
}

StatusItem is a component that has status representation on the filesystem

func (StatusItem) MarshalJSON

func (si StatusItem) MarshalJSON() ([]byte, error)

MarshalJSON marshals a StatusItem, handling mtime specially

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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