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 ID to path lookups and the inverse.

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

This is created with the true root ID and the root path.

In order to use the cache FindRoot() must be called on it without error. This isn't done at initialization as it isn't known whether the root and intermediate directories need to be created or not.

Most of the utility functions wil call FindRoot() on the caller's behalf with the create flag passed in.

The cache is safe for concurrent use

func (*DirCache) DirMove Uses

func (dc *DirCache) DirMove(
    ctx context.Context, srcDC *DirCache, srcRoot, srcRemote, dstRoot, dstRemote string) (srcID, srcDirectoryID, srcLeaf, dstDirectoryID, dstLeaf string, err error)

DirMove prepares to move the directory (srcDC, srcRoot, srcRemote) into the directory (dc, dstRoot, dstRemote)

It does all the checking, creates intermediate directories and returns leafs and IDs ready for the move.

This returns

- srcID - ID of the source directory - srcDirectoryID - ID of the parent of the source directory - srcLeaf - leaf name of the source directory - dstDirectoryID - ID of the parent of the destination directory - dstLeaf - leaf name of the destination directory

These should be used to do the actual move then srcDC.FlushDir(srcRemote) should be called.

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

It will call FindRoot if it hasn't been called already

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

If called with path == "" then it will return the ID of the parent directory of the root and the leaf name of the root in that directory. Note that it won't create the root directory in this case even if create is true.

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

It will call FindRoot if it hasn't been called already

func (*DirCache) FindRoot Uses

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

FindRoot finds the root directory if not already found

If successful this changes the root of the cache from the true root to the root specified by the path passed into New.

Resets the root directory

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

func (*DirCache) Flush Uses

func (dc *DirCache) Flush()

Flush the cache of all data

func (*DirCache) FlushDir Uses

func (dc *DirCache) FlushDir(dir string)

FlushDir flushes the map of all data starting with with the path dir.

If dir is empty string 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

func (*DirCache) Get Uses

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

Get a directory ID given a path

Returns the ID and a boolean as to whether it was found or not in the cache.

func (*DirCache) GetInv Uses

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

GetInv gets a path given a directory ID

Returns the path and a boolean as to whether it was found or not in the cache.

func (*DirCache) Put Uses

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

Put a (path, directory ID) pair into the cache

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(ctx context.Context, create bool) (ID string, err error)

RootID returns the ID of the root directory

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

func (*DirCache) RootParentID Uses

func (dc *DirCache) RootParentID(ctx context.Context, create bool) (ID string, err error)

RootParentID returns the ID of the parent of the root directory

If create is set it will make the root parent directory if not found (but not the root)

func (*DirCache) String Uses

func (dc *DirCache) String() string

String returns the directory cache in string form for debugging

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

This should be implemented by the backend and will be called by the dircache package when appropriate.

Package dircache imports 8 packages (graph) and is imported by 10 packages. Updated 2020-08-03. Refresh now. Tools for package owners.