Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DeterministicFileModificationTimestamp = time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC)
DeterministicFileModificationTimestamp is a fixed timestamp that can be provided to Directory.Chtimes() to give files deterministic modification times. It is used by bb_worker to ensure that all files in the input root of a build action have the same modification time. This is needed to make certain kinds of build actions (most notably Autoconf scripts) succeed.
2000-01-01T00:00:00Z was chosen, because it's easy to distinguish from genuine timestamps. 1970-01-01T00:00:00Z would be impractical to use, because it tends to cause regressions in practice.
Examples: https://bugs.python.org/issue34097 https://gerrit.wikimedia.org/r/#/c/mediawiki/core/+/437977/
var DontCreate = CreationMode{}
DontCreate indicates that opening should fail in case the target file does not exist.
Functions ¶
This section is empty.
Types ¶
type CreationMode ¶
type CreationMode struct {
// contains filtered or unexported fields
}
CreationMode specifies whether and how Directory.Open*() should create new files.
func CreateExcl ¶
func CreateExcl(perm os.FileMode) CreationMode
CreateExcl indicates that a new file should be created. If the target file already exists, opening shall fail.
func CreateReuse ¶
func CreateReuse(perm os.FileMode) CreationMode
CreateReuse indicates that a new file should be created if it doesn't already exist. If the target file already exists, that file will be opened instead.
type DeviceNumber ¶
type DeviceNumber struct {
// contains filtered or unexported fields
}
DeviceNumber stores a block or character device number, both as major/minor pair and the raw value. This is done because conversion between both formats is platform dependent and not always bijective.
func NewDeviceNumberFromMajorMinor ¶
func NewDeviceNumberFromMajorMinor(major, minor uint32) DeviceNumber
NewDeviceNumberFromMajorMinor creates a new device number based on a major/minor pair.
func NewDeviceNumberFromRaw ¶
func NewDeviceNumberFromRaw(raw uint64) DeviceNumber
NewDeviceNumberFromRaw creates a new device number based on a raw value.
func (DeviceNumber) ToMajorMinor ¶
func (d DeviceNumber) ToMajorMinor() (uint32, uint32)
ToMajorMinor returns the major/minor pair of the device number.
func (DeviceNumber) ToRaw ¶
func (d DeviceNumber) ToRaw() uint64
ToRaw returns the raw value of the device number.
type Directory ¶
type Directory interface { // EnterDirectory creates a derived directory handle for a // subdirectory of the current subtree. EnterDirectory(name path.Component) (DirectoryCloser, error) // Open a file contained within the directory for writing, only // allowing data to be appended to the end of the file. OpenAppend(name path.Component, creationMode CreationMode) (FileAppender, error) // Open a file contained within the directory for reading. The // CreationMode is assumed to be equal to DontCreate. OpenRead(name path.Component) (FileReader, error) // Open a file contained within the current directory for both // reading and writing. OpenReadWrite(name path.Component, creationMode CreationMode) (FileReadWriter, error) // Open a file contained within the current directory for writing. OpenWrite(name path.Component, creationMode CreationMode) (FileWriter, error) // Link is the equivalent of os.Link(). Link(oldName path.Component, newDirectory Directory, newName path.Component) error // Clonefile is the equivalent of unix.Clonefile on macOS. Clonefile(oldName path.Component, newDirectory Directory, newName path.Component) error // Lstat is the equivalent of os.Lstat(). Lstat(name path.Component) (FileInfo, error) // Mkdir is the equivalent of os.Mkdir(). Mkdir(name path.Component, perm os.FileMode) error // Mknod is the equivalent of unix.Mknod(). Mknod(name path.Component, perm os.FileMode, deviceNumber DeviceNumber) error // ReadDir is the equivalent of os.ReadDir(). ReadDir() ([]FileInfo, error) // Readlink is the equivalent of os.Readlink(). Readlink(name path.Component) (path.Parser, error) // Remove is the equivalent of os.Remove(). Remove(name path.Component) error // RemoveAll is the equivalent of os.RemoveAll(). RemoveAll(name path.Component) error // RemoveAllChildren empties out a directory, without removing // the directory itself. RemoveAllChildren() error // Rename is the equivalent of os.Rename(). Rename(oldName path.Component, newDirectory Directory, newName path.Component) error // Symlink is the equivalent of os.Symlink(). Symlink(oldName path.Parser, newName path.Component) error // Sync the contents of a directory (i.e., the list of names) to // disk. This does not sync the contents of the files // themselves. Sync() error // Chtimes sets the atime and mtime of the named file. Chtimes(name path.Component, atime, mtime time.Time) error // IsWritable checks whether the Directory can be written to by the current user. IsWritable() (bool, error) // IsWritableChild checks whether the path in the Directory can be written to by the current user. IsWritableChild(name path.Component) (bool, error) // Function that base types may use to implement calls that // require double dispatching, such as hardlinking and renaming. Apply(arg interface{}) error // Mount and Unmount. Mount(mountpoint path.Component, source, fstype string) error Unmount(mountpoint path.Component) error }
Directory is an abstraction for accessing a subtree of the file system. Each of the functions should be implemented in such a way that they reject access to data stored outside of the subtree. This allows for safe, race-free traversal of the file system.
By placing this in a separate interface, it's easier to stub out file system handling as part of unit tests entirely.
type DirectoryCloser ¶
DirectoryCloser is a Directory handle that can be released.
func NewLocalDirectory ¶
func NewLocalDirectory(directoryParser path.Parser) (DirectoryCloser, error)
NewLocalDirectory creates a directory handle that corresponds to a local path on the system.
func NopDirectoryCloser ¶
func NopDirectoryCloser(d Directory) DirectoryCloser
NopDirectoryCloser adds a no-op Close method to a Directory object, similar to how io.NopCloser() adds a Close method to a Reader.
type FileAppender ¶
FileAppender is returned by Directory.OpenAppend(). It is a handle for a file that only permits new data to be written to the end.
type FileInfo ¶
type FileInfo struct {
// contains filtered or unexported fields
}
FileInfo is a subset of os.FileInfo, only containing the features used by the Buildbarn codebase.
func NewFileInfo ¶
NewFileInfo constructs a FileInfo object that returns fixed values for its methods.
func (*FileInfo) IsExecutable ¶
IsExecutable returns whether the regular file is executable.
type FileInfoList ¶
type FileInfoList []FileInfo
FileInfoList is a list of FileInfo objects returned by Directory.ReadDir(). This type may be used to sort elements in the list by name.
func (FileInfoList) Len ¶
func (l FileInfoList) Len() int
func (FileInfoList) Less ¶
func (l FileInfoList) Less(i, j int) bool
func (FileInfoList) Swap ¶
func (l FileInfoList) Swap(i, j int)
type FileReadWriter ¶
type FileReadWriter interface { FileReader FileWriter }
FileReadWriter is returned by Directory.OpenReadWrite(). It is a handle for a file that permits data to be read from and written to arbitrary locations.
type FileReader ¶
type FileReader interface { io.Closer io.ReaderAt // Equivalent to lseek() with SEEK_DATA and SEEK_HOLE. // // These functions return io.EOF when the provided offset points // to or past the end-of-file position. Calling this function // with Data may also return io.EOF when no more data regions // exist past the provided offset. GetNextRegionOffset(offset int64, regionType RegionType) (int64, error) }
FileReader is returned by Directory.OpenRead(). It is a handle for a file that permits data to be read from arbitrary locations.
type FileType ¶
type FileType int
FileType is an enumeration of the type of a file stored on a file system.
const ( // FileTypeRegularFile means the file is a regular file. FileTypeRegularFile FileType = iota // FileTypeDirectory means the file is a directory. FileTypeDirectory // FileTypeSymlink means the file is a symbolic link. FileTypeSymlink // FileTypeBlockDevice means the file is a block device. FileTypeBlockDevice // FileTypeCharacterDevice means the file is a character device. FileTypeCharacterDevice // FileTypeFIFO means the file is a FIFO. FileTypeFIFO // FileTypeSocket means the file is a socket. FileTypeSocket // FileTypeOther means the file is neither a regular file, a // directory or symbolic link. FileTypeOther )
type FileWriter ¶
FileWriter is returned by Directory.OpenWrite(). It is a handle for a file that permits data to be written to arbitrary locations.
type ReferenceCountedDirectoryCloser ¶
type ReferenceCountedDirectoryCloser struct { DirectoryCloser // contains filtered or unexported fields }
ReferenceCountedDirectoryCloser is a decorator for DirectoryCloser that adds reference counting. This makes it possible to duplicate it, and call Close() on it multiple times.
func NewReferenceCountedDirectoryCloser ¶
func NewReferenceCountedDirectoryCloser(directory DirectoryCloser) *ReferenceCountedDirectoryCloser
NewReferenceCountedDirectoryCloser creates a new ReferenceCountedDirectoryCloser against which Close() can be called exactly once.
func (*ReferenceCountedDirectoryCloser) Close ¶
func (d *ReferenceCountedDirectoryCloser) Close() error
Close the ReferenceCountedDirectoryCloser by decreasing its reference count. If the reference count reaches zero, the underlying directory is closed.
func (*ReferenceCountedDirectoryCloser) Duplicate ¶
func (d *ReferenceCountedDirectoryCloser) Duplicate() *ReferenceCountedDirectoryCloser
Duplicate the ReferenceCountedDirectoryCloser by increasing its reference count.
type RegionType ¶
type RegionType int
RegionType is an enumeration type that can be provided to FileReader.GetNextRegionOffset() to specify whether the next offset for data or a hole should be obtained.
const ( // Data region inside a file. Data RegionType = 1 // Hole inside a sparse file. Hole RegionType = 2 )