Documentation ¶
Overview ¶
Package dircache provides a simple cache for caching directory to path lookups
Index ¶
- func SplitPath(path string) (directory, leaf string)
- type DirCache
- func (dc *DirCache) FindDir(ctx context.Context, path string, create bool) (pathID string, err error)
- func (dc *DirCache) FindPath(ctx context.Context, path string, create bool) (leaf, directoryID string, err error)
- func (dc *DirCache) FindRoot(ctx context.Context, create bool) error
- func (dc *DirCache) FindRootAndPath(ctx context.Context, path string, create bool) (leaf, directoryID string, err error)
- func (dc *DirCache) Flush()
- func (dc *DirCache) FlushDir(dir string)
- func (dc *DirCache) FoundRoot() bool
- func (dc *DirCache) Get(path string) (id string, ok bool)
- func (dc *DirCache) GetInv(id string) (path string, ok bool)
- func (dc *DirCache) Put(path, id string)
- func (dc *DirCache) ResetRoot()
- func (dc *DirCache) RootID() string
- func (dc *DirCache) RootParentID() (string, error)
- func (dc *DirCache) String() string
- type DirCacher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DirCache ¶
type DirCache struct {
// contains filtered or unexported fields
}
DirCache caches paths to directory IDs and vice versa
func (*DirCache) FindDir ¶
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 ¶
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 ¶
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 ¶
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) FlushDir ¶
FlushDir flushes the map of all data starting with dir
If dir is empty then this is equivalent to calling ResetRoot
func (*DirCache) FoundRoot ¶
FoundRoot returns whether the root directory has been found yet
Call this from FindLeaf or CreateDir only
func (*DirCache) ResetRoot ¶
func (dc *DirCache) ResetRoot()
ResetRoot resets the root directory to the absolute root and clears the DirCache
func (*DirCache) RootID ¶
RootID returns the ID of the root directory
This should be called after FindRoot
func (*DirCache) RootParentID ¶
RootParentID returns the ID of the parent of the root directory
This should be called after FindRoot