core

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 12 Imported by: 66 modules, 67 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.

README

Mountweave

Composable file management and storage primitives for Go.

Inspired by OpenList, Mountweave is an independently developed library for building file-management backends. It is not a refactor of OpenList or a replacement for its API. Its goal is to provide core functionality as an embeddable dependency; it does not yet cover every OpenList feature or Driver.

The core uses only the Go standard library. It does not load configuration, start listeners, or require a frontend, database, cache or task system. Go 1.24 or newer is required. The package name of the root library is core.

Start with a local mount

package consumer

import (
    "errors"

    core "github.com/nostalume/mountweave"
    "github.com/nostalume/mountweave/local"
)

func NewLocalReader(directory string, authorize core.Authorizer) (*core.Core, error) {
    files, err := core.New(core.Options{Authorize: authorize})
    if err != nil {
        return nil, err
    }
    storage, err := local.New(directory)
    if err != nil {
        return nil, err
    }
    if _, err := files.Install("/files", storage); err != nil {
        return nil, errors.Join(err, storage.Close())
    }
    return files, nil
}

Supply an authorization policy, then call Stat, List, Open and optional mutations with an explicit principal. Close every returned Body and directory scope. Successful Install transfers Driver ownership; a rejected Driver stays with its creator. The application eventually calls Core.Close with its own wait context.

Compose what the application needs

Component Responsibility Reference
core Namespace, authorization, file operations and resource lifetime go doc -all .
local Prepared filesystem root and native file operations go doc -all ./local
control Desired mount definitions and explicit activation/restore go doc -all ./control
task Arbitrary bounded function execution go doc -all ./task
httpapi Optional HTTP delivery with injected identity and policies OpenAPI, go doc -all ./httpapi
Optional Drivers Native clients, credentials and storage representation S3, Alipan, Pool

See Architecture for dependency direction and ownership. Detailed behavioral contracts live with their owning packages in GoDoc.

Current scope

The core supports mounted reads, fixed aliases, synchronous file operations, bounded batches and finite tree operations. Copy belongs to Core; optional Driver capabilities determine which mutations are available. Cross-mount Move is currently unsupported. File effects remain observable alongside errors and cancellation; a tree operation is not a transaction.

Local provides file and directory mutations. S3 currently provides reads and known-length conditional creation; Alipan provides reads and rotating credentials. The optional Pool Driver provides an erasure-coded logical filesystem, member management, repair and durable maintenance. These are independently versioned modules; the core does not import them or their SDK/database dependencies.

Remote adapters have closed protocol tests, not a universal live-service compatibility claim. The host owns credential persistence and chooses budgets. Cancellation requests a stop; it does not forcibly interrupt arbitrary native I/O. There is no product executable, frontend or legacy configuration converter.

Development and availability

Install the core library:

go get github.com/nostalume/mountweave@v0.1.0

Optional Driver modules are published separately from the same repository:

go get github.com/nostalume/mountweave/drivers/s3@v0.1.0
go get github.com/nostalume/mountweave/drivers/alipan@v0.1.0
go get github.com/nostalume/mountweave/drivers/pool@v0.1.0

The Driver modules depend on core v0.1.0. Relative replacements apply only to checkout development; consuming applications do not need local replacements.

See Contributing for commands covering all four modules. The API is under development; no v1 compatibility promise is made yet.

License

Mountweave source, documentation and schemas are available under the MIT License. Third-party dependencies retain their own licenses; see Third-party notices.

Documentation

Overview

Package core provides authorized file management over prepared storage mounts.

Call Stat, List, or Open with an explicit Principal. Close every returned content Body. The creator closes a rejected Driver; Install transfers ownership only on success. The embedding application eventually calls Core.Close with its chosen wait context. Drivers keep physical paths, provider IDs and temporary URLs private.

ListRequest.CursorTTL supplies an absolute lifetime on the first enumeration request. A continuation inherits it when zero, or must match it when supplied. Stat and Open need no enumeration policy. MaxCursors and OpenTimeout are optional runtime policies. Hosts choose values; there are no benchmark defaults. Continuations bind principal, path, mount generation and limit. The latest continuation response is replayable until advancement; competing advancement returns 429 instead of queuing. ReleaseCursor explicitly releases one enumeration. Cursors do not survive process restart.

Mount.Retire rejects new uses, invalidates enumerations and requests cancellation. Its context limits the wait, not unfinished work. Cleanup failures preserve the cause and owned resource; no automatic replacement or retry is claimed.

Directory aliases

BindAlias(ctx, prefix, mount, base) exposes an existing mount-relative directory under a fixed prefix. Ordinary mount entries and aliases share namespace lookup. All entry prefixes must be unique and non-nested. Targets are real installed Mount handles, so aliases cannot chain or merge storage. The base is a path mapping, not a pinned directory-object version.

An alias owns no Driver, connection or credentials. Every action checks both its visible path and corresponding primary path through the same Authorizer. Operations reject alias roots just like mount roots. Explicit aliases share mount revisions and retirement; equivalent resolved Copy/Move endpoints are rejected. No implicit physical-alias discovery across independent mounts is promised.

UnbindAlias removes the entry and invalidates its cursors, waiting for their cleanup within the supplied context. Already opened bodies retain their original mount use. A replacement mount requires explicit rebinding; queued work captured on an old binding cannot silently switch to the replacement. Hosts own alias persistence and control-plane authorization, just as they own prepared Install.

Optional mutations

Core.Mkdir and default Core.Write/Core.Create require CreateAction on the target; explicit replacement requires WriteAction, which permits creation or replacement at that name. Core.Remove requires RemoveAction. Policies granting only StatAction, ListAction and ReadAction remain read-only. An authorizer that ignores the action and returns nil for everything is a wildcard grant.

DirectoryMaker, Remover, FileCreator and FilePublisher are independent optional interfaces. The required Driver and Iterator interfaces are unchanged. Unsupported mounts return UnsupportedOperation with Unchanged before target effects or input reads. There is no second writer runtime, permission table or provider registry.

Create borrows an io.Reader until it returns. The caller retains ownership and closes owned input afterward. A nil length permits unknown input length; a nonnegative length describes the entire input, including normal EOF. Short, overlong and failed input cannot report successful completion. The operation does not seek, replay or close the input. A blocking reader may keep retirement unfinished even after cancellation.

Change.Effect is independent of error: Unknown (the zero value), Unchanged, Applied or Incomplete. Check both. Confirmed effects survive cancellation and cleanup failure; do not automatically retry or delete a failed target by path.

Local creates one directory with requested mode 0700, removes one entry without recursion, and creates new files with O_CREATE|O_EXCL and requested mode 0600. The operating system's permission rules still apply. Existing contents are never truncated. A final symbolic link is removed itself, not its target.

Default new-file creation may be visible while being written, and failed input can leave an incomplete file. This mode has no complete-publication or append guarantee. Explicit complete publication is described below. Failed native cleanup remains owned by the Driver and prevents successful retirement.

A possible mutation invalidates existing cursors for that mount before its result returns, including EOF replay. Other mounts and opened content are not invalidated by this coordination. Already-admitted reads may finish with an earlier observation; enumeration is not a snapshot.

The HTTP mutation routes are:

| Method and path | Result | | --- | --- | | POST /api/v1/fs/directories?path=... | Create one directory; no request body | | DELETE /api/v1/fs/entry?path=... | Remove one entry without recursion; no body | | PUT /api/v1/fs/content?path=... | Create a file from raw request bytes |

Success returns JSON with effect applied (201 for creation, 200 for removal). Handled mutation errors add effect to redacted Problem Details. Unsupported mounts return 501; existing targets and nonempty directories return 409. PUT optionally accepts If-None-Match: *; a proven unchanged conflict then returns 412. The condition uses native exclusion, not a metadata preflight. Other mutation conditions/range headers and non-identity Content-Encoding are rejected. Known Content-Length is exact; chunked input runs to normal EOF. A disconnected client may receive no receipt and must treat its outcome as uncertain. A later conflict does not prove an earlier lost request had no effect.

The info response lists server operations, not per-mount support or permission. There is no capability-discovery or frontend product in this module.

Complete file publication

Core.Write(ctx, principal, target, input, length, options...) is the common body write entry. Core.Create remains its default new-file shorthand. Supply at most one WriteOptions; Replace defaults to false. Explicit Replace creates a missing name or replaces an existing file only after complete input, including normal EOF and any declared length, has been validated. Input is never replayed or closed by the operation. Copy accepts the same options; each CopyRequest embeds WriteOptions for CopyBatch. CopyTree accepts it through DirectoryCopyOptions; Move retains its no-replacement rule. The HTTP PUT route continues to use default creation.

FilePublisher is a narrow optional Driver capability, separate from FileCreator. Unsupported capability or known Local configuration/volume mismatch is refused before reading input. Preparation and input failures leave the target Unchanged. A confirmed native publication reports Applied even with a subsequent cancellation or cleanup error. Unconfirmed publication stays Unknown; partial-publication receipts violate the capability and are reported conservatively. There is no automatic retry, rollback, conditional version update or power-loss durability.

Local enables publication with local.New(directory, local.Options{ StagingDirectory: staging, MaxStagingBytes: budget}). Both settings are required together; the byte budget must be positive. The host supplies an existing staging directory outside the served root, keeps it private from other mounts, and does not move or manipulate its owned objects while the Driver is active. No user name is reserved or filtered. Each target's actual parent must share the staging filesystem; a mismatch refuses publication without a cross-device copy fallback. Missing configuration leaves default creation available and refuses replacement.

Optional local.Options.MaxConcurrentCommits limits concurrent native complete-file publication commits within one Local instance. Zero adds no limit; negative values are invalid. It is independent of batch concurrency and staging configuration. Transfers remain parallel, and waiting calls retain their staging reservations, captured parents and runtime uses. Waiting honors cancellation and retirement; the permit is released after the native call, before temporary-file cleanup. The limit does not cover default creation, Move or Remove, and supplies no FIFO ordering, cross-instance limit or transaction isolation. Choose it for the host's filesystem workload; no platform-specific limit is imposed.

The budget belongs to one Local instance across all its calls. Known lengths reserve their full logical byte count before reading input; unknown lengths reserve each write before growing the temporary file. Exhaustion fails with CapacityExceeded rather than queueing. Cleanup of unpublished data must finish before its reservation is released; failed cleanup remains owned and charged. Published data leaves this temporary budget, while cleanup errors still prevent successful retirement. This is not a physical-block, total-storage, file-count or cross-instance quota. It excludes old opened objects, foreign files and crash leftovers; restart cleanup and recovery belong to the host.

Local performs one streaming write to private storage, then a parent-relative native rename: renameat on Linux and FileRenameInformationEx with replacement and POSIX semantics on Windows. It does not copy the temporary body back into target. See [Windows rename semantics](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_rename_information). Observed directories, links and spelling mismatches are refused. Final links introduced by a race are never followed; compatible name replacement may race. There is no content snapshot, object-ID/ACL preservation or external-mutation isolation. Already opened readers retain their old object.

A write retains its captured mount and parent through transfer, publication and cleanup. If the parent is moved meanwhile, the bound original directory remains the destination; new requests resolve the current namespace independently. Alias rebinding never redirects started work, and queued work rechecks its binding. Cancellation requests stop; the call still waits for borrowed input and cleanup acknowledgments. Cancellation can race with native publication, so inspect both Change and error.

Existing batch conflict ranges cover source reads and target writes for the whole operation. They preserve call-local order and the started result prefix. Separate calls have no shared path lock: writes, removes and parent moves may compete. A confirmed effect does not promise the current path still holds that result. Concurrency defaults to one. With W in-flight publications, stream buffers grow with W, and unpublished bytes are additionally bounded by the configured instance budget. Native filesystem work can reject publication after transfer; there is no truncation, copy/delete or delayed-success fallback.

Copy files

Core.Copy(ctx, principal, source, target, options...) writes the complete source body to a new target by default. It uses ReadAction and CreateAction, without requiring Stat or List grants. Explicit WriteOptions{Replace: true} instead uses WriteAction and the same complete-publication path as Core.Write. The target parent must exist; source and target paths must differ. Distinct paths within one mount or across mounts are supported. Copy does not remove source or copy metadata.

Copy borrows the opened Body and Length to the common write path, waits for that call to return, then closes the source and preserves observed cancellation. Check both Change.Effect and error. Default copies may leave incomplete targets; explicit replacement follows the complete-publication contract above. Source opening can independently refresh credentials. Neither mode promises a source snapshot, hard native-I/O cancellation deadline or durable job. Copy is included in the root test command and needs no additional module.

Rename and move entries

Core.Move(ctx, principal, source, target) unifies renaming, moving and changing both parent and name. It requires RemoveAction at source and CreateAction at target. MoveResult contains Source and Target changes: confirmed source-name removal and complete target creation. Both must be Applied and error must be nil for completion without errors. Applied can coexist with cancellation or cleanup errors; inspect receipts and error together and do not automatically replay.

Currently both paths must select the same live mount with the optional Relocator port. Its native no-replace receipt maps to both endpoints; a possible effect invalidates that mount's cursors once. Unchanged means this call did not modify the endpoint, not that another caller could not have changed it. Unknown is not resolved by checking the current path. Cross-mount movement is refused before creating a target: ordinary Open and Remove do not bind deletion to the object and content state read by this call. Move never falls back to copying and then deleting an unbound path.

Directory moves relocate one entry together with its children, without subtree enumeration or content copying. Source RemoveAction and target CreateAction authorize that whole relocation; descendant grants are not checked individually. Mount and alias roots, equivalent resolved endpoints and targets inside the source path are rejected. Aliases retain their configured paths after a move.

Local admits regular files and directories with existing target parents, refusing observed final symbolic links and special objects. Name and type checks are observations, not object/version/type conditions against external replacement. Windows opens the source with DELETE access relative to its rooted parent and uses the target directory handle; Linux amd64 uses renameat2 with RENAME_NOREPLACE and rooted parent descriptors. Other native platform/filesystem combinations return UnsupportedOperation when this guarantee is unavailable. Failed owned-handle cleanup remains with the Driver. Cross-volume fallback and power-loss durability are not promised.

Batch file operations

Core.RemoveBatch(ctx, principal, targets, options...), Core.CopyBatch(ctx, principal, requests, options...) and Core.MoveBatch(ctx, principal, requests, options...) retain input order and duplicates. MoveBatch takes []MoveRequest with Source and Target paths. Supply at most one ExecutionOptions. Concurrency zero or one is serial; negative values are invalid. Existing calls without options preserve serial behavior.

Explicit concurrency uses a shared, call-scoped executor. It resolves known aliases to mount generations and relative paths, and preserves read/write conflicts on equal or ancestor paths. Copy includes its source read and target write; Remove includes its target write; Move includes both endpoint writes. A blocked next item is not bypassed. Unknown locations act as conservative barriers. This orders known namespace conflicts within the call, without providing cross-request locks, physical-alias discovery or protection from external writers.

RemoveBatch and CopyBatch return []ItemResult with Change and Err; MoveBatch returns []MoveItemResult embedding MoveResult (Source and Target) plus Err. Each result slice is the started input prefix, in input order. Captured endpoint bindings are checked again at admission, so queued work cannot switch to a recreated alias or replacement mount. The first observed item error stops dispatch, including Applied with an error. With concurrency, later items may already have started; all in-flight items finish under their original contexts and keep their actual receipts. User cancellation requests cancellation of native work. The call waits for its resource handoffs before returning, without a hard native-I/O deadline. The overall error also retains cancellation observed between items or after the last success, without rewriting recorded item errors.

Empty input performs no authorization or native work, but reports observed cancellation. Results grow with K attempted items, and executor state is bounded by the chosen concurrency. Calls do not retain input lists, retry, roll back or create durable jobs.

Directory copy

Core.CopyTree(ctx, principal, source, target, TreeOptions, directoryOptions...) copies one real source directory into its corresponding target directory, whose parent must exist. It uses ListAction on source directories and ReadAction on copied files. Target directories and default file creation use CreateAction; explicit file publication uses WriteAction. The default requires new target names. It preserves empty directories without metadata preservation or source deletion.

Supply at most one DirectoryCopyOptions. Explicit MergeDirectories: true reuses existing directories and creates missing ones. Only an unchanged existence conflict followed by successful no-follow directory confirmation and cleanup is accepted. Reused directories report Unchanged with no error; this receipt does not summarize their descendants. File names still conflict by default, and type collisions fail; extra target entries are retained. Ordinary Mkdir keeps its rule. Merge requires DirectoryReader on the target, checked before mutation; native confirmation can still fail later after earlier directory effects. Confirmation uses CreateAction without additional Stat/List grants or consuming the returned target iterator. Native path resolution remains driver-specific.

DirectoryCopyOptions embeds WriteOptions independently of MergeDirectories. Explicit WriteOptions{Replace: true} publishes each complete file at its target name, creating missing files or replacing existing ones. It uses WriteAction on files and requires FilePublisher rather than FileCreator. Directories still use CreateAction and do not merge unless MergeDirectories is explicit. A new tree can also select complete file publication without directory merging.

The default retains ordinary Create semantics, including possible Incomplete effects on failure. Explicit publication reuses the single-file contract and Local staging budget/commit capacity. Failed input preserves that file's old target; confirmed earlier files and directories remain. This is not a whole-tree transaction. Known missing interfaces are refused before target mutation; driver configuration, per-file authorization and native submission failures can still occur after earlier effects. Input is not replayed, and publication never falls back to default creation. Inspect per-item Change and error on failure. The target tree is resolved by name per operation, without a physical-tree pin or transaction. Observed target links/redirects are refused during confirmation; external replacements afterward can change later path resolution. Confirmation does not supply parent-relative writes or a lasting link-free guarantee.

TreeOptions embeds ExecutionOptions and requires positive MaxEntries and MaxPlanBytes chosen by the caller. The root counts as an entry; the byte budget counts relative-path UTF-8 bytes in the plan, not content or native responses. Source scans also bound empty nonterminal advances with MaxEntries. Budget exhaustion is an error, never successful truncation. TreeCopyOptions remains a type alias for existing callers.

Discovery completes and closes all enumerations before target mutation. Directories are created parent-first and serially. File groups prepare bounded batches of at most W source directory scopes, each with a completed membership scan, then share one executor budget of at most W file operations. W is the requested concurrency, defaulting to one. Dispatch and results retain contiguous group order; adjacent groups can overlap without a worker pool per directory. Scopes close only after all started bodies finish. Membership scans retain their per-directory budgets; explicit concurrency can retain up to W directories' lookup state. A preparation failure leaves that batch unstarted; earlier effects remain. File bodies retain the existing Open/write ownership, length and cleanup contracts. Core adds no extra content staging or shared directory cache; explicit Local publication uses the private storage described above.

DirectoryReader is optional and leaves the required Driver unchanged. DirectoryScope reuses Iterator and adds OpenFile for an observed child name, available after normal enumeration EOF. OpenFile may run concurrently; Next has one caller, and all returned bodies must finish before Close. Source scopes reject native links/redirects at actual opens. Local supports this on Windows and Linux; Windows reparse points are refused, and unsupported platforms refuse before target mutation. S3 and alipan also provide source scopes. Destination capabilities remain independent: Local and Pool supply directory creation; see each Driver for its capabilities.

TreeItemResult reports RelativePath ("/" for the copied root), Change and Err in plan order: directories first, then file groups. Discovery, budget or discovery-close failure leaves the target untouched. Execution or later source preparation failure can leave a partial target; inspect both returned rows and the overall error. Confirmed effects survive cancellation or cleanup faults. Only discovered entries are included, without a directory/content snapshot, stable versions or a promise about undeclared physical overlap. Resolved same-mount source/target containment is refused.

Directory removal

Core.RemoveTree(ctx, principal, target, TreeOptions) removes one real directory using a finite discovery plan. Core.Remove remains nonrecursive. Mount, alias and virtual roots are refused. The positive entry/path budgets have the same meaning as CopyTree. Discovery, name validation, known capability checks, authorization preflight and enumeration cleanup finish before any deletion.

Discovery requires ListAction on directories and RemoveAction on every planned entry, including the root. Per-entry discovery authorization does not register a runtime mount use and does not reserve future permission. Each deletion is admitted again against the captured binding and borrows its own runtime use. It requires no content ReadAction and does not enumerate the target's outside parent. Discovery accepts ordinary files and directories; observed links, redirects or special objects are refused before effects.

Selection means names, not discovered object versions. A compatible same-name replacement can be removed, including a file whose content has changed. Unlisted new names are not chased. Nonempty directories return DirectoryNotEmpty; missing planned entries return Unchanged with NotFound and stop execution. An execution parent is opened without following redirects and then remains bound for its group. Final links are never followed; a non-directory unlink can remove the link itself. External renames are not transactionally isolated.

Parent groups execute deepest-first, retaining discovery order within each depth and group. Children finish and their parent scope closes before that directory can be removed; the target root is last. Within each depth, batches prepare at most W parent scopes and share one executor budget of W in-flight deletions, using the same ExecutionOptions and defaulting to serial execution. Dispatch and results keep contiguous group order; adjacent independent parents can overlap. A preparation failure leaves that batch unstarted and closes its prepared scopes. All started items finish and all batch scopes close before another batch starts. There is no worker pool per directory or global lock.

The optional ChildRemover capability belongs to DirectoryScope. RemoveChild takes one child name and File (non-directory unlink) or Directory (empty-directory removal only). It needs no enumeration first. Calls can overlap each other, but not Next, OpenFile or Close. Local implements it with parent-relative unlinkat on Linux and parent-relative DELETE handles with POSIX disposition on Windows. A successful Windows delete-handle close confirms namespace removal; pending deletion alone is not reported as Applied. Unsupported native modes have no recursive or delayed-success fallback. S3 and Alipan read scopes remain read-only; Pool supplies ChildRemover.

RemoveTree returns []TreeItemResult in started execution order, with "/" for the root. Every item keeps its Change and Err; cancellation, preparation and cleanup errors are also retained by the overall error. Already confirmed effects are not rolled back or rewritten. Applied describes this operation's name removal, not storage reclamation or protection against later recreation. Failed cleanup stays owned by its original scope/Driver. There are no retries, durable jobs or cross-mount Move guarantees.

Index

Constants

View Source
const (
	DefaultPage     = 100
	MaxPage         = 200
	MaxPathBytes    = 4096
	MaxPathSegments = 64
)

Variables

This section is empty.

Functions

func Fail

func Fail(code Code, cause error) error

func ValidName

func ValidName(s string) bool

func ValidatePath

func ValidatePath(p string) error

func Within

func Within(p, root string) bool

Types

type Action

type Action string
const (
	StatAction   Action = "stat"
	ListAction   Action = "list"
	ReadAction   Action = "read"
	CreateAction Action = "create"
	WriteAction  Action = "write" // Explicit create-or-replace permission.
	RemoveAction Action = "remove"
)

type Authorizer

type Authorizer func(context.Context, Principal, Action, string) error

type BindingInfo

type BindingInfo struct {
	Mount *Mount
	Base  string
}

BindingInfo is an observation, never an execution credential.

type Change

type Change struct{ Effect Effect }

type ChildRemover

type ChildRemover interface {
	RemoveChild(context.Context, string, Kind) (Change, error)
}

ChildRemover is an optional capability of a DirectoryScope, not of Driver. It removes one current child name without resolving the parent again. File means a non-directory unlink (never following a final link); Directory means empty-directory removal only. It does not bind a discovered object version. No enumeration is required. Calls may overlap each other, but must not overlap Next, OpenFile or Close. Native work finishes before return; failed cleanup stays owned by the scope/Driver. Applied confirms name removal, not storage reclamation.

type Code

type Code string
const (
	UnsupportedOperation     Code = "unsupported_operation"
	AlreadyExists            Code = "already_exists"
	DirectoryNotEmpty        Code = "directory_not_empty"
	InvalidRequest           Code = "invalid_request"
	InvalidPath              Code = "invalid_path"
	InvalidRange             Code = "invalid_range"
	Unauthenticated          Code = "unauthenticated"
	PermissionDenied         Code = "permission_denied"
	NotFound                 Code = "not_found"
	PathAmbiguous            Code = "path_ambiguous"
	NotDirectory             Code = "not_directory"
	NotFile                  Code = "not_file"
	UnrepresentableName      Code = "unrepresentable_name"
	CursorUnavailable        Code = "cursor_unavailable"
	RangeNotSatisfiable      Code = "range_not_satisfiable"
	CapacityExceeded         Code = "capacity_exceeded"
	MountUnavailable         Code = "mount_unavailable"
	InvalidUpstreamResponse  Code = "invalid_upstream_response"
	UpstreamFailure          Code = "upstream_failure"
	UpstreamAccessDenied     Code = "upstream_access_denied"
	UpstreamTimeout          Code = "upstream_timeout"
	InternalError            Code = "internal_error"
	ResolutionBudgetExceeded Code = "resolution_budget_exceeded"
	ResponseBudgetExceeded   Code = "response_budget_exceeded"
	UpstreamThrottled        Code = "upstream_throttled"
)

func CodeOf

func CodeOf(err error) Code

type Content

type Content struct {
	Entry  Entry
	Body   io.ReadCloser
	Length *int64
	Range  *ContentRange
}

type ContentRange

type ContentRange struct{ Start, End, Total int64 }

type CopyRequest

type CopyRequest struct {
	Source string
	Target string
	WriteOptions
}

type Core

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

func New

func New(opts Options) (*Core, error)

func (*Core) BindAlias

func (c *Core) BindAlias(ctx context.Context, prefix string, mount *Mount, base string) error

BindAlias exposes a directory of an installed mount under a new, non-nested prefix. It owns no Driver and grants no permission beyond the primary path.

func (*Core) Binding

func (c *Core) Binding(prefix string) (BindingInfo, bool)

func (*Core) Capture

func (c *Core) Capture(ctx context.Context, accesses ...PathAccess) (*Selection, error)

Capture selects existing real bindings, including paths not yet created. Authorization remains mandatory when the normal operation executes.

func (*Core) CheckCursor

func (c *Core) CheckCursor(ctx context.Context, p Principal, r ListRequest) error

CheckCursor validates a continuation without advancing it, for conditional responses. No I/O or extra enumeration is performed.

func (*Core) Close

func (c *Core) Close(ctx context.Context) error

func (*Core) Copy

func (c *Core) Copy(ctx context.Context, principal Principal, source, target string, options ...WriteOptions) (Change, error)

Copy synchronously writes target from the complete source body. The parent must exist; replacement is explicit. It does not remove source. The returned Change describes the target even when error is non-nil.

func (*Core) CopyBatch

func (c *Core) CopyBatch(ctx context.Context, p Principal, requests []CopyRequest, options ...ExecutionOptions) ([]ItemResult, error)

CopyBatch follows RemoveBatch's prefix and stop contract. Its conflict ranges include both source reads and target writes after explicit alias resolution. Unknown physical aliases and external mutations are not transactionally locked.

func (*Core) CopyTree

func (c *Core) CopyTree(ctx context.Context, p Principal, source, target string, options TreeOptions, directoryOptions ...DirectoryCopyOptions) (results []TreeItemResult, err error)

CopyTree discovers a finite source directory before writing its target tree. Existing directories require explicit MergeDirectories; file publication uses the selected WriteOptions. It preserves empty directories without source deletion, snapshots, retries or rollback. Supply at most one DirectoryCopyOptions.

func (*Core) Create

func (c *Core) Create(ctx context.Context, p Principal, target string, input io.Reader, length *int64) (Change, error)

Create writes a new file without replacing an existing target. The caller owns input and keeps it valid until this synchronous call returns.

func (*Core) Inspect

func (c *Core) Inspect(ctx context.Context, p Principal, action Action, target string) (Entry, error)

Inspect checks metadata under the requested action without opening content.

func (*Core) Install

func (c *Core) Install(p string, d Driver) (*Mount, error)

func (*Core) List

func (c *Core) List(ctx context.Context, p Principal, r ListRequest) (Page, error)

func (*Core) Mkdir

func (c *Core) Mkdir(ctx context.Context, p Principal, target string) (Change, error)

func (*Core) Move

func (c *Core) Move(ctx context.Context, p Principal, source, target string) (MoveResult, error)

Move renames or moves a file or directory without replacing target. Directory admission authorizes the whole native relocation, without descendant checks. Both receipts must be Applied and error must be nil for completion without errors. Currently only native relocation within one mount is supported; copying followed by removal through an unbound source path is never used.

func (*Core) MoveBatch

func (c *Core) MoveBatch(ctx context.Context, p Principal, requests []MoveRequest, options ...ExecutionOptions) ([]MoveItemResult, error)

MoveBatch follows the same prefix and stop contract as CopyBatch. Both endpoints are writes, including their descendants, within this finite call.

func (*Core) Open

func (c *Core) Open(ctx context.Context, p Principal, target string, wanted *Range) (Content, error)

func (*Core) ReleaseCursor

func (c *Core) ReleaseCursor(ctx context.Context, p Principal, token string) error

ReleaseCursor closes an owned enumeration, including in-flight work. A revoked read grant does not prevent cleanup of the principal's existing resource.

func (*Core) Remove

func (c *Core) Remove(ctx context.Context, p Principal, target string) (Change, error)

func (*Core) RemoveBatch

func (c *Core) RemoveBatch(ctx context.Context, p Principal, targets []string, options ...ExecutionOptions) ([]ItemResult, error)

RemoveBatch retains input order and duplicates. Execution is serial unless an explicit concurrency option is supplied. On failure no more items start; already started items finish and retain their receipts in the returned prefix.

func (*Core) RemoveTree

func (c *Core) RemoveTree(ctx context.Context, p Principal, target string, options TreeOptions) (results []TreeItemResult, err error)

RemoveTree removes only the names in a bounded discovery of one directory. Compatible same-name replacements can be removed; unlisted new names are not chased. Directories are removed only when empty. Results are the started prefix in child-before-parent execution order, with the root last.

func (*Core) Stat

func (c *Core) Stat(ctx context.Context, p Principal, target string) (Entry, error)

func (*Core) UnbindAlias

func (c *Core) UnbindAlias(ctx context.Context, prefix string) error

UnbindAlias removes only an alias and its cursors. Open bodies keep their captured mount use. Context bounds cleanup waiting, not native cleanup work.

func (*Core) Write

func (c *Core) Write(ctx context.Context, p Principal, target string, input io.Reader, length *int64, options ...WriteOptions) (Change, error)

Write shares Create's input ownership. The default creates a new file; explicit Replace requires WriteAction and complete-publication capability.

type DirectoryCopyOptions

type DirectoryCopyOptions struct {
	WriteOptions
	MergeDirectories bool
}

DirectoryCopyOptions selects directory and file policies independently. MergeDirectories accepts existing directories. WriteOptions governs each file.

type DirectoryMaker

type DirectoryMaker interface {
	Mkdir(context.Context, string) (Change, error)
}

Optional capabilities share the installed Driver's lifetime. An unsupported mode must be refused before consuming input or changing the target.

type DirectoryReader

type DirectoryReader interface {
	OpenDirectory(context.Context, string) (DirectoryScope, error)
}

DirectoryReader opens a bound directory. Every path component is opened without following native links or redirects; "/" is the prepared root. Opening does not require Next. The returned scope is owned even on error.

type DirectoryScope

type DirectoryScope interface {
	Iterator
	OpenFile(context.Context, string) (Opened, error)
}

DirectoryScope enumerates one bound directory. Only after normal EOF may OpenFile open an observed, unambiguous regular child by a single name. OpenFile may run concurrently; Next has one caller. Bodies must finish before Close. Neither the directory nor file content is promised to be a snapshot.

type Driver

type Driver interface {
	Stat(context.Context, string) (Metadata, error)
	Enumerate(context.Context, string) (Iterator, error)
	Open(context.Context, string, *Range) (Opened, error)
	Close() error
}

Driver is rooted when constructed. Paths use slash-separated mount-relative syntax beginning at /. Provider IDs and physical paths remain inside it. Open transfers every returned Body to the caller, including on error.

type Effect

type Effect uint8

Effect describes target mutation independently of an operation's error. The zero value is conservative: no absence of effects has been established.

const (
	Unknown Effect = iota
	Unchanged
	Applied
	Incomplete
)

func (Effect) String

func (e Effect) String() string

type Entry

type Entry struct {
	Path       string     `json:"path"`
	Name       string     `json:"name"`
	Kind       Kind       `json:"kind"`
	Size       *int64     `json:"size"`
	ModifiedAt *time.Time `json:"modified_at"`
	Virtual    bool       `json:"virtual"`
}

type Error

type Error struct {
	Code  Code
	Cause error
	Total *int64
}

Error preserves an internal cause without making it part of the wire response.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ExecutionOptions

type ExecutionOptions struct{ Concurrency int }

ExecutionOptions applies within one finite call, not across independent requests or external writers. Zero and one select serial execution.

type FileCreator

type FileCreator interface {
	// Create borrows input synchronously; it must not close or retain it.
	// Length, when supplied, describes the entire input, including its normal EOF.
	Create(context.Context, string, io.Reader, *int64) (Change, error)
}

type FilePublisher

type FilePublisher interface {
	Publish(context.Context, string, io.Reader, *int64) (Change, error)
}

FilePublisher is optional. Publish validates complete input before changing the target name, creates or replaces it, and borrows input only until return. It does not promise conditional versions, metadata preservation or durability.

type ItemResult

type ItemResult struct {
	Change Change
	Err    error
}

ItemResult records one attempted input occurrence, including repeated inputs. An error does not erase a confirmed or uncertain Change.

type Iterator

type Iterator interface {
	Next(context.Context, int) ([]Metadata, error)
	Close() error
}

Iterator owns a native enumeration. Next returns a batch and may return io.EOF together with its final entries. Context applies to the current call only.

type Kind

type Kind string
const (
	File      Kind = "file"
	Directory Kind = "directory"
)

type ListRequest

type ListRequest struct {
	Path   string
	Limit  int
	Cursor string
	// CursorTTL is required on the first request; zero inherits on continuation.
	CursorTTL time.Duration
}

type Metadata

type Metadata struct {
	Name       string
	Kind       Kind
	Size       *int64
	ModifiedAt *time.Time
}

Metadata contains observations, not an object identity or an owned handle.

type Mount

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

Mount is the identity of one installed generation. Retiring an old handle never retires a later replacement installed at the same virtual path.

func (*Mount) Retire

func (m *Mount) Retire(ctx context.Context) error

Retire stops admission and requests cancellation immediately. Its context bounds this wait, not the lifetime of unfinished work or Driver.Close.

func (*Mount) Status

func (m *Mount) Status() MountStatus

Status observes this exact generation, even after its prefix is replaced.

type MountStatus

type MountStatus struct {
	Active, Retiring, Done bool
	Err                    error
}

type MoveItemResult

type MoveItemResult struct {
	MoveResult
	Err error
}

MoveItemResult retains both endpoint receipts for one attempted occurrence.

type MoveRequest

type MoveRequest struct {
	Source string
	Target string
}

type MoveResult

type MoveResult struct {
	Source Change
	Target Change
}

MoveResult reports this operation's source removal and target creation. Receipts do not describe changes made by other callers after either effect.

type Opened

type Opened struct {
	Metadata Metadata
	Body     io.ReadCloser
	Length   *int64
	Range    *ContentRange
}

type Options

type Options struct {
	Authorize   Authorizer
	MaxCursors  int
	OpenTimeout time.Duration
}

Options supplies runtime policy, not a configuration-file format. Cursor lifetime belongs to each enumeration request.

type Page

type Page struct {
	Items           []Entry    `json:"items"`
	NextCursor      *string    `json:"next_cursor"`
	CursorExpiresAt *time.Time `json:"cursor_expires_at"`
}

type PathAccess

type PathAccess struct {
	Path  string
	Write bool
}

PathAccess describes a logical range for capture and optional conflict checks. Write is scheduling metadata, not an authorization grant.

type Principal

type Principal string

type Range

type Range struct {
	Start, End int64
	Suffix     bool
}

Range is either an inclusive start/end (End=-1 means open-ended), or a suffix.

func (Range) Resolve

func (r Range) Resolve(total int64) (ContentRange, error)

func (Range) Valid

func (r Range) Valid() bool

type Relocator

type Relocator interface {
	Relocate(context.Context, string, string) (Change, error)
}

Relocator atomically moves an admitted regular file or directory without replacement. Unsupported entry kinds must be refused before effects. Paths use the Driver's native execution-time binding; metadata checks do not bind an object version or type against external replacement. Source and target belong to the same installed Driver and an existing parent.

type Remover

type Remover interface {
	Remove(context.Context, string) (Change, error)
}

type Selection

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

Selection records process-local bindings without borrowing their resources. It cannot be restored, grants no permission, and does not freeze file content.

func (*Selection) Conflicts

func (s *Selection) Conflicts(other *Selection) bool

Conflicts compares the declared ranges, without accessing mutable mount state. Independent Core instances and undeclared physical aliases are not compared.

func (*Selection) Context

func (s *Selection) Context(ctx context.Context) context.Context

Context constrains ordinary calls to these bindings and their descendants. A retired/rebound selection fails at admission instead of resolving anew.

type TreeCopyOptions

type TreeCopyOptions = TreeOptions

TreeCopyOptions remains an alias for existing CopyTree callers.

type TreeItemResult

type TreeItemResult struct {
	RelativePath string // "/" is the operation root.
	Change       Change
	Err          error
}

type TreeOptions

type TreeOptions struct {
	ExecutionOptions
	// Both budgets are caller-selected and positive. MaxPlanBytes counts stored
	// relative-path UTF-8 bytes, not native response bytes or file content.
	MaxEntries   int
	MaxPlanBytes int
}

type WriteOptions

type WriteOptions struct{ Replace bool }

WriteOptions leaves existing targets untouched unless Replace is explicit. Replace publishes complete input at a name, creating it when absent.

Directories

Path Synopsis
browser module
Package control manages desired mount definitions using host-owned storage and factories.
Package control manages desired mount definitions using host-owned storage and factories.
drivers
alipan module
atomgit module
autoindex module
azureblob module
babelbird module
baidupan module
baidupan/cdp module
box module
bunny module
cloudreve module
cnbreleases module
codeartsrepo module
dingtalkdrive module
dropbox module
emby module
fangcloud module
febbox module
feishudrive module
ftp module
githubrepo module
gokuai module
googledrive module
googlephotos module
graphdrive module
guangyapan module
huaweidrive module
imgbed module
ipfs module
kdocs module
koodrive module
lanzou module
mediafire module
misskey module
mobilepan module
pan115 module
pan115/cdp module
pan123 module
pan123/cdp module
pdsshare module
pikpak module
pool module
quark module
quark/cdp module
s3 module
seafile module
sftp module
smb module
teambition module
teldrive module
tencentdocs module
tencentsmh module
tianyipan module
uc module
upyun module
urltree module
webdav module
wecomdrive module
weiyun module
wps365 module
wuyingdrive module
yandex module
yunpan360 module
Package httpapi projects file, mount-control and task contracts onto HTTP.
Package httpapi projects file, mount-control and task contracts onto HTTP.
Package local adapts a prepared filesystem root to file operations.
Package local adapts a prepared filesystem root to file operations.
protocols
s3 module
sftp module
Package task runs arbitrary process-local work with bounded admission and concurrency.
Package task runs arbitrary process-local work with bounded admission and concurrency.

Jump to

Keyboard shortcuts

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