Documentation
¶
Index ¶
- Variables
- func CreateTempFile(dir, pattern string) (*os.File, error)
- func EnsureDir(dir string) error
- func FileExists(filename string) bool
- func FilesExist(filenames ...string) (bool, error)
- func IsHomeDir(path string) bool
- func ReadFile(filename string) (string, error)
- func ReadFileBytes(path string) ([]byte, error)
- func SafeResolvePath(filePath string) (string, error)
- func SafeResolvePathForWrite(filePath string) (string, error)
- func SafeResolvePathForWriteWithBypass(ctx context.Context, filePath string) (string, error)
- func SafeResolvePathWithBypass(ctx context.Context, filePath string) (string, error)
- func SaveFile(filename, content string) error
- func SecurityBypassEnabled(ctx context.Context) bool
- func WithSecurityBypass(ctx context.Context) context.Context
- func WithWorkspaceRoot(ctx context.Context, workspaceRoot string) context.Context
- func WorkspaceRootFromContext(ctx context.Context) string
- func WriteFileWithDir(path string, data []byte, perm os.FileMode) error
Constants ¶
This section is empty.
Variables ¶
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
var ErrWriteOutsideWorkingDirectory = errors.New("file write outside working directory")
ErrWriteOutsideWorkingDirectory is returned when a write path is outside the working directory
Functions ¶
func CreateTempFile ¶
CreateTempFile creates a temporary file
func FileExists ¶
FileExists checks if a file exists at the given path
func FilesExist ¶
FilesExist checks if all the given files exist
func IsHomeDir ¶ added in v0.16.25
IsHomeDir reports whether path is the current user's home directory. Both paths are resolved through symlinks so that, e.g., /var/folders/... and /Users/alanp compare correctly on macOS.
Symlink resolution is bounded by symlinkTimeout so a hanging network mount (NFS, SMB) cannot stall index builds indefinitely.
func ReadFileBytes ¶
ReadFileBytes reads file as bytes
func SafeResolvePath ¶
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 ¶
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 ¶
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 ¶
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 ¶
SaveFile saves or removes a file with the given content. If content is empty, the file is removed.
func SecurityBypassEnabled ¶
SecurityBypassEnabled reports whether the context carries an explicit filesystem security bypass approval.
func WithSecurityBypass ¶
WithSecurityBypass marks a context as having explicit user approval for file access outside the workspace root.
func WithWorkspaceRoot ¶
WithWorkspaceRoot stores an explicit workspace root on the context so file and process operations do not depend on the process-global cwd.
func WorkspaceRootFromContext ¶
WorkspaceRootFromContext returns the explicit workspace root carried on ctx, if any.
Types ¶
This section is empty.