fileutil

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxEditFileSize = 5 * 1024 * 1024 // 5MB
)

Variables

View Source
var StaticMimeTypeMap = map[string]string{}/* 1260 elements not displayed */

Functions

func AddMimeTypeToFileInfo

func AddMimeTypeToFileInfo(path string, fileInfo *wshrpc.FileInfo)

func ApplyEdits

func ApplyEdits(originalContent []byte, edits []EditSpec) ([]byte, error)

ApplyEdits applies a series of edits to the given content and returns the modified content. This is atomic - all edits succeed or all fail.

func DetectMimeType

func DetectMimeType(path string, fileInfo fs.FileInfo, extended bool) string

on error just returns "" does not return "application/octet-stream" as this is considered a detection failure can pass an existing fileInfo to avoid re-statting the file falls back to text/plain for 0 byte files

func DetectMimeTypeWithDirEnt

func DetectMimeTypeWithDirEnt(path string, dirEnt fs.DirEntry) string

func FixPath

func FixPath(path string) (string, error)

func IsInitScriptPath

func IsInitScriptPath(input string) bool

IsInitScriptPath tries to determine if the input string is a path to a script rather than an inline script content.

func ReplaceInFile

func ReplaceInFile(filePath string, edits []EditSpec) error

func WinSymlinkDir

func WinSymlinkDir(path string, bits os.FileMode) bool

Types

type DirEntryOut

type DirEntryOut struct {
	Name         string `json:"name"`
	Dir          bool   `json:"dir,omitempty"`
	Symlink      bool   `json:"symlink,omitempty"`
	Size         int64  `json:"size,omitempty"`
	Mode         string `json:"mode"`
	Modified     string `json:"modified"`
	ModifiedTime string `json:"modified_time"`
}

type EditResult

type EditResult struct {
	Applied bool   `json:"applied"`
	Desc    string `json:"desc"`
	Error   string `json:"error,omitempty"`
}

func ApplyEditsPartial

func ApplyEditsPartial(originalContent []byte, edits []EditSpec) ([]byte, []EditResult)

ApplyEditsPartial applies edits incrementally, continuing until the first failure. Returns the modified content (potentially partially applied) and results for each edit.

func ReplaceInFilePartial

func ReplaceInFilePartial(filePath string, edits []EditSpec) ([]EditResult, error)

ReplaceInFilePartial applies edits incrementally up to the first failure. Returns the results for each edit and writes the partially modified content.

type EditSpec

type EditSpec struct {
	OldStr string `json:"old_str"`
	NewStr string `json:"new_str"`
	Desc   string `json:"desc,omitempty"`
}

type FsFileInfo

type FsFileInfo struct {
	NameInternal    string
	ModeInternal    os.FileMode
	SizeInternal    int64
	ModTimeInternal int64
	IsDirInternal   bool
}

func ToFsFileInfo

func ToFsFileInfo(fi *wshrpc.FileInfo) FsFileInfo

ToFsFileInfo converts wshrpc.FileInfo to FsFileInfo. It panics if fi is nil.

func (FsFileInfo) IsDir

func (f FsFileInfo) IsDir() bool

func (FsFileInfo) ModTime

func (f FsFileInfo) ModTime() time.Time

func (FsFileInfo) Mode

func (f FsFileInfo) Mode() os.FileMode

func (FsFileInfo) Name

func (f FsFileInfo) Name() string

func (FsFileInfo) Size

func (f FsFileInfo) Size() int64

func (FsFileInfo) Sys

func (f FsFileInfo) Sys() interface{}

type ReadDirResult

type ReadDirResult struct {
	Path         string        `json:"path"`
	AbsolutePath string        `json:"absolute_path"`
	ParentDir    string        `json:"parent_dir,omitempty"`
	Entries      []DirEntryOut `json:"entries"`
	EntryCount   int           `json:"entry_count"`
	TotalEntries int           `json:"total_entries"`
	Truncated    bool          `json:"truncated,omitempty"`
}

func ReadDir

func ReadDir(path string, maxEntries int) (*ReadDirResult, error)

func ReadDirRecursive

func ReadDirRecursive(path string, maxEntries int) (*ReadDirResult, error)

Jump to

Keyboard shortcuts

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