filesystem

package
v0.16.24 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOutsideWorkingDirectory = errors.New("file access outside working directory")

ErrOutsideWorkingDirectory is returned when a path is outside the working directory This should be caught by tool handlers to prompt the user for confirmation

View Source
var ErrWriteOutsideWorkingDirectory = errors.New("file write outside working directory")

ErrWriteOutsideWorkingDirectory is returned when a write path is outside the working directory

Functions

func CreateTempFile

func CreateTempFile(dir, pattern string) (*os.File, error)

CreateTempFile creates a temporary file

func EnsureDir

func EnsureDir(dir string) error

EnsureDir creates directory if it doesn't exist

func FileExists

func FileExists(filename string) bool

FileExists checks if a file exists at the given path

func FilesExist

func FilesExist(filenames ...string) (bool, error)

FilesExist checks if all the given files exist

func ReadFile

func ReadFile(filename string) (string, error)

ReadFile reads the content of a file.

func ReadFileBytes

func ReadFileBytes(path string) ([]byte, error)

ReadFileBytes reads file as bytes

func SafeResolvePath

func SafeResolvePath(filePath string) (string, error)

SafeResolvePath validates and resolves a file path, checking for path traversal while allowing symlinks that stay within the working directory.

Returns the resolved absolute path if it's safe to access, or an error otherwise.

func SafeResolvePathForWrite

func SafeResolvePathForWrite(filePath string) (string, error)

SafeResolvePathForWrite validates a file path for writing, checking that the parent directory is safe to access. This allows writing to new files that don't exist yet while still preventing path traversal attacks.

Returns the absolute path if it's safe to write, or an error otherwise.

func SafeResolvePathForWriteWithBypass

func SafeResolvePathForWriteWithBypass(ctx context.Context, filePath string) (string, error)

SafeResolvePathForWriteWithBypass validates a file path for writing with optional bypass. This allows writing to new files that don't exist yet while still preventing path traversal attacks. When security bypass is enabled via context, writes outside the working directory are allowed.

Returns the absolute path if it's safe to write, or an error otherwise.

func SafeResolvePathWithBypass

func SafeResolvePathWithBypass(ctx context.Context, filePath string) (string, error)

SafeResolvePathWithBypass validates a file path for reading, checking that it's within the working directory and handling symlinks properly. Optional bypass can be enabled via context when user has explicitly approved the operation.

func SaveFile

func SaveFile(filename, content string) error

SaveFile saves or removes a file with the given content. If content is empty, the file is removed.

func SecurityBypassEnabled

func SecurityBypassEnabled(ctx context.Context) bool

SecurityBypassEnabled reports whether the context carries an explicit filesystem security bypass approval.

func WithSecurityBypass

func WithSecurityBypass(ctx context.Context) context.Context

WithSecurityBypass marks a context as having explicit user approval for file access outside the workspace root.

func WithWorkspaceRoot

func WithWorkspaceRoot(ctx context.Context, workspaceRoot string) context.Context

WithWorkspaceRoot stores an explicit workspace root on the context so file and process operations do not depend on the process-global cwd.

func WorkspaceRootFromContext

func WorkspaceRootFromContext(ctx context.Context) string

WorkspaceRootFromContext returns the explicit workspace root carried on ctx, if any.

func WriteFileWithDir

func WriteFileWithDir(path string, data []byte, perm os.FileMode) error

WriteFileWithDir creates the directory and writes the file

Types

This section is empty.

Jump to

Keyboard shortcuts

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