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
- Variables
- func DeleteComponent(comp component.Component, name string, dirPath string) error
- func DeleteComponentFiles(dir string) error
- func DeleteDatasetFiles(dirPath string) error
- func FilesystemPathToLocal(qfsPath string) string
- func GetBody(dirPath string, offset, limit int, all bool) (interface{}, error)
- func GetLinkedFilesysRef(dir string) (dsref.Ref, bool)
- func GetProblems(comp component.Component) string
- func IsFSIPath(path string) bool
- func ReadBodyBytes(dirPath string, format dataset.DataFormat, fcfg dataset.FormatConfig, ...) ([]byte, error)
- func ReadDir(dir string) (*dataset.Dataset, error)
- func RepoPath(repoPath string) string
- func SplitDirByExist(fullpath string) (string, string)
- func WriteComponent(comp component.Component, name string, dirPath string) (string, error)
- func WriteComponents(ds *dataset.Dataset, dirPath string, fs qfs.Filesystem) error
- type FSI
- func (fsi *FSI) CalculateStateTransition(ctx context.Context, prev, next component.Component) (changes []StatusItem, err error)
- func (fsi *FSI) CanInitDatasetWorkDir(dir, bodyPath string) error
- func (fsi *FSI) CreateLink(ctx context.Context, dirPath string, ref dsref.Ref) (vi *dsref.VersionInfo, rollback func(), err error)
- func (fsi *FSI) EnsureRefNotLinked(ref dsref.Ref) error
- func (fsi *FSI) InitDataset(ctx context.Context, p InitParams) (ref dsref.Ref, err error)
- func (fsi *FSI) IsWorkingDirectoryClean(ctx context.Context, dir string) error
- func (fsi *FSI) ListLinks(offset, limit int) ([]dsref.VersionInfo, error)
- func (fsi *FSI) ModifyLinkDirectory(ctx context.Context, dirPath string, ref dsref.Ref) (*dsref.VersionInfo, error)
- func (fsi *FSI) ModifyLinkReference(dirPath string, ref dsref.Ref) (string, error)
- func (fsi *FSI) Remove(dirPath string) error
- func (fsi *FSI) RemoveAll(dirPath string) error
- func (fsi *FSI) ResolvedPath(ref *dsref.Ref) error
- func (fsi *FSI) Status(ctx context.Context, dir string) (changes []StatusItem, err error)
- func (fsi *FSI) StatusAtVersion(ctx context.Context, ref dsref.Ref) (changes []StatusItem, err error)
- func (fsi *FSI) Unlink(ctx context.Context, dirPath string, ref dsref.Ref) error
- type InitParams
- type StatusItem
Constants ¶
const PathPrefix = "/fsi"
PathPrefix indicates paths that are using file system integration
Variables ¶
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") )
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") )
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
DeleteComponent deletes the component with the given name from the directory
func DeleteComponentFiles ¶ added in v0.9.2
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 ¶
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
FilesystemPathToLocal converts a qfs.Filesystem path that has an /fsi prefix to a local path
func GetLinkedFilesysRef ¶
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
GetProblems returns the problem messages on a component collection
func IsFSIPath ¶ added in v0.9.13
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 RepoPath ¶
RepoPath returns the standard path to an FSI file for a given file-system repo location
func SplitDirByExist ¶ added in v0.10.0
SplitDirByExist splits a path into the part that exists, and the part that is missing
func WriteComponent ¶ added in v0.9.1
WriteComponent writes the component with the given name to the directory
func WriteComponents ¶
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 (*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
CanInitDatasetWorkDir returns nil if the directory can init a dataset, or an error if not
func (*FSI) CreateLink ¶
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
EnsureRefNotLinked checks if a ref already has an existing link on the file system
func (*FSI) InitDataset ¶
InitDataset creates a new dataset
func (*FSI) IsWorkingDirectoryClean ¶ added in v0.9.2
IsWorkingDirectoryClean returns nil if the directory is clean, or ErrWorkingDirectoryDirty if it is dirty
func (*FSI) ListLinks ¶ added in v0.9.9
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
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) RemoveAll ¶ added in v0.9.7
RemoveAll attempts to remove the dataset directory but also removes low value files first
func (*FSI) ResolvedPath ¶ added in v0.9.9
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 ¶
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.
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