Documentation
¶
Index ¶
- Constants
- func OpenRelative(ctx context.Context, root, relative string) (*os.File, error)
- func ReadRelative(ctx context.Context, root, relative string, limit int64) ([]byte, error)
- func ValidateManifest(manifest Manifest, limits Limits) error
- func VerifyFile(ctx context.Context, path string, item Item, limits Limits) error
- type Error
- type Hooks
- type Item
- type Library
- func (l *Library) CreateRelativeTempDirectory(relative, pattern string) (string, error)
- func (l *Library) EnsureRelativeDirectory(relative string) error
- func (l *Library) EnsureRelativeDirectoryNoState(relative string) error
- func (l *Library) ItemPath(item Item) (string, error)
- func (l *Library) OpenVerified(ctx context.Context, item Item) (*os.File, string, error)
- func (l *Library) ReadItem(ctx context.Context, id string) (Item, string, error)
- func (l *Library) ReadManifest(ctx context.Context) (Manifest, error)
- func (l *Library) ReadManifestRequired(ctx context.Context) (Manifest, error)
- func (l *Library) RemoveRelative(ctx context.Context, relative string) (bool, error)
- func (l *Library) RemoveRelativeDirectory(ctx context.Context, relative string) error
- func (l *Library) UpdateManifest(ctx context.Context, fn func(Manifest) (Manifest, error)) error
- func (l *Library) Validate(ctx context.Context, manifest Manifest) error
- func (l *Library) VerifyItem(ctx context.Context, item Item) error
- func (l *Library) WithReadLock(ctx context.Context, fn func(Manifest) error) error
- func (l *Library) WithWriteLock(ctx context.Context, fn func(Manifest) error) error
- func (l *Library) WriteManifest(ctx context.Context, manifest Manifest) error
- func (l *Library) WriteManifestLocked(ctx context.Context, manifest Manifest) error
- func (l *Library) WriteRelativeAtomic(ctx context.Context, relative string, data []byte) error
- func (l *Library) WriteRelativeAtomicFrom(ctx context.Context, relative string, source io.Reader, limit int64, ...) error
- type Limits
- type Manifest
Constants ¶
const ( ManifestName = "manifest.json" EmoticonsDirectory = "emoticons" MaxManifestBytes = 8 << 20 MaxImageBytes = 32 << 20 MaxManifestItems = 20_000 MaxCaptionBytes = 4 << 10 )
Variables ¶
This section is empty.
Functions ¶
func OpenRelative ¶
OpenRelative opens a file beneath root without following symbolic links in any path component. The caller owns and must close the returned file.
func ReadRelative ¶
ReadRelative reads a bounded file beneath root using the platform's secure relative-open implementation. Callers must pass a relative path and handle the returned error according to their own boundary contract.
func ValidateManifest ¶
ValidateManifest validates metadata without reading the referenced files.
Types ¶
type Error ¶
type Error struct {
Kind string
Subtype string
Message string
Hint string
Retryable bool
Committed bool
Err error
}
Error is a stable, machine-readable error returned by the library layer. Callers should branch on Kind and Subtype rather than Message.
type Hooks ¶
type Hooks struct {
BeforeRename func(string) error
AfterRename func(string) error
SyncDirectory func(string) error
BeforeManifest func() error
}
Hooks make filesystem failure boundaries testable without changing production behavior.
type Item ¶
type Item struct {
MD5 string `json:"md5"`
SHA256 string `json:"sha256"`
Filename string `json:"filename"`
Format string `json:"format"`
Size int64 `json:"size"`
Caption string `json:"caption,omitempty"`
}
Item is one standard v1 manifest entry. Filename is relative to the library root.
func ReadImage ¶
ReadImage reads and validates one local original image. The returned item uses the standard emoticons/<md5>.<format> filename and has an empty caption. The returned bytes are a snapshot of the opened file and can be staged for a later manifest update even when the source path is subsequently moved.
type Library ¶
Library confines all paths used by this package to Root.
func (*Library) CreateRelativeTempDirectory ¶
CreateRelativeTempDirectory creates a private temporary directory beneath an existing directory inside the library root. Unix implementations create it through an anchored directory descriptor to avoid path-swap races.
func (*Library) EnsureRelativeDirectory ¶
EnsureRelativeDirectory creates a directory beneath the library root while rejecting symlinked path components. It is used by higher-level operations for their private staging and state directories before they publish files.
func (*Library) EnsureRelativeDirectoryNoState ¶
EnsureRelativeDirectoryNoState creates a directory beneath an already existing library root without creating the library's private .sticker state directory. It is intended for temporary material roots that must contain only standard library files.
func (*Library) ItemPath ¶
ItemPath resolves a manifest item's standard filename beneath the library root. It checks path components but does not read the image; use ReadItem when content integrity must be established before returning a usable path.
func (*Library) OpenVerified ¶
OpenVerified opens one standard item only after all declared integrity checks have passed. The caller owns the returned file and must close it. The file offset is reset to the beginning before returning.
func (*Library) ReadItem ¶
ReadItem locates and verifies one item, returning its absolute path only after all declared integrity checks have passed. It performs no image reads for other items.
func (*Library) ReadManifest ¶
ReadManifest reads the root manifest. A missing manifest is an empty personal library; an existing malformed manifest is always an integrity error.
func (*Library) ReadManifestRequired ¶
ReadManifestRequired reads a standard manifest that must exist. It is used for imports and other operations where a missing source is not an empty collection.
func (*Library) RemoveRelative ¶
RemoveRelative removes one file beneath the library root without following symbolic links in path components. The operation is idempotent: a missing root, parent, or target returns (false, nil). A present target is removed in one filesystem operation and returns (true, nil).
func (*Library) RemoveRelativeDirectory ¶
RemoveRelativeDirectory removes a directory tree beneath the library root without following symbolic links. A missing target is already clean. Callers should use it for private temporary directories, never for the library root itself.
func (*Library) UpdateManifest ¶
UpdateManifest executes fn under the cross-process write lock and atomically publishes one manifest.
func (*Library) Validate ¶
Validate checks every referenced file and its declared format, size, MD5, and SHA-256.
func (*Library) VerifyItem ¶
VerifyItem validates one manifest item using the library root's secure relative-open implementation.
func (*Library) WithReadLock ¶
WithReadLock runs fn while holding the library's shared lock when one is present. The callback receives the manifest snapshot read under that lock, which lets read operations open referenced files without racing a manifest writer between the snapshot and the file handles.
func (*Library) WithWriteLock ¶
WithWriteLock runs fn while holding the library's cross-process exclusive lock. The callback receives the latest personal manifest snapshot read under that lock, so callers can validate concurrent changes before publishing related private state.
func (*Library) WriteManifest ¶
WriteManifest validates metadata and atomically replaces the root manifest.
func (*Library) WriteManifestLocked ¶
WriteManifestLocked validates and atomically publishes a manifest while the caller holds the lock acquired by WithWriteLock. It is intended for updates that publish the manifest together with related private metadata under one lock; callers must not invoke it outside that callback.
func (*Library) WriteRelativeAtomic ¶
WriteRelativeAtomic publishes data at a path beneath the library root. Parent directories must already exist. The platform implementation anchors the write to the library root so a concurrent symlink swap cannot redirect the temporary file or rename outside the library.
func (*Library) WriteRelativeAtomicFrom ¶
func (l *Library) WriteRelativeAtomicFrom(ctx context.Context, relative string, source io.Reader, limit int64, validate func(int64) error) error
WriteRelativeAtomicFrom streams bounded data into a root-anchored temporary file, validates it before rename, and atomically publishes it below the library root. The validator receives the number of bytes copied and runs before the destination becomes visible.
type Limits ¶
Limits bounds input accepted by the library. Zero fields use the defaults.
func DefaultLimits ¶
func DefaultLimits() Limits
Source Files
¶
- atomic.go
- atomic_relative.go
- atomic_relative_reader_unix.go
- atomic_relative_unix.go
- atomic_unix.go
- ensure_relative_unix.go
- errors.go
- fs.go
- image.go
- lock_unix.go
- manifest.go
- open_relative_unix.go
- open_source.go
- open_source_unix.go
- open_unix.go
- remove_directory.go
- remove_directory_unix.go
- remove_relative.go
- remove_relative_unix.go
- rename_unix.go
- signature.go
- temp_relative_unix.go