managedfs

package
v0.0.0-...-678bb0e Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2017 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package managedfs offers a managed filesystem. A managed filesystem assumes that it has ownership of a specified directory and all of that directory's contents, and tracks directory and creation.

This is useful in enabling the reuse of managed directories. In between uses, new files may be added and old files may be deleted. A managed filesystem allows the user to perform all of the creation operations and then, via "CleanUp", reduce the actual filesystem to the target state without performing a massive recursive deletion at the beginning.

Additionally, the directory and file objects have utility functions that are useful to "deploytool".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dir

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

Dir is a managed directory, rooted in a Filesystem.

func (*Dir) CleanUp

func (d *Dir) CleanUp() error

CleanUp deletes any unmanaged files within this directory and its descendants.

The filesystem's lock is held for the duration of the cleanup.

func (*Dir) EnsureDirectory

func (d *Dir) EnsureDirectory(elem string, elems ...string) (*Dir, error)

EnsureDirectory returns a managed sub-directory composed by joining all of the specified elements together.

If the described directory doesn't exist, it will be created.

func (*Dir) File

func (d *Dir) File(name string) *File

File creates a new managed File immediately within d.

func (*Dir) GetSubDirectory

func (d *Dir) GetSubDirectory(elem string, elems ...string) *Dir

GetSubDirectory returns a managed sub-directory composed by joining all of the specified elements.

Unlike EnsureDirectory, this does not actually create the specified directory.

func (*Dir) Ignore

func (d *Dir) Ignore()

Ignore configures d to be marked as ignored. This causes it and all of its contents to be exempt from cleanup.

func (*Dir) RelPath

func (d *Dir) RelPath() string

RelPath returns the path of this Dir relative to its filesystem root.

func (*Dir) RelPathFrom

func (d *Dir) RelPathFrom(targpath string) (string, error)

RelPathFrom returns the relative path from d to targpath. It also asserts that targpath is under the Filesystem root.

func (*Dir) ShallowSymlinkFrom

func (d *Dir) ShallowSymlinkFrom(dir string, rel bool) error

ShallowSymlinkFrom creates one symlink under d per regular file in dir.

func (*Dir) String

func (d *Dir) String() string

String returns the full path of this managed directory.

type File

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

File is a managed file within a managed Dir.

func (*File) CopyFrom

func (f *File) CopyFrom(src string) (rerr error)

CopyFrom copies contents from the specified path to f's location.

func (*File) GenerateGo

func (f *File) GenerateGo(c context.Context, content string) error

GenerateGo writes Go contents to the supplied filesystem.

func (*File) GenerateTextProto

func (f *File) GenerateTextProto(c context.Context, msg proto.Message) error

GenerateTextProto writes the specified object as rendered text protobuf to f's location.

func (*File) GenerateYAML

func (f *File) GenerateYAML(c context.Context, obj interface{}) error

GenerateYAML writes the specified object as a YAML file to f's location.

func (*File) Name

func (f *File) Name() string

Name returns the last path component to this file, it's file name.

func (*File) ReadAll

func (f *File) ReadAll() ([]byte, error)

ReadAll reads the contents of the file at f's location.

func (*File) RelPath

func (f *File) RelPath() string

RelPath returns the path of this File relative to its filesystem root.

func (*File) SameAs

func (f *File) SameAs(other string) (bool, error)

SameAs returns true if the spceified path is the exact same file as the file at f's location.

func (*File) String

func (f *File) String() string

String returns the full path of this File.

func (*File) SymlinkFrom

func (f *File) SymlinkFrom(from string, rel bool) error

SymlinkFrom writes a symlink from the specified path to f's location.

If rel is true, the symlink's target will be "from" relative to the managed filesystem's root. If it goes above the root, it is an error.

func (*File) WriteData

func (f *File) WriteData(d []byte) (err error)

WriteData writes the supplied bytes to f's location.

func (*File) WriteDataFrom

func (f *File) WriteDataFrom(fn func(io.Writer) error) (err error)

WriteDataFrom creates a new file at f's location and passes a Writer to this file to the supplied callback.

type Filesystem

type Filesystem struct {
	// GenName is the name of the tool that will be referenced in generated
	// content.
	GenName string
	// GenHeader is generated header text lines that should be added to any
	// generated file.
	GenHeader []string
	// contains filtered or unexported fields
}

Filesystem is a managed directory struct. It will track all files and directories added to it.

Its "CleanUp" method may be invoked, which will crawl the directory space and delete any directories and files that were not explicitly added during to it.

func New

func New(rootDir string) (*Filesystem, error)

New creates a new managed filesystem rooted at the target directory.

The filesystem will create rootDir if it does not exist, and assumes total ownership of its contents.

func (*Filesystem) Base

func (fs *Filesystem) Base() *Dir

Base returns the base Dir for this filesystem.

Jump to

Keyboard shortcuts

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