Documentation
¶
Overview ¶
Package hashfs provides a filesystem with digest hash.
Index ¶
- Variables
- func Load(ctx context.Context, opts Option) (*pb.State, error)
- func Save(ctx context.Context, state *pb.State, opts Option) error
- func StateMap(s *pb.State) map[string]*pb.Entry
- type DataSource
- type Dir
- type DirEntry
- type FSMonitor
- type File
- type FileInfo
- func (fi FileInfo) Action() digest.Digest
- func (fi FileInfo) CmdHash() []byte
- func (fi FileInfo) IsChanged() bool
- func (fi FileInfo) IsDir() bool
- func (fi FileInfo) IsMissingChecked() bool
- func (fi FileInfo) ModTime() time.Time
- func (fi FileInfo) Mode() fs.FileMode
- func (fi FileInfo) Name() string
- func (fi *FileInfo) Path() string
- func (fi FileInfo) Size() int64
- func (fi FileInfo) Sys() any
- func (fi FileInfo) Target() string
- func (fi FileInfo) UpdatedTime() time.Time
- type FileInfoer
- type FileSystem
- func (fsys FileSystem) Open(name string) (fs.File, error)
- func (fsys FileSystem) ReadDir(name string) ([]fs.DirEntry, error)
- func (fsys FileSystem) ReadFile(name string) ([]byte, error)
- func (fsys FileSystem) Stat(name string) (fs.FileInfo, error)
- func (fsys FileSystem) Sub(dir string) (fs.FS, error)
- type HashFS
- func (hfs *HashFS) Availables(ctx context.Context, root string, inputs []string) []string
- func (hfs *HashFS) Close(ctx context.Context) error
- func (hfs *HashFS) Copy(ctx context.Context, root, src, dst string, mtime time.Time, cmdhash []byte) error
- func (hfs *HashFS) DataSource() DataSource
- func (hfs *HashFS) Entries(ctx context.Context, root string, inputs []string) ([]merkletree.Entry, error)
- func (hfs *HashFS) FileSystem(ctx context.Context, dir string) FileSystem
- func (hfs *HashFS) Flush(ctx context.Context, execRoot string, files []string) error
- func (hfs *HashFS) Forget(ctx context.Context, root string, inputs []string)
- func (hfs *HashFS) ForgetMissings(ctx context.Context, root string, inputs []string) []string
- func (hfs *HashFS) ForgetMissingsInDir(ctx context.Context, root, dir string)
- func (hfs *HashFS) IsClean() bool
- func (hfs *HashFS) LoadErr() error
- func (hfs *HashFS) Mkdir(ctx context.Context, root, dirname string, cmdhash []byte) error
- func (hfs *HashFS) NeedFlush(ctx context.Context, execRoot, fname string) bool
- func (hfs *HashFS) Notify(f NotifyFunc)
- func (hfs *HashFS) OnCog() bool
- func (hfs *HashFS) PreviouslyGeneratedFiles() []string
- func (hfs *HashFS) ReadDir(ctx context.Context, root, name string) (dents []DirEntry, err error)
- func (hfs *HashFS) ReadFile(ctx context.Context, root, fname string) ([]byte, error)
- func (hfs *HashFS) Refresh(ctx context.Context, execRoot string) error
- func (hfs *HashFS) Remove(ctx context.Context, root, fname string) error
- func (hfs *HashFS) RemoveAll(ctx context.Context, root, name string) error
- func (hfs *HashFS) RetrieveUpdateEntries(ctx context.Context, root string, fnames []string) []UpdateEntry
- func (hfs *HashFS) RetrieveUpdateEntriesFromLocal(ctx context.Context, root string, fnames []string) []UpdateEntry
- func (hfs *HashFS) SetExecutables(m map[string]bool)
- func (hfs *HashFS) SetState(ctx context.Context, state *pb.State) error
- func (hfs *HashFS) Stat(ctx context.Context, root, fname string) (FileInfo, error)
- func (hfs *HashFS) State(ctx context.Context) *pb.State
- func (hfs *HashFS) Symlink(ctx context.Context, root, target, linkpath string, mtime time.Time, ...) error
- func (hfs *HashFS) TaintedFiles() []string
- func (hfs *HashFS) Update(ctx context.Context, execRoot string, entries []UpdateEntry) error
- func (hfs *HashFS) WaitReady(ctx context.Context) error
- func (hfs *HashFS) WriteFile(ctx context.Context, root, fname string, b []byte, isExecutable bool, ...) error
- type IgnoreFunc
- type NotifyFunc
- type Option
- type OutputLocalFunc
- type UpdateEntry
Constants ¶
This section is empty.
Variables ¶
var DigestSemaphore = semaphore.New("file-digest", runtimex.NumCPU())
DigestSemaphore is a semaphore to control concurrent digest calculation.
var FlushSemaphore = semaphore.New("fs-flush", runtimex.NumCPU()*2)
FlushSemaphore is a semaphore to control concurrent flushes.
var ForgetMissingsSemaphore = semaphore.New("fs-forget", runtimex.NumCPU()*2)
ForgetMissingsSemaphore is a semaphore to control concurrent ForgetMissings. os.Lstat in ForgetMissings would create lots of thread. b/325565625
Functions ¶
Types ¶
type DataSource ¶
DataSource is an interface to get digest source for digest and its name.
type Dir ¶
type Dir struct {
// contains filtered or unexported fields
}
Dir implements https://pkg.go.dev/io/fs#ReadDirFile.
type DirEntry ¶
type DirEntry struct {
// contains filtered or unexported fields
}
DirEntry implements https://pkg.go.dev/io/fs#DirEntry.
type FSMonitor ¶
type FSMonitor interface { // ClockToken returns a token that represents the check time. ClockToken(context.Context) (string, error) // Scan returns FileInfoer from last checked token. Scan(context.Context, string) (FileInfoer, error) }
FSMonitor provides a way to access file info on the disk for the entry.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File implements https://pkg.go.dev/io/fs#File. This is an in-memory representation of the file.
type FileInfo ¶
type FileInfo struct {
// contains filtered or unexported fields
}
FileInfo implements https://pkg.go.dev/io/fs#FileInfo.
func (FileInfo) IsMissingChecked ¶
IsMissingChecked returns true if file has been checked existence for ForgetMissings.
func (FileInfo) Sys ¶
Sys returns merkletree Entry of the file. For local file, digest may not be calculated yet. Use Entries to get correct merkletree.Entry.
func (FileInfo) Target ¶
Target returns a symlink target of the file, or empty if it is not symlink.
func (FileInfo) UpdatedTime ¶
UpdatedTime is a update time of the file. Usually it is the same with ModTime, but may differ for restat=1.
type FileInfoer ¶
FileInfoer get fs.FileInfo for *pb.Entry from the disk.
type FileSystem ¶
type FileSystem struct {
// contains filtered or unexported fields
}
FileSystem provides fs.{FS,ReadDirFS,ReadFileFS,StatFS,SubFS} interfaces.
func (FileSystem) Open ¶
func (fsys FileSystem) Open(name string) (fs.File, error)
Open opens a file for name.
func (FileSystem) ReadDir ¶
func (fsys FileSystem) ReadDir(name string) ([]fs.DirEntry, error)
ReadDir reads directory at name.
func (FileSystem) ReadFile ¶
func (fsys FileSystem) ReadFile(name string) ([]byte, error)
ReadFile reads contents of name.
type HashFS ¶
type HashFS struct { // OS wraps of OS I/O operations in the HashFS. OS *osfs.OSFS // contains filtered or unexported fields }
HashFS is a filesystem for digest hash.
func (*HashFS) Availables ¶
Availables returns valid inputs (i.e. exist in hashfs).
func (*HashFS) Copy ¶
func (hfs *HashFS) Copy(ctx context.Context, root, src, dst string, mtime time.Time, cmdhash []byte) error
Copy copies a file from root/src to root/dst with mtime and cmdhash. if src is dir, returns error.
func (*HashFS) DataSource ¶
func (hfs *HashFS) DataSource() DataSource
DataSource returns DataSource of the HashFS.
func (*HashFS) Entries ¶
func (hfs *HashFS) Entries(ctx context.Context, root string, inputs []string) ([]merkletree.Entry, error)
Entries gets merkletree entries for inputs at root. it won't return entries symlink escaped from root.
func (*HashFS) FileSystem ¶
func (hfs *HashFS) FileSystem(ctx context.Context, dir string) FileSystem
FileSystem returns FileSystem interface at dir.
func (*HashFS) ForgetMissings ¶
ForgetMissings forgets cached entry for input under root if it doesn't exist on local disk, and returns valid inputs. It is currently used for deps=msvc only to workaround clang-cl issue. https://github.com/llvm/llvm-project/issues/58726
func (*HashFS) ForgetMissingsInDir ¶
ForgetMissingsInDir forgets cached entry under root/dir if it isn't generated files/dirs by any steps and doesn't exist on local disk. It is used for a step that removes files under a dir. b/350662100
func (*HashFS) NeedFlush ¶
NeedFlush returns whether the fname need to be flushed based on OutputLocal option.
func (*HashFS) Notify ¶
func (hfs *HashFS) Notify(f NotifyFunc)
Notify causes the hashfs to relay filesystem motification to f.
func (*HashFS) PreviouslyGeneratedFiles ¶
PreviouslyGeneratedFiles returns a list of generated files (i.e. has cmdhash) in the previous builds. It will reset internal data, so next call will return nil
func (*HashFS) RemoveAll ¶
RemoveAll removes all files under root/name. Also removes from the disk at the same time.
func (*HashFS) RetrieveUpdateEntries ¶
func (hfs *HashFS) RetrieveUpdateEntries(ctx context.Context, root string, fnames []string) []UpdateEntry
RetrieveUpdateEntries gets UpdateEntry for fnames at root.
func (*HashFS) RetrieveUpdateEntriesFromLocal ¶
func (hfs *HashFS) RetrieveUpdateEntriesFromLocal(ctx context.Context, root string, fnames []string) []UpdateEntry
RetrieveUpdateEntriesFromLocal gets UpdateEntry for fnames at root from local disk. It is intended to be used for local execution outputs in cmd.RecordOutputsFromLocal. It won't wait for digest calculation for entries, so UpdateEntry's Entry will be nil. It will forget recorded enties when err (doesn't exist or so).
func (*HashFS) SetExecutables ¶
SetExecutables sets a map of full paths for files to be considered as executable, even if it is not executable on local disk.
func (*HashFS) Symlink ¶
func (hfs *HashFS) Symlink(ctx context.Context, root, target, linkpath string, mtime time.Time, cmdhash []byte) error
Symlink creates a symlink to target at root/linkpath with mtime and cmdhash.
func (*HashFS) TaintedFiles ¶
TaintedFiles returns a list of manually modified generated files.
type IgnoreFunc ¶
IgnoreFunc returns true if given fname should be ignored in hashfs.
type NotifyFunc ¶
NotifyFunc is the type of the function to notify the filesystem changes.
type Option ¶
type Option struct { StateFile string // filename that HashFS saves its state to GzipUsesBgzf bool // use bgzf for gzip compression CompressZstd bool // compress fs state using zstd instead of gzip CompressLevel int // compression level (0 = uncompressed, 1 = fastest, 10 = best) CompressThreads int // number of threads to use for data compression KeepTainted bool // keep manually modified generated file OSFSOption osfs.Option FSMonitor FSMonitor DataSource DataSource OutputLocal OutputLocalFunc Ignore IgnoreFunc CogFS *cogutil.Client ArtFS *artfsutil.Client }
Option is an option for HashFS.
func (*Option) RegisterFlags ¶
RegisterFlags registers flags for the option.
type OutputLocalFunc ¶
OutputLocalFunc returns true if given fname needs to be on local disk.
type UpdateEntry ¶
type UpdateEntry struct { Name string // if Entry is nil, use local disk (from RetrieveUpdateEntriesFromLocal), so need to calculate digest from file. // If Entry is not nil, use digest in Entry, rather than calculating digest from file. Entry *merkletree.Entry Mode fs.FileMode ModTime time.Time CmdHash []byte Action digest.Digest UpdatedTime time.Time IsChanged bool // IsLocal=true uses Entry, but assumes file exists on local, // to avoid unnecessary flush operation. IsLocal bool }
UpdateEntry is an entry for Update.
func (UpdateEntry) String ¶
func (e UpdateEntry) String() string