vfs

package
v0.1.1-alpha Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitSudoClient

func InitSudoClient(appPath, askPass string)

InitSudoClient initializes the global SudoClient.

func IsTerminalRunnable

func IsTerminalRunnable(ctx context.Context, v VFS, path string) bool

IsTerminalRunnable checks if a file can be executed in the built-in terminal.

func RegisterProvider

func RegisterProvider(p VFSProvider)

func RunSudoAskpass

func RunSudoAskpass()

RunSudoAskpass is executed when f4 is called with --askpass flag by sudo -A. It connects back to the main f4 process to get the password from the UI.

func RunSudoDispatcher

func RunSudoDispatcher(sockPath string)

RunSudoDispatcher starts the elevated backend server loop. It is spawned by SudoClient via `sudo -A`.

Types

type App

type App interface {
	GetActivePanelVFS() VFS
	GetPassivePanelVFS() VFS
	GetSelectedNames() []string
	GetSelectedName() string
	RefreshAll()
	RunProgressTask(title, startMsg string, forked bool, worker func(ctx context.Context, update func(msg string, percent int)) error, onComplete func(err error))
	// UI Bridge
	Message(title, msg string, buttons []string) int
	InputBox(title, prompt, history string, callback func(string))
	Menu(title string, items []string, callback func(int))
}

App defines the interface for plugin-to-core UI interactions.

type FastScanner

type FastScanner interface {
	Scan(ctx context.Context, basePath string, names []string, cb ScanCallback) (OpStats, error)
}

FastScanner is an optional interface for VFS implementations. If a VFS implements this, it means it can offload the tree traversal to the remote server (e.g., FISH+), drastically reducing network roundtrips.

type HostAPI

type HostAPI interface {
	GetVersion() string
	Log(msg string)
	Message(msg string)

	RegisterHighlighter(p vtui.HighlighterProvider)
	RegisterVFSProvider(p VFSProvider)
	RegisterDrive(name string, factory func() VFS)
	RegisterGlobalHotkey(vk uint16, mods vtinput.ControlKeyState, handler func(app App))
	RegisterPluginMenuItem(label string, handler func(app App))
}

HostAPI defines the functions f4 exposes to plugins.

type NullVFS

type NullVFS struct {
	// contains filtered or unexported fields
}

NullVFS is a mock filesystem for testing UI responsiveness and file operations. It provides virtual files of specific sizes and discards any written data, simulating network or disk delays via a speed limit.

func NewNullVFS

func NewNullVFS(speedLimit int64) *NullVFS

NewNullVFS creates a new NullVFS with the specified speed limit in bytes per second.

func (*NullVFS) Abs

func (v *NullVFS) Abs(p string) (string, error)

func (*NullVFS) Base

func (v *NullVFS) Base(p string) string

func (*NullVFS) Clone

func (v *NullVFS) Clone() VFS

func (*NullVFS) Close

func (v *NullVFS) Close() error

func (*NullVFS) Create

func (v *NullVFS) Create(ctx context.Context, p string) (io.WriteCloser, error)

func (*NullVFS) Dir

func (v *NullVFS) Dir(p string) string

func (*NullVFS) GetCapabilities

func (v *NullVFS) GetCapabilities() VFSCapabilities

func (*NullVFS) GetPath

func (v *NullVFS) GetPath() string

func (*NullVFS) IsAtRoot

func (v *NullVFS) IsAtRoot() bool

func (*NullVFS) Join

func (v *NullVFS) Join(elem ...string) string

func (*NullVFS) MkDir

func (v *NullVFS) MkDir(ctx context.Context, p string) error

Mutations succeed silently

func (*NullVFS) Open

func (v *NullVFS) Open(ctx context.Context, p string) (ReadAtCloser, error)

func (*NullVFS) ParentVFS

func (v *NullVFS) ParentVFS() VFS

func (*NullVFS) ReadDir

func (v *NullVFS) ReadDir(ctx context.Context, p string, onChunk func([]VFSItem)) error

func (*NullVFS) Remove

func (v *NullVFS) Remove(ctx context.Context, p string) error

func (*NullVFS) Rename

func (v *NullVFS) Rename(ctx context.Context, old, new string) error

func (*NullVFS) Search

func (v *NullVFS) Search(ctx context.Context, p string, pattern string) (chan int64, error)

func (*NullVFS) SetAttributes

func (v *NullVFS) SetAttributes(ctx context.Context, path string, item VFSItem) error

func (*NullVFS) SetPath

func (v *NullVFS) SetPath(p string) error

func (*NullVFS) Stat

func (v *NullVFS) Stat(ctx context.Context, p string) (VFSItem, error)

type OSVFS

type OSVFS struct {
	// contains filtered or unexported fields
}

func NewOSVFS

func NewOSVFS(initialPath string) *OSVFS

func (*OSVFS) Abs

func (v *OSVFS) Abs(path string) (string, error)

func (*OSVFS) Base

func (v *OSVFS) Base(path string) string

func (*OSVFS) Clone

func (v *OSVFS) Clone() VFS

func (*OSVFS) Close

func (v *OSVFS) Close() error

func (*OSVFS) Create

func (v *OSVFS) Create(ctx context.Context, path string) (io.WriteCloser, error)

func (*OSVFS) Dir

func (v *OSVFS) Dir(path string) string

func (*OSVFS) GetCapabilities

func (v *OSVFS) GetCapabilities() VFSCapabilities

func (*OSVFS) GetPath

func (v *OSVFS) GetPath() string

func (*OSVFS) IsAtRoot

func (v *OSVFS) IsAtRoot() bool

func (*OSVFS) Join

func (v *OSVFS) Join(elem ...string) string

func (*OSVFS) MkDir

func (v *OSVFS) MkDir(ctx context.Context, path string) error

func (*OSVFS) Open

func (v *OSVFS) Open(ctx context.Context, path string) (ReadAtCloser, error)

func (*OSVFS) ParentVFS

func (v *OSVFS) ParentVFS() VFS

func (*OSVFS) ReadDir

func (v *OSVFS) ReadDir(ctx context.Context, path string, onChunk func([]VFSItem)) error

func (*OSVFS) Remove

func (v *OSVFS) Remove(ctx context.Context, path string) error

func (*OSVFS) Rename

func (v *OSVFS) Rename(ctx context.Context, old, new string) error

func (*OSVFS) Search

func (v *OSVFS) Search(ctx context.Context, path string, pattern string) (chan int64, error)

func (*OSVFS) SetAttributes

func (v *OSVFS) SetAttributes(ctx context.Context, path string, item VFSItem) error

func (*OSVFS) SetPath

func (v *OSVFS) SetPath(path string) error

func (*OSVFS) Stat

func (v *OSVFS) Stat(ctx context.Context, path string) (VFSItem, error)

type OpStats

type OpStats struct {
	Bytes int64
	Files int64
	Dirs  int64
}

OpStats holds detailed statistics about a file system subtree. Separating Files/Dirs from Bytes allows for highly accurate, non-linear ETA calculations during I/O operations.

func CalculateStats

func CalculateStats(ctx context.Context, v VFS, basePath string, names []string, cb ScanCallback) (OpStats, error)

CalculateStats is the main entry point for gathering operation statistics. It uses FastScanner if available, otherwise falls back to GenericScan.

func GenericScan

func GenericScan(ctx context.Context, v VFS, basePath string, names []string, cb ScanCallback) (OpStats, error)

GenericScan performs a recursive, client-side tree traversal to gather stats.

func (*OpStats) Add

func (s *OpStats) Add(other OpStats)

Add merges another OpStats into the current one.

type PtyProvider

type PtyProvider interface {
	OpenPty(cols, rows int) (any, error)
}

PtyProvider allows a VFS to provide its own PTY implementation (e.g. an SSH session for remote systems).

type ReadAtCloser

type ReadAtCloser interface {
	ReadAt(ctx context.Context, p []byte, off int64) (n int, err error)
	Read(ctx context.Context, p []byte) (n int, err error)
	io.Closer
	Size() int64

} // TempFileWrapper is a helper for VFS that need to extract files to temp storage.

ReadAtCloser combines reader interfaces with context support.

type ScanCallback

type ScanCallback func(currentPath string, stats OpStats)

ScanCallback is used to report progress during a long scanning operation. It returns the path currently being inspected and the accumulated stats so far.

type SudoClient

type SudoClient struct {
	// contains filtered or unexported fields
}

SudoClient manages a persistent connection to the elevated f4 dispatcher.

func GetSudoClient

func GetSudoClient() *SudoClient

GetSudoClient returns the global instance.

func (*SudoClient) Connect

func (c *SudoClient) Connect() error

Connect attempts to start the elevated dispatcher via sudo and connect to its socket.

func (*SudoClient) IsAvailable

func (c *SudoClient) IsAvailable() bool

IsAvailable checks if the SudoClient has been initialized.

func (*SudoClient) MkDir

func (c *SudoClient) MkDir(path string, mode uint32) error

func (*SudoClient) Open

func (c *SudoClient) Open(path string, flags int, mode uint32) (*os.File, error)

Open uses SudoClient to securely fetch a File Descriptor to a protected file.

func (*SudoClient) ReadDir

func (c *SudoClient) ReadDir(path string) ([]VFSItem, error)

func (*SudoClient) Remove

func (c *SudoClient) Remove(path string) error

func (*SudoClient) Rename

func (c *SudoClient) Rename(oldPath, newPath string) error

func (*SudoClient) RunOnUI

func (c *SudoClient) RunOnUI(fn func())

Dummy for SudoClient to satisfy RunOnUI if not imported

func (*SudoClient) SendRequest

func (c *SudoClient) SendRequest(req SudoRequest) (SudoResponse, *os.File, error)

SendRequest sends a command to the dispatcher and waits for the response.

func (*SudoClient) SetAttributes

func (c *SudoClient) SetAttributes(path string, item VFSItem) error

func (*SudoClient) Stat

func (c *SudoClient) Stat(path string) (VFSItem, error)

type SudoCommand

type SudoCommand byte
const (
	CmdPing SudoCommand = iota
	CmdOpen
	CmdCreate
	CmdStat
	CmdReadDir
	CmdMkDir
	CmdRemove
	CmdRename
	CmdSetAttributes
)

type SudoRequest

type SudoRequest struct {
	Cmd   SudoCommand
	Path  string
	Path2 string  // Used for rename
	Flags int     // OS flags (e.g. O_RDONLY)
	Mode  uint32  // File permissions
	Item  VFSItem // Used for SetAttributes
}

type SudoResponse

type SudoResponse struct {
	Error string
	Item  VFSItem
	Items []VFSItem
	IsEOF bool
}

type TempFileWrapper

type TempFileWrapper struct {
	*os.File
	SizeVal  int64
	TempPath string
}

func (*TempFileWrapper) Read

func (w *TempFileWrapper) Read(ctx context.Context, p []byte) (int, error)

func (*TempFileWrapper) ReadAt

func (w *TempFileWrapper) ReadAt(ctx context.Context, p []byte, off int64) (int, error)

func (*TempFileWrapper) Size

func (w *TempFileWrapper) Size() int64

type VFS

type VFS interface {
	IsAtRoot() bool
	GetPath() string
	SetPath(path string) error
	ReadDir(ctx context.Context, path string, onChunk func([]VFSItem)) error
	Stat(ctx context.Context, path string) (VFSItem, error)
	Join(elem ...string) string
	Abs(path string) (string, error)
	Base(path string) string
	Dir(path string) string

	// Mutations
	MkDir(ctx context.Context, path string) error
	Remove(ctx context.Context, path string) error
	Rename(ctx context.Context, oldpath, newpath string) error

	// Advanced / Remote Operations
	GetCapabilities() VFSCapabilities
	Search(ctx context.Context, path string, pattern string) (chan int64, error)

	// Random Access (required for high-performance Viewer/Editor)
	// Open returns a ReadAtCloser for the file.
	Open(ctx context.Context, path string) (ReadAtCloser, error)

	// Create returns a WriteCloser for new files.
	Create(ctx context.Context, path string) (io.WriteCloser, error)

	// SetAttributes updates file metadata (mode, ownership, times)
	SetAttributes(ctx context.Context, path string, item VFSItem) error

	ParentVFS() VFS // Returns the underlying VFS if this is a virtual mount, or nil

	Clone() VFS
	Close() error
}

VFS is the core interface for file operations in f4.

type VFSCapabilities

type VFSCapabilities struct {
	HasServerSideCopy bool
	HasServerSideMove bool
	HasRandomAccess   bool // Supports ReadAt
	HasSearch         bool // Supports server-side search
}

VFSCapabilities defines what the current VFS implementation can do efficiently.

type VFSItem

type VFSItem struct {
	Name         string
	Size         int64
	IsDir        bool
	MTime        time.Time
	Mode         string
	IsExecutable bool
	IsHidden     bool
	// Metadata for Attributes dialog
	ATime    time.Time // Last Access
	CTime    time.Time // Creation (Win) or Status Change (Unix)
	UnixMode uint32    // Raw numeric mode for chmod
	Uid, Gid int       // Ownership
}

VFSItem represents a generic file or directory entry.

type VFSProvider

type VFSProvider interface {
	Name() string
	// Priority: чем выше, тем раньше провайдер опрашивается (архивы обычно имеют низкий приоритет)
	Priority() int
	// CanOpen возвращает true, если провайдер понимает этот путь.
	// parent — текущая VFS, в которой находится объект.
	CanOpen(ctx context.Context, parent VFS, path string) bool
	// Open создает новый экземпляр VFS.
	Open(ctx context.Context, parent VFS, path string) (VFS, error)
}

VFSProvider умеет определять, может ли он открыть путь, и создавать экземпляр VFS.

func FindProvider

func FindProvider(ctx context.Context, parent VFS, path string) VFSProvider

Jump to

Keyboard shortcuts

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