Help us shape the future of Go! Take the 2026 Go Developer Survey

productfiles

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

README

Private files for host applications

productfiles exposes the native private-file operations that Starmap uses. Starport can use these operations without copying filesystem access code. The package does no catalog acquisition and starts no background work.

The host selects its absolute paths through productpaths or explicit settings. NewDirectory creates missing private directories and validates existing access. ExistingDirectory validates an existing directory without creating paths. Neither operation repairs existing permissions. Child checks or creates a private child directory. CreateChild requires a new child and refuses an existing path.

directory, err := productfiles.NewDirectory(configDirectory)
if err != nil {
    return err
}
// A nil previous value requires an absent file.
return directory.CompareAndPublish(ctx, "config.env", nil, configBytes)

Each directory binding retains its original filesystem identity. The Identity method exposes the native volume and directory identity for host recovery records. The FileIdentity function reads the native identity of a caller-owned open file or directory. It does not establish an access policy for that handle.

An operation refuses a replaced directory, an unsafe ancestor, or invalid native access. Linux and macOS use ownership, modes, and the applicable ACL checks. Windows uses the native owner and DACL checks. New files have private access from creation.

ReadFile requires a byte limit and reads one regular private file. CopyFile streams one regular private file into a caller-owned writer under an explicit byte limit. It checks native access and identity before and after the copy and supports context cancellation. The caller must discard partial output after an error, fence writers, and verify content hashes when required. Streaming does not create a snapshot or approve recovery.

CompareAndPublish requires matching previous bytes before it replaces a file. A nil previous value means absence. An empty, non-nil value means an empty file. CompareAndRemove also requires matching bytes and allows retries after removal.

Record publication reserves .record-publications for its writer lock and recovery receipts. Writes and recovery preserve unknown entries and changed files. RecoverPublications recovers abandoned record writes under the same lock. It does not recover an application transaction across config, data, or state roots. Record writes have a 64 MiB bound.

An errors.PublicationError means the change became visible, but durability remains unconfirmed. The caller must retain the intended bytes and resolve that result before a different write. It must not assume that the old file remains selected.

Open returns a checked os.Root that the caller must close. Raw operations on that root follow the standard library contract. They do not inherit the record publication or recovery contract.

PublishDirectory moves a direct child between open roots on the same filesystem. It refuses any existing destination, including an empty directory. The caller must sync staged contents before the move and both parent directories afterward. The caller also owns recovery if its operation spans multiple roots. SyncDirectory reports native synchronization errors without claiming hardware power-loss qualification.

CheckNoPendingPublications inspects existing publication journals without creating files or recovering writes. It uses the existing native writer lock and refuses pending journals. PublicationDirectoryName identifies metadata owned by this package. Hosts must preserve that metadata and fence writers before copying inspected state.

InspectRetainedPublications validates captured publication evidence without filesystem operations. The caller supplies verified file sizes and digests, a bounded reader, and a destination owner check. The result selects journals and matching staging files for inactive retention. The caller must preserve those bytes and validate all remaining destination records separately. Historical native identities cannot authorize cleanup on a restore host. This check never promotes staged bytes or approves application permission.

Documentation

Overview

Package productfiles supplies native private-file operations for Starmap hosts. The host owns path selection, record schemas, and transactions across directories.

Index

Constants

View Source
const PublicationDirectoryName = privatefiles.PublicationDirectoryName

PublicationDirectoryName identifies metadata owned by private-record publication. Callers must preserve this directory and use its owner APIs to inspect or recover it.

Variables

This section is empty.

Functions

func FileIdentity

func FileIdentity(file *os.File) (string, error)

FileIdentity returns the native volume and file identity for an open file or directory. It does not establish ownership or access policy. The caller owns the handle and its validation.

func InspectRetainedPublications

func InspectRetainedPublications(ctx context.Context, files map[string]RetainedFile, read RetainedRecordReader, accepts func(parent, destination, prefix string) bool) ([]string, error)

InspectRetainedPublications selects matching journals and staging files for inactive retention. The owner callback approves destination names and prefixes within each parent directory. The caller preserves selected files and validates the remaining tree before publication. This check never promotes staged bytes or approves current permission.

func PublishDirectory

func PublishDirectory(sourceRoot *os.Root, source string, targetRoot *os.Root, target string) error

PublishDirectory moves one direct child between open directories without replacing a destination. The roots must refer to the same filesystem. The move uses their open handles. Callers must sync the source contents before publication and both parents afterward. Success reports namespace publication. It does not establish durability.

func SyncDirectory

func SyncDirectory(root *os.Root) error

SyncDirectory flushes an open directory through the native filesystem API. Filesystem and hardware qualification remain the host's responsibility.

func ValidateAncestors

func ValidateAncestors(path string) error

ValidateAncestors checks an existing path route without creating files or directories. The final entry requires its own type and access checks.

Types

type Directory

type Directory struct {
	// contains filtered or unexported fields
}

Directory binds a private directory to its filesystem identity. Operations check native ownership and access without changing existing permissions. The zero value is invalid. No directory handle remains open between operations.

func CreateDirectory

func CreateDirectory(path string) (*Directory, error)

CreateDirectory exclusively creates one private directory beneath an existing trusted parent. The path must be clean and absolute. Existing targets retain their contents and permissions.

func ExistingDirectory

func ExistingDirectory(path string) (*Directory, error)

ExistingDirectory checks an existing private directory without creating paths.

func NewDirectory

func NewDirectory(path string) (*Directory, error)

NewDirectory creates missing private directories or checks an existing directory. The path must be absolute. Existing ancestors must pass the native access policy.

func (*Directory) CheckNoPendingPublications

func (d *Directory) CheckNoPendingPublications(ctx context.Context) error

CheckNoPendingPublications refuses retained publication journals without changing files. It checks an existing writer lock but creates no lock or metadata directory. The caller must fence writers before copying or publishing inspected state.

func (*Directory) Child

func (d *Directory) Child(name string) (*Directory, error)

Child checks or privately creates one direct child directory.

func (*Directory) CompareAndPublish

func (d *Directory) CompareAndPublish(ctx context.Context, name string, previous, data []byte) error

CompareAndPublish atomically publishes data if the current bytes equal previous. A nil previous value requires absence. A non-nil empty value requires an empty file. Publication uses a checked writer lock and durable recovery receipts. A PublicationError reports visible bytes whose durability remains unconfirmed.

func (*Directory) CompareAndRemove

func (d *Directory) CompareAndRemove(ctx context.Context, name string, previous []byte) (bool, error)

CompareAndRemove removes a private record only when its bytes equal previous. Missing records permit an idempotent retry. The previous value must not be nil. A true result reports visible removal, including an unconfirmed durability error.

func (*Directory) CompletePublication

func (d *Directory) CompletePublication(ctx context.Context, name string, previous, data []byte, check func(context.Context) error) error

CompletePublication finishes an exact record after the host checks its original decision and native receipt. It refuses foreign journals, changed native identities, and incomplete staging evidence. The callback runs under the writer lock. It must not publish or recover records in this directory. An already published exact value permits a retry. This operation grants no host transaction authority.

func (*Directory) CopyFile

func (d *Directory) CopyFile(ctx context.Context, name string, output io.Writer, maxBytes int64) (int64, error)

CopyFile streams one private regular child file into a caller-owned writer. It checks native access and identity before and after the bounded copy. A failure can follow partial output. The caller must discard that output. Writers must remain fenced. Content hashes remain the caller's responsibility.

func (*Directory) CreateChild

func (d *Directory) CreateChild(name string) (*Directory, error)

CreateChild exclusively creates one private direct child directory. An existing child produces an existence error without changing that child.

func (*Directory) ExistingChild

func (d *Directory) ExistingChild(name string) (*Directory, error)

ExistingChild checks one existing direct child without creating paths.

func (*Directory) Identity

func (d *Directory) Identity() (identity string, resultErr error)

Identity returns the native volume and file identity of the bound directory. Hosts can retain this value in a private recovery record to detect replacement.

func (*Directory) InspectPublication

func (d *Directory) InspectPublication(ctx context.Context, name string, previous, data []byte) ([]string, error)

InspectPublication checks an exact pending write without cleanup or publication. Stage names let the host read its original decision while those checked records remain pending. Names grant no completion or transaction authority. CompletePublication rechecks every native receipt.

func (*Directory) Open

func (d *Directory) Open() (*os.Root, error)

Open returns a confined root after checking the original directory identity and access. The caller must close the root. Raw root operations retain their standard library contract.

func (*Directory) ReadFile

func (d *Directory) ReadFile(name string, maxBytes int64) ([]byte, error)

ReadFile reads one private regular file within a caller-selected byte limit. It refuses links, changed identities, and invalid native access.

func (*Directory) RecoverPublications

func (d *Directory) RecoverPublications(ctx context.Context) error

RecoverPublications recovers abandoned private-record writes under the checked writer lock. It preserves unknown entries and entries whose identity, bytes, or access changed. This operation does not recover a host transaction across directories.

type RetainedFile

type RetainedFile = privatefiles.RetainedFile

RetainedFile identifies bytes in a verified backup.

type RetainedRecordReader

type RetainedRecordReader = privatefiles.RetainedRecordReader

RetainedRecordReader reads bounded bytes from a verified backup.

Jump to

Keyboard shortcuts

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