acp

package module
v0.0.0-...-af05f05 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: BSD-2-Clause Imports: 29 Imported by: 3

README

acp

An Advanced Copy Tools, with following extra features:

  • Process bar
  • Sorted copy order, to improve tape device read performance
  • Multi target path, read once write many
  • Read file with mmap, with small file prefetch hint
  • JSON format job report
  • Can use as a golang library

Install

# Install acp
go install github.com/samuelncui/acp/cmd/acp

Usage

Usage of acp:
  -n    do not overwrite exist file
  -notarget
        do not have target, use as dir index tool
  -report string
        json report storage path
  -target value
        use target flag to give multi target path

Example

# copy `example` dir to `target` dir
acp example target/

# copy `example` dir to `target` dir, and output a report to `report.json`
acp -report report.json example target/

# copy `example` dir to `target1` and `target2` dir
acp example -target target1 -target target2

# do not copy, just get a dir index, write to `report.json`
acp example -notarget -report report.json

Documentation

Index

Constants

View Source
const (
	JobStatusPending   = "pending"
	JobStatusPreparing = "preparing"
	JobStatusCopying   = "copying"
	JobStatusFinishing = "finishing"
	JobStatusFinished  = "finished"
)
View Source
const (
	UnexpectFileMode = os.ModeType &^ os.ModeDir
)

Variables

View Source
var (
	ErrTargetNoSpace        = fmt.Errorf("acp: target have no space")
	ErrTargetDropToReadonly = fmt.Errorf("acp: target droped into readonly")
)

Functions

func Cache

func Cache[K comparable, V any](f func(in K) V) func(in K) V

func NewReportGetter

func NewReportGetter() (EventHandler, ReportGetter)

Types

type Copyer

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

func New

func New(ctx context.Context, opts ...Option) (*Copyer, error)

func (*Copyer) Wait

func (c *Copyer) Wait()

type DeviceOption

type DeviceOption func(*deviceOption) *deviceOption

func DeviceThreads

func DeviceThreads(threads int) DeviceOption

func LinearDevice

func LinearDevice(b bool) DeviceOption

type Error

type Error struct {
	Src string `json:"src,omitempty"`
	Dst string `json:"dst,omitempty"`
	Err error  `json:"error,omitempty"`
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) MarshalJSON

func (e *Error) MarshalJSON() ([]byte, error)

func (*Error) UnmarshalJSON

func (e *Error) UnmarshalJSON(buf []byte) error

type Event

type Event interface {
	// contains filtered or unexported methods
}

type EventFinished

type EventFinished struct{}

type EventHandler

type EventHandler func(Event)

func NewProgressBar

func NewProgressBar() EventHandler

type EventReportError

type EventReportError struct {
	Error *Error
}

type EventUpdateCount

type EventUpdateCount struct {
	Bytes, Files int64
	Finished     bool
}

type EventUpdateJob

type EventUpdateJob struct {
	Job *Job
}

type EventUpdateProgress

type EventUpdateProgress struct {
	Bytes, Files int64
	Finished     bool
}

type Job

type Job struct {
	Base string   `json:"base"`
	Path []string `json:"path"`

	Status         string           `json:"status"`
	SuccessTargets []string         `json:"success_target,omitempty"`
	FailTargets    map[string]error `json:"fail_target,omitempty"`

	Size      int64       `json:"size"`
	Mode      fs.FileMode `json:"mode"`
	ModTime   time.Time   `json:"mod_time"`
	WriteTime time.Time   `json:"write_time"`
	SHA256    string      `json:"sha256"`
}

type Option

type Option func(*option) *option

func AccurateJob

func AccurateJob(src string, dsts []string) Option

func Overwrite

func Overwrite(b bool) Option

func SetFromDevice

func SetFromDevice(opts ...DeviceOption) Option

func SetToDevice

func SetToDevice(opts ...DeviceOption) Option

func WildcardJob

func WildcardJob(opts ...WildcardJobOption) Option

func WithEventHandler

func WithEventHandler(h EventHandler) Option

func WithHash

func WithHash(b bool) Option

func WithLogger

func WithLogger(logger *logrus.Logger) Option

func WithProgressBar

func WithProgressBar() Option

type Report

type Report struct {
	Jobs   []*Job   `json:"files,omitempty"`
	Errors []*Error `json:"errors,omitempty"`
}

func (*Report) ToJSONString

func (r *Report) ToJSONString(indent bool) string

type ReportGetter

type ReportGetter func() *Report

type WildcardJobOption

type WildcardJobOption func(*wildcardJob) *wildcardJob

func AccurateSource

func AccurateSource(base string, paths ...[]string) WildcardJobOption

func Source

func Source(paths ...string) WildcardJobOption

func Target

func Target(paths ...string) WildcardJobOption

Directories

Path Synopsis
cmd
acp
Package mmap provides a way to memory-map a file.
Package mmap provides a way to memory-map a file.

Jump to

Keyboard shortcuts

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