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
- Variables
- func EnsureLayout(dataDir string) error
- func ManifestDigest(snap *Snapshot) string
- func NewPublishID(now time.Time) string
- type Entry
- type Limits
- type Manifest
- type Skip
- type Snapshot
- type Store
- func (s *Store) Close() error
- func (s *Store) File(rel string) (*os.File, fs.FileInfo, error)
- func (s *Store) Invalidate()
- func (s *Store) InvalidateLocked()
- func (s *Store) LockPublish()
- func (s *Store) PublicFileExistsLocked(rel string) (bool, error)
- func (s *Store) PublicFileSHA256Locked(rel string, maxBytes int64) (string, int64, error)
- func (s *Store) ReadPublicFileLocked(rel string, maxBytes int64) ([]byte, error)
- func (s *Store) Refresh(ctx context.Context) (*Snapshot, error)
- func (s *Store) RefreshLocked(ctx context.Context) (*Snapshot, error)
- func (s *Store) RemovePublicFile(rel string) error
- func (s *Store) RemovePublicFileLocked(rel string) error
- func (s *Store) Snapshot(ctx context.Context) (*Snapshot, error)
- func (s *Store) SnapshotLocked(ctx context.Context) (*Snapshot, error)
- func (s *Store) UnlockPublish()
- func (s *Store) Warnings() []string
- func (s *Store) WriteFriends(data []byte) (bool, error)
- func (s *Store) WritePublicFile(rel string, data []byte) (Entry, error)
- func (s *Store) WritePublicFileLocked(rel string, data []byte) (Entry, error)
Constants ¶
const ( CacheTTL = 30 * time.Second FirstScanWait = 3 * time.Second MaxManifestPage = 64 << 10 MaxManifestLimit = 200 DefaultManifestLimit = 100 )
Variables ¶
var ErrInvalidPublicPath = errors.New("content: invalid public path")
ErrInvalidPublicPath reports a path that is not a safe relative public path.
var ErrScanInProgress = errors.New("content: initial scan in progress")
Functions ¶
func EnsureLayout ¶
func ManifestDigest ¶
ManifestDigest computes the stable publication digest over version, peer_id and path-sorted entries. GeneratedAt and mtimes are intentionally excluded.
func NewPublishID ¶
NewPublishID returns a safe staging directory name.
Types ¶
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
}
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
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 ¶
PublicFileExistsLocked reports a regular, non-symlink public file.
func (*Store) PublicFileSHA256Locked ¶
PublicFileSHA256Locked hashes one public file without exposing its bytes.
func (*Store) ReadPublicFileLocked ¶
ReadPublicFileLocked reads one regular public file, rejecting symlinks.
func (*Store) Refresh ¶
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 ¶
RefreshLocked is Refresh for a caller already holding LockPublish.
func (*Store) RemovePublicFile ¶
RemovePublicFile removes one public file. A missing file is a no-op; a symlink is refused.
func (*Store) RemovePublicFileLocked ¶
RemovePublicFileLocked is RemovePublicFile for a caller holding LockPublish.
func (*Store) Snapshot ¶
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 ¶
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) WriteFriends ¶
WriteFriends atomically replaces friends.json only when bytes differ. It is the only writer for the generated file.
func (*Store) WritePublicFile ¶
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.