plainfs

package
v0.43.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func MkdirAll(root, dir string) error

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 Remove

func Remove(root, filePath string) error

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.

func RemoveAll

func RemoveAll(root, dir string) error

RemoveAll deletes the plain folder dir, which must be inside root, with everything in it. A folder that is not there is not an error; the project folder itself is never removed.

func WriteFile

func WriteFile(root, filePath string, write func(io.Writer) error) (err error)

WriteFile is CreateFile followed by write and a Close; it returns the error of the write, or else the error of the close.

Types

This section is empty.

Jump to

Keyboard shortcuts

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