Documentation
¶
Overview ¶
Package plainfs writes, removes and creates folders inside a project folder only through plain files and plain folders.
A project folder may have been cloned from someone else, so nothing below it can be trusted to be what it looks like. Every function here takes the project folder (root, trusted as given) and a path inside it, walks from root down to the path with Lstat, and refuses a folder that is a link or is not a plain folder, and a target that exists and is not a plain file. A file is opened so that a link put in its place after the check is not followed where the platform has O_NOFOLLOW (every Unix); on Windows, which has none, the Lstat check alone applies, and it also refuses a junction.
A refusal wraps ErrNotPlain and names the path inside the project; it never says where a link leads. Reads are not covered by this package.
Index ¶
- Variables
- func CreateFile(root, filePath string) (io.WriteCloser, error)
- func MkdirAll(root, dir string) error
- func PublishFile(ctx context.Context, rootPath, filePath string, data []byte, ...) (err error)
- func Remove(root, filePath string) error
- func RemoveAll(root, dir string) error
- func WriteFile(root, filePath string, write func(io.Writer) error) (err error)
Constants ¶
This section is empty.
Variables ¶
var ErrNotPlain = errors.New("not a plain file or folder of the project")
ErrNotPlain is wrapped by every refusal: a path outside the project, a link, or an entry of another kind where a plain file or folder is needed.
Functions ¶
func CreateFile ¶
func CreateFile(root, filePath string) (io.WriteCloser, error)
CreateFile opens filePath, which must be inside root, for writing: it makes the missing folders above it, refuses a target that exists and is not a plain file, and creates or truncates the file without following a link.
func MkdirAll ¶
MkdirAll makes dir, which must be root or inside it, and every missing folder between them, refusing any existing one that is not a plain folder.
func PublishFile ¶ added in v0.126.0
func PublishFile(ctx context.Context, rootPath, filePath string, data []byte, authorize func() error) (err error)
PublishFile writes and closes a private stage, then publishes the complete file with an atomic hard-link operation that never replaces an entry. Paths remain confined to root and every existing parent must be plain. Cleanup removes empty created directories only while their observed identities still occupy the same plain path. A replaced/moved directory is preserved. Errors after the link may leave a committed target; no rollback is claimed. Namespace checks are not a transaction with uncoordinated external renames; callers must coordinate project-directory mutations. A detected post-link identity change returns an error rather than acknowledging the wrong path.
func Remove ¶
Remove deletes the plain file filePath, which must be inside root. A file that is not there, or a folder above it that is not there, is not an error.
Types ¶
This section is empty.