Documentation
¶
Overview ¶
Package dotcog manages the .cog/ project directory.
The .cog/ directory is the local state directory for a Cog project. It stores build staging artifacts, weight caches, mount scratch space, and a project-wide advisory lock. This package provides a structured way to create, access, lock, and clean up the directory.
Typical usage:
d, err := dotcog.Open(projectRoot)
if err != nil { ... }
defer d.Close()
buildDir := d.Path("build") // .cog/build/, created on demand
For operations that need exclusive access:
release, err := d.Lock(ctx)
if err != nil { ... }
defer release()
Index ¶
- Constants
- type Dir
- func (d *Dir) Close() error
- func (d *Dir) FilePath(name string) (string, error)
- func (d *Dir) Lock(ctx context.Context) (release func(), err error)
- func (d *Dir) Path(name string) (string, error)
- func (d *Dir) ProjectDir() string
- func (d *Dir) Root() string
- func (d *Dir) TempPath(name string) (string, error)
Constants ¶
const Name = ".cog"
Name is the directory name inside a project root.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dir ¶
type Dir struct {
// contains filtered or unexported fields
}
Dir is a handle to a project's .cog/ directory.
It provides path accessors, an advisory lock, and cleanup registration. Always create via Open or OpenTemp; never construct directly.
func OpenTemp ¶
OpenTemp creates a Dir in a new temporary directory. The directory and all contents are removed on Close.
func (*Dir) Close ¶
Close runs all registered cleanup functions in reverse order. Close is nil-safe and idempotent: calling Close on a nil *Dir or calling it multiple times is a no-op.
func (*Dir) FilePath ¶
FilePath returns the absolute path to a file inside .cog/, ensuring the parent directory exists. Unlike Path, it does not create the leaf as a directory.
func (*Dir) Lock ¶
Lock acquires an exclusive project-wide advisory lock, blocking until the lock is available or ctx is canceled.
Any mutating operation on the .cog/ directory (builds, weights imports) should hold this lock so concurrent cog invocations against the same project don't race.
Returns a release function that must be called (typically via defer) to release the lock. The release function is safe to call even if Lock returned an error (it is a no-op in that case).
func (*Dir) Path ¶
Path returns the absolute path to a subdirectory of .cog/, creating it if it doesn't exist. For example, d.Path("build") returns ".cog/build/".
func (*Dir) ProjectDir ¶
ProjectDir returns the absolute path to the parent project directory.