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 ¶
- type Dir
- func (d *Dir) CleanUp() error
- func (d *Dir) EnsureDirectory(elem string, elems ...string) (*Dir, error)
- func (d *Dir) File(name string) *File
- func (d *Dir) GetSubDirectory(elem string, elems ...string) *Dir
- func (d *Dir) Ignore()
- func (d *Dir) RelPath() string
- func (d *Dir) RelPathFrom(targpath string) (string, error)
- func (d *Dir) ShallowSymlinkFrom(dir string, rel bool) error
- func (d *Dir) String() string
- type File
- func (f *File) CopyFrom(src string) (rerr error)
- func (f *File) GenerateGo(c context.Context, content string) error
- func (f *File) GenerateTextProto(c context.Context, msg proto.Message) error
- func (f *File) GenerateYAML(c context.Context, obj interface{}) error
- func (f *File) Name() string
- func (f *File) ReadAll() ([]byte, error)
- func (f *File) RelPath() string
- func (f *File) SameAs(other string) (bool, error)
- func (f *File) String() string
- func (f *File) SymlinkFrom(from string, rel bool) error
- func (f *File) WriteData(d []byte) (err error)
- func (f *File) WriteDataFrom(fn func(io.Writer) error) (err error)
- type Filesystem
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 ¶
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 ¶
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 ¶
File creates a new managed File immediately within d.
func (*Dir) GetSubDirectory ¶
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 ¶
RelPath returns the path of this Dir relative to its filesystem root.
func (*Dir) RelPathFrom ¶
RelPathFrom returns the relative path from d to targpath. It also asserts that targpath is under the Filesystem root.
func (*Dir) ShallowSymlinkFrom ¶
ShallowSymlinkFrom creates one symlink under d per regular file in dir.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is a managed file within a managed Dir.
func (*File) CopyFrom ¶
CopyFrom copies contents from the specified path to f's location.
func (*File) GenerateGo ¶
GenerateGo writes Go contents to the supplied filesystem.
func (*File) GenerateTextProto ¶
GenerateTextProto writes the specified object as rendered text protobuf to f's location.
func (*File) GenerateYAML ¶
GenerateYAML writes the specified object as a YAML file to f's location.
func (*File) Name ¶
Name returns the last path component to this file, it's file name.
func (*File) ReadAll ¶
ReadAll reads the contents of the file at f's location.
func (*File) RelPath ¶
RelPath returns the path of this File relative to its filesystem root.
func (*File) SameAs ¶
SameAs returns true if the spceified path is the exact same file as the file at f's location.
func (*File) SymlinkFrom ¶
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 ¶
WriteData writes the supplied bytes to f's location.
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.