Documentation
¶
Overview ¶
Package files serves the filesystem and changes RPCs (DBX-43): listing, stat, reads with a content hash, compare-and-swap writes, recursive watches, and git changes grouped by checkout.
Index ¶
- Constants
- func HashFile(path string) (string, error)
- type ChangesCache
- type Checkouts
- type Service
- func (s *Service) BranchDiffStat(ctx context.Context, req *devboxv1.BranchDiffStatRequest) (*devboxv1.BranchDiffStatResponse, error)
- func (s *Service) Changes(ctx context.Context, req *devboxv1.GetChangesRequest) (*devboxv1.GetChangesResponse, error)
- func (s *Service) List(ctx context.Context, req *devboxv1.ListFilesRequest) (*devboxv1.ListFilesResponse, error)
- func (s *Service) Read(ctx context.Context, req *devboxv1.ReadFileRequest) (*devboxv1.ReadFileResponse, error)
- func (s *Service) Resolve(p string) (string, error)
- func (s *Service) Stat(ctx context.Context, p string) (*devboxv1.FileEntry, error)
- func (s *Service) Watch(ctx context.Context, req *devboxv1.WatchFilesRequest, ...) error
- func (s *Service) Write(ctx context.Context, req *devboxv1.WriteFileRequest) (*devboxv1.WriteFileResponse, error)
Constants ¶
const ( // DefaultReadLimit is ReadFile's default byte limit. DefaultReadLimit = 1 << 20 // MaxReadLimit caps ReadFile. MaxReadLimit = 16 << 20 // MaxListEntries caps ListFiles. MaxListEntries = 5000 // MaxWriteBytes caps WriteFile. MaxWriteBytes = 32 << 20 )
const (
// MaxCacheWatches caps the directories the changes cache watches across all checkouts.
MaxCacheWatches = 65536
)
const MaxWatchedDirs = 8192
MaxWatchedDirs caps a recursive watch.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ChangesCache ¶
type ChangesCache struct {
// contains filtered or unexported fields
}
ChangesCache keeps each checkout's changes current in the background: a watch on the work tree and git directory marks a checkout stale as it changes, and a debounced recompute refreshes what was last asked for, so GetChanges is usually served without running git.
func NewChangesCache ¶
func NewChangesCache(log *slog.Logger) *ChangesCache
NewChangesCache returns a cache; Run starts its watch.
func (*ChangesCache) Get ¶
func (c *ChangesCache) Get(ctx context.Context, key changesKey) (*devboxv1.RepositoryChanges, error)
Get returns a checkout's changes, from the cache when nothing has changed since they were computed.
func (*ChangesCache) Invalidate ¶
func (c *ChangesCache) Invalidate(repos ...string)
Invalidate marks checkouts stale, for changes the watch can't see.
func (*ChangesCache) Run ¶
func (c *ChangesCache) Run(ctx context.Context)
Run watches registered checkouts and refreshes stale ones until ctx ends.
type Checkouts ¶
type Checkouts interface {
// Checkouts returns the main checkouts' absolute paths.
Checkouts() []string
// ThreadWorktrees returns a thread's worktree paths.
ThreadWorktrees(threadID string) []string
}
Checkouts lists the checkouts under the home directory and, for a thread, its worktrees.
type Service ¶
type Service struct {
Home string
Checkouts Checkouts
// ChangesCache, when set, serves GetChanges from checkouts' background-maintained changes.
ChangesCache *ChangesCache
// contains filtered or unexported fields
}
Service implements the filesystem RPCs.
func (*Service) BranchDiffStat ¶
func (s *Service) BranchDiffStat(ctx context.Context, req *devboxv1.BranchDiffStatRequest) (*devboxv1.BranchDiffStatResponse, error)
BranchDiffStat sizes a pull request's branch in the checkout req.Repository names, matched by name, path or remote.
func (*Service) Changes ¶
func (s *Service) Changes(ctx context.Context, req *devboxv1.GetChangesRequest) (*devboxv1.GetChangesResponse, error)
Changes implements GetChanges: one entry per checkout (or per thread worktree).
func (*Service) List ¶
func (s *Service) List(ctx context.Context, req *devboxv1.ListFilesRequest) (*devboxv1.ListFilesResponse, error)
List implements ListFiles.
func (*Service) Read ¶
func (s *Service) Read(ctx context.Context, req *devboxv1.ReadFileRequest) (*devboxv1.ReadFileResponse, error)
Read implements ReadFile.
func (*Service) Resolve ¶
Resolve maps a request path to an absolute path inside the home directory.
func (*Service) Watch ¶
func (s *Service) Watch(ctx context.Context, req *devboxv1.WatchFilesRequest, send func(*devboxv1.FileEvent) error) error
Watch streams changes under a path until ctx ends or send fails.
func (*Service) Write ¶
func (s *Service) Write(ctx context.Context, req *devboxv1.WriteFileRequest) (*devboxv1.WriteFileResponse, error)
Write implements WriteFile with compare-and-swap on the current content's sha256.