local

package
v0.0.0-...-bb2c1c1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FS

type FS interface {
	fs.StatFS
	fs.ReadDirFS
	Mkdir(path string) error
	RemoveAll(path string) error
}

FS is an interface for making calls to a local file system.

type ID

type ID uint64

ID is a synthetic number for identifying a node.

const RootID ID = 1

RootID is the identifier for the root (ie, the synchronized directory).

type Node

type Node struct {
	ID       ID
	Ino      uint64 // 0 means unknown
	ParentID ID
	Name     string
	Type     types.Type
	Status   Status
}

Node is a file or directory on the local file system.

We don't use the inode number as the main identifier, as inode numbers can be reused on Linux, and we may want to says that two files (with two inode numbers) are the same like when saving a file by using a temporary file.

type Nodes

type Nodes struct {
	ByID       map[ID]*Node
	ByParentID map[ID]map[ID]*Node // parentID -> map of children
	ByIno      map[uint64]*Node
}

Nodes is keeping the information about the files in the synchronized directory of the local file system.

func NewNodes

func NewNodes() *Nodes

NewNodes creates a new state for managing nodes (data about files or directories on the local file system).

func (*Nodes) ByPath

func (nodes *Nodes) ByPath(path string) (*Node, error)

ByPath returns the node with the given path (if it exists).

func (*Nodes) CheckEventualConsistency

func (nodes *Nodes) CheckEventualConsistency() error

CheckEventualConsistency checks properties that should be true if a stable nodes is reached, ie when no changes are made to the local file system, and we wait that the desktop client says it is synchronized. Then, properties like all nodes have a type that is file or directory, not unknown, should be true.

func (*Nodes) CheckInvariants

func (nodes *Nodes) CheckInvariants() error

CheckInvariants checks a few properties that should always be true. It can be used to detect bugs in the nodes.Local implementation.

func (*Nodes) Children

func (nodes *Nodes) Children(parent *Node) map[ID]*Node

Children returns a map of id -> node for the children of the given directory.

func (*Nodes) MarkAsScanned

func (nodes *Nodes) MarkAsScanned(node *Node)

func (*Nodes) Path

func (nodes *Nodes) Path(doc *Node) string

Path return the path for the given node.

func (*Nodes) PrintTree

func (nodes *Nodes) PrintTree()

PrintTree can be used for debug.

func (*Nodes) Root

func (nodes *Nodes) Root() *Node

Root returns the node for the root of the synchronized directory.

func (*Nodes) Upsert

func (nodes *Nodes) Upsert(n *Node)

Upsert will add or update the given node in the nodes.

type Status

type Status int

Status describes what operations are in progress on a node to improve the knowledge we have of it. For a directory, we can scan it to find what are its children.

const (
	// InitialStatus is the default status of a new node
	InitialStatus Status = iota
	// ScanningStatus means that we are looking for the direct children of a directory
	ScanningStatus
	// ScannedStatus means that we know the direct children, but not yet the nodes below them
	ScannedStatus
	// StableStatus means that that the information about this node is reliable
	StableStatus
)

Jump to

Keyboard shortcuts

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