copier

package
v0.0.0-...-1dd1f65 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package copier provides a mockable interface for network-transparent(ish) file copying, and implementations thereof.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyMapping

func CopyMapping(ctx context.Context, dst, src Copier, mapping map[string]string, o ...Observer) error

CopyMapping copies the files in the (dest-to-src) map mapping from dst to src. It checks ctx for cancellation between operations.

func OnCopy

func OnCopy(m Message, cos ...Observer)

OnCopy sends an OnCopyStep observation to multiple observers.

func OnCopyEnd

func OnCopyEnd(cos ...Observer)

OnCopyEnd sends an OnCopyEnd observation to multiple observers.

func OnCopyStart

func OnCopyStart(nfiles int, cos ...Observer)

OnCopyStart sends an OnCopyStart observation to multiple observers.

func OnCopyStep

func OnCopyStep(i int, dst, src string, cos ...Observer)

OnCopyStep sends an OnCopyStep observation to multiple observers.

func RecvMapping

func RecvMapping(ctx context.Context, src Copier, mapping map[string]string, o ...Observer) error

RecvMapping is shorthand for CopyMapping where the source is a Local.

func SendMapping

func SendMapping(ctx context.Context, dst Copier, mapping map[string]string, o ...Observer) error

SendMapping is shorthand for CopyMapping where the source is a Local.

Types

type Copier

type Copier interface {
	// Create tries to create a file at path, and, if successful, opens a write-closer pointing to it.
	Create(path string) (io.WriteCloser, error)
	// Open tries to open a file at path, and, if successful, opens a read-closer pointing to it.
	Open(path string) (io.ReadCloser, error)
	// MkdirAll recursively makes the directories mentioned in dir.
	MkdirAll(dir string) error
}

Copier provides a mockable interface for remote copying.

type Local

type Local struct{}

Local implements Copier through os.

func (Local) Create

func (l Local) Create(path string) (io.WriteCloser, error)

Create calls os.Create on path.

func (Local) MkdirAll

func (l Local) MkdirAll(dir string) error

MkdirAll calls os.MkdirAll on path, with vaguely sensible permissions.

func (Local) Open

func (l Local) Open(path string) (io.ReadCloser, error)

Open calls os.Open on path.

type Message

type Message struct {
	observing.Batch

	// Dst is the name of the destination file, if we're on a step.
	Dst string `json:"dst,omitempty"`

	// Src is the name of the source file, if we're on a step.
	Src string `json:"src,omitempty"`
}

Message is the type of copy observation messages.

type Observer

type Observer interface {
	// OnCopy sends a copy observation message.
	OnCopy(Message)
}

Observer is an interface for types that observe an SFTP file copy.

type SFTP

type SFTP sftp.Client

SFTP wraps an sftp.Client to adapt it to the Copier interface.

func (*SFTP) Create

func (s *SFTP) Create(path string) (io.WriteCloser, error)

Create wraps sftp.Client's Create in such a way as to implement Copier.

func (*SFTP) MkdirAll

func (s *SFTP) MkdirAll(dir string) error

MkdirAll wraps sftp.Client's MkdirAll in such a way as to implement Copier.

func (*SFTP) Open

func (s *SFTP) Open(path string) (io.ReadCloser, error)

Open wraps sftp.Client's Open in such a way as to implement Copier.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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