fsindex

package
v0.0.0-...-8112484 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultSettings = Settings{
		OmitRootNameFromPath:       false,
		StripFileExtensionFromName: true,
		UnknownCharsToDash:         false,
		HardLinks:                  false,
	}
)

Default Settings

Functions

This section is empty.

Types

type CBFile

type CBFile func(*Model, *FileEntry) bool // (*interface{}, error)

CBFile is a simple callback if you return true, then the caller function immediately returns.

type CBPath

type CBPath func(*Model, *PathEntry) bool // (*interface{}, error)

CBPath is a simple callback; if you return true, then the caller function immediately returns.

type FileEntry

type FileEntry struct {
	Parent    *PathEntry `json:"-"`              // Parent directory
	Name      string     `json:"name,omitempty"` //
	FullPath  string     `json:"-"`              // Complete directory path
	SHA1      string     `json:"sha1,omitempty"`
	Path      string     `json:"path,omitempty"`
	Extension string     `json:"ext,omitempty"`
	Mod       time.Time  `json:"mod"`
}

FileEntry ...

func (*FileEntry) Abs

func (f *FileEntry) Abs() string

Abs ...Get the absolute path of a given directory.

func (*FileEntry) Base

func (f *FileEntry) Base() string

Base ..

func (*FileEntry) GetSHA1

func (f *FileEntry) GetSHA1() string

GetSHA1 stores SHA1 hash on FileEntry and returns the result.

func (*FileEntry) Modified

func (f *FileEntry) Modified() string

Modified gets the file-system modified time.

func (*FileEntry) Rooted

func (f *FileEntry) Rooted(r *Model) string

Rooted returns the FileEntry.FullPath excluding the full root-path with exception to the root-directory name. It applies `Settings.OmitRootNameFromPath`.

func (*FileEntry) RootedPath

func (f *FileEntry) RootedPath(r *Model) string

RootedPath applies additional filtering on `FileEntry` such as `Settings.UnknownCharsToDash` and `Settings.OmitRootNameFromPath`.

type FileHandler

type FileHandler func(*Model, *FileEntry) bool

FileHandler is a simple callback.

type FileSpec

type FileSpec struct {
	Name       string   `json:"name"`
	Extensions []string `json:"ext"`
}

FileSpec structure.

func (*FileSpec) Match

func (f *FileSpec) Match(input string) bool

Match checks to see if an input file extention matches any of the file extensions defined in a given FileSpec.

type Handlers

type Handlers struct {
	ChildPath PathHandler
	ChildFile FileHandler
}

Handlers contains simple callbacks.

type Model

type Model struct {
	PathEntry
	IgnorePaths []string `json:"ignore,omitempty"`
	SimpleModel `json:"-"`
	Settings    `json:"-"`
}

Model is the same as PathEntry but with Settings

type PathEntry

type PathEntry struct {
	PathSpec

	FileFilter []FileSpec `json:"-"`
	Index      int32      `json:"id"`
	// FauxPath is only set on the root item and is
	// used to portray a URI from a relative path.
	FauxPath string `json:"uri,omitempty"`
}

PathEntry ...

func (*PathEntry) Info

func (p *PathEntry) Info()

Info prints out some PathEntry info, of course.

func (*PathEntry) IsIgnore

func (p *PathEntry) IsIgnore(r *Model) bool

IsIgnore is a case sensitive string matcher checking each path added to our index with a unix slash `/` path separator. We'll check against abspath, path name

func (*PathEntry) Refresh

func (p *PathEntry) Refresh(model *Model, counter *(int32), handler *Handlers)

Refresh refreshes child directories and files. parameter `rootPathEntry`: root-path entry. parameter `counter (*int32)`: pointer to our indexing integer (counter). parameter `callback (RefreshAction)` is a method (if defined) which

can be used arbitrarily.

func (*PathEntry) RefreshCB

func (p *PathEntry) RefreshCB(rootPathEntry *Model, counter *(int32), cbPath *CBPath, cbFile *CBFile)

RefreshCB refreshes child directories and files. parameter `rootPathEntry`: root-path entry. parameter `counter (*int32)`: pointer to our indexing integer (counter). parameter `callback (RefreshAction)` is a method (if defined) which

can be used arbitrarily.

Only difference here is that we're using CBPath and CBFile as opposed to a Handlers structure which contains callbacks for our `Refresh(…)`.

func (*PathEntry) Review

func (p *PathEntry) Review(mRoot *Model, cbPath *CBPath, cbFile *CBFile)

Review is similar to `Refresh()` except we don't rebuild the graph. here, we're just linking the callbacks, directories are listed before files like the `Refresh()` method.

func (*PathEntry) Top

func (p *PathEntry) Top() *PathEntry

Top gets the top-most, root path entry.

type PathHandler

type PathHandler func(*Model, *PathEntry) bool

PathHandler is a simple callback.

type PathSpec

type PathSpec struct {
	FileEntry

	// Indicates a top-level directory
	IsRoot bool `json:"-"`

	// Child items
	Paths []PathEntry `json:"paths,omitempty"`
	Files []FileEntry `json:"files,omitempty"`
}

PathSpec has to have a comment so there it is.

This structure is basis for file/directory navigation wrapping folder/file structure in memory.

type Settings

type Settings struct {
	// OmitRootNameFromPath will strip the root directory-name from indexed path targets.
	// Only the default value of false is currently known to be working.
	// For example if true, a path converted to "http path": path-in: "c:/mypath/mysubdir/my-target-path", path-out: "/".
	// If set to (default) false: path-in: "c:/mypath/mysubdir/my-target-path", path-out: "/my-target-path".
	OmitRootNameFromPath       bool `json:"omit-root"`
	StripFileExtensionFromName bool `json:"strip-file-ext,omitempty"` // since default=true: "opmitempty".
	UnknownCharsToDash         bool `json:"space2dash,omitempty"`     // not uet supported.
	HardLinks                  bool `json:"hard-link"`                // this tells us weather or not to use full link-path such as `http://[server:port]/` when generating JSON.
}

Settings will slightly alter how the `Refresh` method runs. Eventually, we'll convert this to flag-usage in the console client.

type SimpleModel

type SimpleModel struct {
	File     map[string]*FileEntry
	FileSHA1 map[string]*FileEntry
	Path     map[string]*PathEntry
	PathSHA1 map[string]*PathEntry
}

SimpleModel collects our indexes

func (*SimpleModel) AddFile

func (m *SimpleModel) AddFile(p *Model, c *FileEntry)

AddFile is a callback per FileEntry. It adds each FileEntry to a flat (non-hierarchical) map (dictionary).

func (*SimpleModel) AddPath

func (m *SimpleModel) AddPath(p *Model, c *PathEntry)

AddPath is a callback per PathEntry. It adds each PathEntry to a flat (non-hierarchical) map (dictionary).

func (*SimpleModel) CreateMaps

func (m *SimpleModel) CreateMaps()

CreateMaps makes a new data-set.

func (*SimpleModel) ResetMaps

func (m *SimpleModel) ResetMaps()

ResetMaps destroys all top level items (if hierarchical) in the maps.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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