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

filestore

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package filestore provides SDK-internal root-confined text storage for agents.

Store paths are relative to a store root. An empty directory names the root. FileSystemStore creates missing directories and confines operations to its root, rejecting absolute paths and paths that escape the root. Relative symbolic links are followed only when they remain within the root. Read and Delete report missing files with errors wrapping fs.ErrNotExist. ListChildren returns only direct regular files, not directories, symbolic links, or names that cannot be addressed through the store's path normalization.

Contexts are checked before filesystem operations and during enumeration. A filesystem call already in progress cannot be interrupted. Individual store operations are safe for concurrent use; callers must synchronize sequences of operations that need to be performed together.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSystemStore

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

FileSystemStore stores text files beneath a filesystem directory. Use NewFileSystemStore to create a store and FileSystemStore.Close to release its root handle. Relative symbolic links within the root are allowed; listing omits symbolic links.

func NewFileSystemStore

func NewFileSystemStore(rootDirectory string) (*FileSystemStore, error)

NewFileSystemStore opens a store rooted at rootDirectory, creating the directory if needed with permission 0700. New working directories use 0700 and new files use 0600; existing permissions are unchanged.

func (*FileSystemStore) Close

func (s *FileSystemStore) Close() error

Close releases the root directory handle. It is safe to call more than once. Subsequent operations return an error wrapping fs.ErrClosed.

func (*FileSystemStore) CreateDirectory

func (s *FileSystemStore) CreateDirectory(ctx context.Context, directory string) error

CreateDirectory ensures a directory and its parents exist beneath the root.

func (*FileSystemStore) Delete

func (s *FileSystemStore) Delete(ctx context.Context, name string) error

Delete removes a file, or returns an error wrapping fs.ErrNotExist if missing.

func (*FileSystemStore) ListChildren

func (s *FileSystemStore) ListChildren(ctx context.Context, directory string) ([]string, error)

ListChildren returns sorted names of regular files directly under directory. Directories, symbolic links and unaddressable names are omitted. A missing directory is empty.

func (*FileSystemStore) Read

func (s *FileSystemStore) Read(ctx context.Context, name string) (string, error)

Read returns a file's content, or an error wrapping fs.ErrNotExist if missing.

func (*FileSystemStore) Write

func (s *FileSystemStore) Write(ctx context.Context, name, content string) error

Write creates or overwrites a file and creates missing parent directories.

type Store

type Store interface {
	// Write creates or overwrites a file, creating its parent directories.
	Write(ctx context.Context, name, content string) error

	// Read returns a file's content. A missing file returns an error wrapping
	// [fs.ErrNotExist], which is distinct from an existing empty file.
	Read(ctx context.Context, name string) (string, error)

	// Delete removes a file, not a directory. A missing file returns an error
	// wrapping [fs.ErrNotExist].
	Delete(ctx context.Context, name string) error

	// ListChildren returns sorted names of regular files directly under directory.
	// Names are relative to that directory, without path separators. An empty
	// directory selects the root; a missing directory returns an empty list.
	// Names that cannot be addressed through the store's paths are omitted.
	ListChildren(ctx context.Context, directory string) ([]string, error)

	// CreateDirectory ensures a directory and its parents exist.
	// An empty directory selects the root.
	CreateDirectory(ctx context.Context, directory string) error
}

Store stores text files under an implementation-defined root. Paths use forward slashes and must not escape that root. Implementations must be safe for concurrent use and honor context cancellation.

Jump to

Keyboard shortcuts

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