dotcog

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

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

View Source
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 Open

func Open(projectDir string) (*Dir, error)

Open returns a Dir rooted at <projectDir>/.cog/, creating it if needed.

func OpenTemp

func OpenTemp() (*Dir, error)

OpenTemp creates a Dir in a new temporary directory. The directory and all contents are removed on Close.

func (*Dir) Close

func (d *Dir) Close() error

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

func (d *Dir) FilePath(name string) (string, error)

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

func (d *Dir) Lock(ctx context.Context) (release func(), err error)

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

func (d *Dir) Path(name string) (string, error)

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

func (d *Dir) ProjectDir() string

ProjectDir returns the absolute path to the parent project directory.

func (*Dir) Root

func (d *Dir) Root() string

Root returns the absolute path to the .cog/ directory.

func (*Dir) TempPath

func (d *Dir) TempPath(name string) (string, error)

TempPath returns the absolute path to a scratch subdirectory of .cog/. Any existing contents are wiped first, and the directory is registered for removal on Close. Use this for directories (like build/) that should start clean and not persist between invocations.

Jump to

Keyboard shortcuts

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