qri: github.com/qri-io/qri/fsi Index | Files

package fsi

import "github.com/qri-io/qri/fsi"

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


Package Files

body.go fsi.go init.go mapping.go status.go


const QriRefFilename = ".qri-ref"

QriRefFilename is the name of the file that links a folder to a dataset. The file contains a dataset reference that declares the link ref files are the authoritative definition of weather a folder is linked or not


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"
    // 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 (

    // ErrNotLinkedToFilesystem 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")

package level logger

var PrepareToWrite = func(comp component.Component) {


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

func DeleteComponent Uses

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

DeleteComponent deletes the component with the given name from the directory

func DeleteComponentFiles Uses

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 Uses

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 GetBody Uses

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

GetBody is an FSI version of base.ReadBody

func GetLinkedFilesysRef Uses

func GetLinkedFilesysRef(dir string) (string, bool)

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

func GetProblems Uses

func GetProblems(comp component.Component) string

GetProblems returns the problem messages on a component collection

func ReadDir Uses

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

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

func RepoPath Uses

func RepoPath(repoPath string) string

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

func WriteComponent Uses

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

WriteComponent writes the component with the given name to the directory

func WriteComponents Uses

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

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

type FSI Uses

type FSI struct {
    // contains filtered or unexported fields

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

func NewFSI Uses

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

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

func (*FSI) AliasToLinkedDir Uses

func (fsi *FSI) AliasToLinkedDir(alias string) (string, error)

AliasToLinkedDir converts the given dataset alias to the FSI path it is linked to.

func (*FSI) CalculateStateTransition Uses

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 *FSI) CreateLink(dirPath, refStr string) (alias string, rollback func(), err error)

CreateLink links a working directory to a dataset. Returns the reference alias, and a rollback function if no error occurs

func (*FSI) InitDataset Uses

func (fsi *FSI) InitDataset(p InitParams) (name string, err error)

InitDataset creates a new dataset

func (*FSI) IsWorkingDirectoryClean Uses

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) LinkedRefs Uses

func (fsi *FSI) LinkedRefs(offset, limit int) ([]reporef.DatasetRef, error)

LinkedRefs returns a list of linked datasets and their connected directories

func (*FSI) ModifyLinkDirectory Uses

func (fsi *FSI) ModifyLinkDirectory(dirPath, refStr string) 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 Uses

func (fsi *FSI) ModifyLinkReference(dirPath, refStr 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) Status Uses

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 Uses

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

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

func (fsi *FSI) Unlink(dirPath, refStr string) error

Unlink breaks the connection between a directory and a dataset

type InitParams Uses

type InitParams struct {
    Dir            string
    Name           string
    Format         string
    Mkdir          string
    SourceBodyPath string

InitParams encapsulates parameters for fsi.InitDataset

type StatusItem Uses

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 Uses

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

MarshalJSON marshals a StatusItem, handling mtime specially

Package fsi imports 19 packages (graph) and is imported by 3 packages. Updated 2020-02-28. Refresh now. Tools for package owners.