rclone: github.com/ncw/rclone/lib/dircache Index | Files

package dircache

import "github.com/ncw/rclone/lib/dircache"

Package dircache provides a simple cache for caching directory to path lookups

Index

Package Files

dircache.go

func SplitPath Uses

func SplitPath(path string) (directory, leaf string)

SplitPath splits a path into directory, leaf

Path shouldn't start or end with a /

If there are no slashes then directory will be "" and leaf = path

type DirCache Uses

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

DirCache caches paths to directory IDs and vice versa

func New Uses

func New(root string, trueRootID string, fs DirCacher) *DirCache

New makes a DirCache

The cache is safe for concurrent use

func (*DirCache) FindDir Uses

func (dc *DirCache) FindDir(ctx context.Context, path string, create bool) (pathID string, err error)

FindDir finds the directory passed in returning the directory ID starting from pathID

Path shouldn't start or end with a /

If create is set it will make the directory if not found

Algorithm:

Look in the cache for the path, if found return the pathID
If not found strip the last path off the path and recurse
Now have a parent directory id, so look in the parent for self and return it

func (*DirCache) FindPath Uses

func (dc *DirCache) FindPath(ctx context.Context, path string, create bool) (leaf, directoryID string, err error)

FindPath finds the leaf and directoryID from a path

Do not call FindPath with the root directory - it will return an error

If create is set parent directories will be created if they don't exist

func (*DirCache) FindRoot Uses

func (dc *DirCache) FindRoot(ctx context.Context, create bool) error

FindRoot finds the root directory if not already found

Resets the root directory

If create is set it will make the directory if not found

func (*DirCache) FindRootAndPath Uses

func (dc *DirCache) FindRootAndPath(ctx context.Context, path string, create bool) (leaf, directoryID string, err error)

FindRootAndPath finds the root first if not found then finds leaf and directoryID from a path

If create is set parent directories will be created if they don't exist

func (*DirCache) Flush Uses

func (dc *DirCache) Flush()

Flush the map of all data

func (*DirCache) FlushDir Uses

func (dc *DirCache) FlushDir(dir string)

FlushDir flushes the map of all data starting with dir

If dir is empty then this is equivalent to calling ResetRoot

func (*DirCache) FoundRoot Uses

func (dc *DirCache) FoundRoot() bool

FoundRoot returns whether the root directory has been found yet

Call this from FindLeaf or CreateDir only

func (*DirCache) Get Uses

func (dc *DirCache) Get(path string) (id string, ok bool)

Get an ID given a path

func (*DirCache) GetInv Uses

func (dc *DirCache) GetInv(id string) (path string, ok bool)

GetInv gets a path given an ID

func (*DirCache) Put Uses

func (dc *DirCache) Put(path, id string)

Put a path, id into the map

func (*DirCache) ResetRoot Uses

func (dc *DirCache) ResetRoot()

ResetRoot resets the root directory to the absolute root and clears the DirCache

func (*DirCache) RootID Uses

func (dc *DirCache) RootID() string

RootID returns the ID of the root directory

This should be called after FindRoot

func (*DirCache) RootParentID Uses

func (dc *DirCache) RootParentID() (string, error)

RootParentID returns the ID of the parent of the root directory

This should be called after FindRoot

type DirCacher Uses

type DirCacher interface {
    FindLeaf(ctx context.Context, pathID, leaf string) (pathIDOut string, found bool, err error)
    CreateDir(ctx context.Context, pathID, leaf string) (newID string, err error)
}

DirCacher describes an interface for doing the low level directory work

Package dircache imports 6 packages (graph) and is imported by 6 packages. Updated 2019-06-25. Refresh now. Tools for package owners.