content

package
v0.1.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package content owns the public directory scanner, manifest and safe file access. Public content is untrusted input and is read through os.Root.

Index

Constants

View Source
const (
	CacheTTL             = 30 * time.Second
	FirstScanWait        = 3 * time.Second
	MaxManifestPage      = 64 << 10
	MaxManifestLimit     = 200
	DefaultManifestLimit = 100
)

Variables

View Source
var ErrInvalidPublicPath = errors.New("content: invalid public path")

ErrInvalidPublicPath reports a path that is not a safe relative public path.

View Source
var ErrScanInProgress = errors.New("content: initial scan in progress")

Functions

func EnsureLayout

func EnsureLayout(dataDir string) error

func ManifestDigest

func ManifestDigest(snap *Snapshot) string

ManifestDigest computes the stable publication digest over version, peer_id and path-sorted entries. GeneratedAt and mtimes are intentionally excluded.

func NewPublishID

func NewPublishID(now time.Time) string

NewPublishID returns a safe staging directory name.

Types

type Entry

type Entry struct {
	Path           string `json:"path"`
	Size           int64  `json:"size"`
	ModifiedUnixMS int64  `json:"modified_unix_ms"`
	SHA256         string `json:"sha256"`
}

type Limits

type Limits struct {
	MaxFileBytes    int64
	MaxPostsBytes   int64
	MaxProfileBytes int64
}

type Manifest

type Manifest struct {
	Version           int     `json:"version"`
	PeerID            string  `json:"peer_id"`
	GeneratedAtUnixMS int64   `json:"generated_at_unix_ms"`
	Entries           []Entry `json:"entries"`
	Total             int     `json:"total"`
}

type Skip

type Skip struct {
	Path   string `json:"path"`
	Reason string `json:"reason"`
}

type Snapshot

type Snapshot struct {
	PeerID      string
	GeneratedAt time.Time
	Entries     []Entry
	Total       int
	Warnings    []string
	Skipped     []Skip
	// FriendsSyncedAt is the mtime of friends.json, i.e. when its contents last
	// changed. WriteFriends skips unchanged writes, so this is not the last time
	// friends were synced.
	FriendsSyncedAt time.Time
}

func (*Snapshot) Page

func (snap *Snapshot) Page(offset, limit int) Manifest

Page returns a deterministic, size-bounded manifest page. The total is the full manifest count, not the page count.

type Store

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

func New

func New(dataDir, peerID string, limits Limits) (*Store, error)

func (*Store) Close

func (s *Store) Close() error

func (*Store) File

func (s *Store) File(rel string) (*os.File, fs.FileInfo, error)

func (*Store) Invalidate

func (s *Store) Invalidate()

func (*Store) InvalidateLocked

func (s *Store) InvalidateLocked()

InvalidateLocked is Invalidate for a caller already holding LockPublish.

func (*Store) LockPublish

func (s *Store) LockPublish()

LockPublish acquires the single public-write/scan lock. The publication coordinator holds it for the entire version-check/write/scan/record critical section. Callers must use the *Locked methods while holding it.

func (*Store) PublicFileExistsLocked

func (s *Store) PublicFileExistsLocked(rel string) (bool, error)

PublicFileExistsLocked reports a regular, non-symlink public file.

func (*Store) PublicFileSHA256Locked

func (s *Store) PublicFileSHA256Locked(rel string, maxBytes int64) (string, int64, error)

PublicFileSHA256Locked hashes one public file without exposing its bytes.

func (*Store) ReadPublicFileLocked

func (s *Store) ReadPublicFileLocked(rel string, maxBytes int64) ([]byte, error)

ReadPublicFileLocked reads one regular public file, rejecting symlinks.

func (*Store) Refresh

func (s *Store) Refresh(ctx context.Context) (*Snapshot, error)

Refresh forces a new scan and waits for it. /published uses this so a user never sees a cached list after adding a file.

func (*Store) RefreshLocked

func (s *Store) RefreshLocked(ctx context.Context) (*Snapshot, error)

RefreshLocked is Refresh for a caller already holding LockPublish.

func (*Store) RemovePublicFile

func (s *Store) RemovePublicFile(rel string) error

RemovePublicFile removes one public file. A missing file is a no-op; a symlink is refused.

func (*Store) RemovePublicFileLocked

func (s *Store) RemovePublicFileLocked(rel string) error

RemovePublicFileLocked is RemovePublicFile for a caller holding LockPublish.

func (*Store) Snapshot

func (s *Store) Snapshot(ctx context.Context) (*Snapshot, error)

Snapshot returns the cached manifest inside the TTL. After the TTL it waits for one singleflight scan, bounded by FirstScanWait and ctx. If the bound is reached it serves the previous snapshot rather than an arbitrarily old one.

func (*Store) SnapshotLocked

func (s *Store) SnapshotLocked(ctx context.Context) (*Snapshot, error)

SnapshotLocked is Snapshot for a caller already holding LockPublish.

func (*Store) UnlockPublish

func (s *Store) UnlockPublish()

UnlockPublish releases the public-write/scan lock.

func (*Store) Warnings

func (s *Store) Warnings() []string

func (*Store) WriteFriends

func (s *Store) WriteFriends(data []byte) (bool, error)

WriteFriends atomically replaces friends.json only when bytes differ. It is the only writer for the generated file.

func (*Store) WritePublicFile

func (s *Store) WritePublicFile(rel string, data []byte) (Entry, error)

WritePublicFile atomically writes one public file. It is the only public writer. A temporary file in the same directory is synced, chmodded 0644 and renamed; a failure never exposes a partial file.

func (*Store) WritePublicFileLocked

func (s *Store) WritePublicFileLocked(rel string, data []byte) (Entry, error)

WritePublicFileLocked is WritePublicFile for a caller holding LockPublish.

Jump to

Keyboard shortcuts

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