files

package
v0.6.76 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0, Apache-2.0, MIT Imports: 27 Imported by: 0

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

View Source
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
)
View Source
const (
	// MaxCacheWatches caps the directories the changes cache watches across all checkouts.
	MaxCacheWatches = 65536
)
View Source
const MaxWatchedDirs = 8192

MaxWatchedDirs caps a recursive watch.

Variables

This section is empty.

Functions

func HashFile

func HashFile(path string) (string, error)

HashFile returns the hex sha256 of a file.

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.

func (*ChangesCache) Warm

func (c *ChangesCache) Warm(ctx context.Context, repos []string)

Warm computes the default view (against HEAD, with diffs) of each checkout in the background.

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

BranchDiffStat sizes a pull request's branch in the checkout req.Repository names, matched by name, path or remote.

func (*Service) Changes

Changes implements GetChanges: one entry per checkout (or per thread worktree).

func (*Service) List

List implements ListFiles.

func (*Service) Read

Read implements ReadFile.

func (*Service) Resolve

func (s *Service) Resolve(p string) (string, error)

Resolve maps a request path to an absolute path inside the home directory.

func (*Service) Stat

func (s *Service) Stat(ctx context.Context, p string) (*devboxv1.FileEntry, error)

Stat implements StatFile.

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

Write implements WriteFile with compare-and-swap on the current content's sha256.

Jump to

Keyboard shortcuts

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