remote

package
v1.35.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: GPL-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package remote implements fsops.Backend over SFTP, on the pooled SSH connection the instance's stored credentials open. Reflinks have no sftp operation and answer fsops.ErrUnsupported, and hardlinks need the server to advertise hardlink@openssh.com. File identity needs the exec tier, where GNU stat and find run as remote commands. Remote paths are slash-delimited, so this package uses path and never path/filepath: the separator belongs to the remote host, not to ours.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

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

Backend implements fsops.Backend for one instance over SFTP. It holds no connection of its own: the pool owns those, so a backend is cheap to build per resolution and safe to discard.

func New

func New(pool *sshpool.Pool, inst *models.Instance) *Backend

func (*Backend) HardlinkTree

func (b *Backend) HardlinkTree(ctx context.Context, plan *hardlinktree.TreePlan) (*fsops.TreeCreateResult, error)

HardlinkTree mirrors hardlinktree.Create. A target that already exists is skipped when targetIsSource can prove it is a link to the source, which needs the exec tier; the sftp tier refuses it, since its attrs carry no inode to tell that link from a stranger's file (fsops.Backend states the contract).

func (*Backend) Lstat

func (b *Backend) Lstat(ctx context.Context, p string) (*fsops.LstatInfo, error)

func (*Backend) LstatBatch added in v1.33.0

func (b *Backend) LstatBatch(ctx context.Context, paths []string) ([]*fsops.LstatInfo, []error)

LstatBatch answers fsops.BatchStater. On the exec tier, one find lstats a batch of paths, with identity, in two round trips. Lstat answers each path that find did not print, such as a missing one, so the error is the one Lstat gives. On the sftp tier, Lstat answers every path. The single Lstat calls run batchWidth at a time.

The paths must be absolute: find reads an argument that starts with "-", "!" or "(" as an expression.

func (*Backend) Mkdir added in v1.34.0

func (b *Backend) Mkdir(ctx context.Context, p string, _ fs.FileMode) error

Mkdir ignores perm, as MkdirAll does. The server answers SSH_FX_FAILURE for an existing path, so an lstat names that cause as fs.ErrExist.

func (*Backend) MkdirAll

func (b *Backend) MkdirAll(ctx context.Context, p string, _ fs.FileMode) error

MkdirAll ignores perm: pkg/sftp sends SSH_FXP_MKDIR with empty attrs, so the server's umask decides, the way it does for every file sftp creates.

func (*Backend) Paths

func (b *Backend) Paths() fsops.PathDialect

func (*Backend) ReadDir

func (b *Backend) ReadDir(ctx context.Context, p string) ([]fsops.DirEntry, error)

func (*Backend) ReflinkTree

func (*Backend) Remove

func (b *Backend) Remove(ctx context.Context, p string, opts fsops.RemoveOptions) error

func (*Backend) RemoveTree

func (b *Backend) RemoveTree(ctx context.Context, created *fsops.TreeCreateResult) error

RemoveTree is hardlinktree.Created.Rollback over sftp: each recorded file is unlinked, each recorded directory removed deepest first and only when empty, so a directory that gained a sibling torrent's files stays. The algorithm is repeated rather than shared because the local one is bound to os.Remove and an errno; a second copy is smaller than the seam.

func (*Backend) SameFilesystem

func (b *Backend) SameFilesystem(ctx context.Context, p1, p2 string) (bool, error)

func (*Backend) Stat

func (b *Backend) Stat(ctx context.Context, p string) (*fsops.LstatInfo, error)

func (*Backend) StatBatch added in v1.33.0

func (b *Backend) StatBatch(ctx context.Context, paths []string) ([]*fsops.LstatInfo, []error)

StatBatch answers fsops.BatchStater. It is LstatBatch, but it follows symlinks, as Stat does.

func (*Backend) Statfs

func (b *Backend) Statfs(ctx context.Context, p string) (*fsops.StatfsResult, error)
func (b *Backend) SupportsReflink(ctx context.Context, _ string) (bool, string, error)

func (*Backend) WalkDir

func (b *Backend) WalkDir(ctx context.Context, root string, opts fsops.WalkOptions) (<-chan fsops.WalkEntry, error)

Jump to

Keyboard shortcuts

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