Documentation
¶
Index ¶
- Constants
- Variables
- func CleanPathPrefix(path string) (string, error)
- func CopyTree(ctx context.Context, src CopySource, srcEntry *CopyEntry, dest CopyDest, ...) error
- func GetParentPath(conn *connparse.Connection) string
- func GetParentPathString(hostAndPath string) string
- func IncompleteTransferError(target string, got int64, want int64) error
- func IsPathWithin(parent string, child string, separator string) bool
- func MakeTempName(baseName string) (string, error)
- func PreservedMode(mode os.FileMode) os.FileMode
- func ReadFileStream(ctx context.Context, readCh <-chan wshrpc.RespOrErrorUnion[wshrpc.FileData], ...) error
- func ReadStreamToFileData(ctx context.Context, readCh <-chan wshrpc.RespOrErrorUnion[wshrpc.FileData]) (*wshrpc.FileData, error)
- func ReplaceLocalFile(target string, r io.Reader, opts ReplaceOpts) (int64, error)
- func ResolveCopyDestPath(dest CopyDest, destPath string, srcBaseName string, destHasSlash bool) (string, error)
- func ResolveLocalWriteTarget(p string) (string, error)
- func SaveLocalFile(p string, data []byte, createMode os.FileMode) error
- func WriteLocalFileInPlace(target string, data []byte) error
- type CopyDest
- type CopyEntry
- type CopyOpts
- type CopySource
- type FileOwner
- type LocalCopyDest
- func (LocalCopyDest) Base(p string) string
- func (LocalCopyDest) Dir(p string) string
- func (LocalCopyDest) Join(dir string, name string) string
- func (LocalCopyDest) Mkdir(p string, mode os.FileMode) error
- func (LocalCopyDest) RemoveAll(p string) error
- func (LocalCopyDest) Rename(oldPath string, newPath string) error
- func (LocalCopyDest) Stat(p string) (*CopyEntry, error)
- func (LocalCopyDest) WriteFile(p string, r io.Reader, mode os.FileMode, expectedSize int64) error
- type LocalCopySource
- type ReplaceOpts
Constants ¶
const ( TempFilePrefix = ".genieterm-" TempBaseNameMaxLen = 64 MaxSymlinkDepth = 40 DefaultFileMode = os.FileMode(0644) )
const ( OverwriteRequiredError = "file already exists at %q, set overwrite flag to delete the existing file" MergeRequiredError = "directory already exists at %q, set overwrite flag to delete the existing contents or set merge flag to merge the contents" )
Variables ¶
ErrAtomicReplaceUnavailable marks failures where the file could not be replaced via temp-file-and-rename without losing something (directory not writable, foreign owner, hard links). Callers that hold the data in memory may fall back to an in-place write.
Functions ¶
func CleanPathPrefix ¶
CleanPathPrefix corrects paths for prefix filesystems (i.e. ones that don't have directories)
func CopyTree ¶ added in v0.5.0
func CopyTree(ctx context.Context, src CopySource, srcEntry *CopyEntry, dest CopyDest, destPath string, opts CopyOpts) error
CopyTree copies srcEntry to destPath. Files replace atomically (overwrite required if the destination exists). Directories are copied into a staging directory and swapped in only on success; with Merge the source tree is copied into the existing directory, replacing files. Symlinks inside a directory tree are copied as their target file contents; symlinked directories and special files are skipped.
func GetParentPath ¶
func GetParentPath(conn *connparse.Connection) string
func GetParentPathString ¶
func IncompleteTransferError ¶ added in v0.5.0
func IsPathWithin ¶ added in v0.5.0
IsPathWithin reports whether child is parent or lies under it (both must be cleaned, same separator).
func MakeTempName ¶ added in v0.5.0
func PreservedMode ¶ added in v0.5.0
PreservedMode keeps permission and setuid/setgid/sticky bits of an existing file.
func ReadFileStream ¶
func ReadStreamToFileData ¶
func ReplaceLocalFile ¶ added in v0.5.0
ReplaceLocalFile streams r into a temp file next to target (same filesystem), fsyncs it, copies the existing file's mode/owner and renames it over target only after everything succeeded. On any failure the temp file is removed and the original target is left untouched.
func ResolveCopyDestPath ¶ added in v0.5.0
func ResolveLocalWriteTarget ¶ added in v0.5.0
ResolveLocalWriteTarget follows symlinks so a replace lands on the link target instead of swapping the link itself for a regular file. Dangling links resolve to their (missing) target.
func SaveLocalFile ¶ added in v0.5.0
SaveLocalFile replaces the contents of p (following symlinks) atomically when possible. When the directory is not writable or ownership/hard links can't be preserved it falls back to truncating and rewriting the existing file in place, which is what editors do in the same situation.
func WriteLocalFileInPlace ¶ added in v0.5.0
Types ¶
type CopyDest ¶ added in v0.5.0
type CopyDest interface {
Stat(p string) (*CopyEntry, error)
Join(dir string, name string) string
Dir(p string) string
Base(p string) string
Mkdir(p string, mode os.FileMode) error
WriteFile(p string, r io.Reader, mode os.FileMode, expectedSize int64) error
Rename(oldPath string, newPath string) error
RemoveAll(p string) error
}
CopyDest is the write side of a copy. Stat follows symlinks and returns (nil, nil) for a missing path. WriteFile must replace atomically. RemoveAll must not follow a top-level symlink.
type CopySource ¶ added in v0.5.0
type CopySource interface {
Stat(p string) (*CopyEntry, error)
ReadDir(p string) ([]*CopyEntry, error)
Open(p string) (io.ReadCloser, error)
}
CopySource is the read side of a copy. Stat follows symlinks; ReadDir entries do not.
type LocalCopyDest ¶ added in v0.5.0
type LocalCopyDest struct{}
func (LocalCopyDest) Base ¶ added in v0.5.0
func (LocalCopyDest) Base(p string) string
func (LocalCopyDest) Dir ¶ added in v0.5.0
func (LocalCopyDest) Dir(p string) string
func (LocalCopyDest) Join ¶ added in v0.5.0
func (LocalCopyDest) Join(dir string, name string) string
func (LocalCopyDest) Mkdir ¶ added in v0.5.0
func (LocalCopyDest) Mkdir(p string, mode os.FileMode) error
func (LocalCopyDest) RemoveAll ¶ added in v0.5.0
func (LocalCopyDest) RemoveAll(p string) error
type LocalCopySource ¶ added in v0.5.0
type LocalCopySource struct{}
func (LocalCopySource) Open ¶ added in v0.5.0
func (LocalCopySource) Open(p string) (io.ReadCloser, error)