dircache

package
v0.0.0-...-e391311 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2015 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

dircache provides a simple cache for caching directory to path lookups

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitPath

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

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

Types

type DirCache

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

DirCache caches paths to directory IDs and vice versa

func New

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

Make a new DirCache

The cache is safe for concurrent use

func (*DirCache) FindDir

func (dc *DirCache) FindDir(path string, create bool) (pathID string, err error)

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(path string, create bool) (leaf, directoryID string, err error)

FindPath finds the leaf and directoryID from a path

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

func (*DirCache) FindRoot

func (dc *DirCache) FindRoot(create bool) error

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) Flush

func (dc *DirCache) Flush()

Flush the map of all data

func (*DirCache) Get

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

Gets an ID given a path

func (*DirCache) GetInv

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

GetInv gets a path given an ID

func (*DirCache) Put

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

Put a path, id into the map

func (*DirCache) ResetRoot

func (dc *DirCache) ResetRoot()

Resets the root directory to the absolute root and clears the DirCache

func (*DirCache) RootID

func (dc *DirCache) RootID() string

RootID returns the ID of the root directory

This should be called after FindRoot

func (*DirCache) RootParentID

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

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

DirCache describes an interface for doing the low level directory work

Jump to

Keyboard shortcuts

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