copyrec

package module
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2023 License: Apache-2.0 Imports: 11 Imported by: 1

README

Effective recursive file copying

Usage

Basic:

copyRec, err := copyrec.New(src, dest, copyrec.Options{})
if err != nil {
	return err
}

copyRec.Run(ctx)

Advanced:

uid, gid := uint32(1000), uint32(1000)

copyRec, err := copyrec.New(src, dest, copyrec.Options{
    UID: &uid,
    GID: &gid,
    MatchDir: func(path string) (copyrec.DirAction, error) {
        switch filepath.Base(path) {
        case "match-this-dir-fully":
            return copyrec.DirMatch, nil
        case "skip-this-dir":
            return copyrec.DirSkip, nil
        default:
            return copyrec.DirFallThrough, nil
        }
    },
    MatchFile: func(path string) (bool, error) {
        return filepath.Base(path) == "match-only-this-filename", nil
    },
})
if err != nil {
    return err
}

copyRec.Run(ctx)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CopyRecurse

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

func New

func New(src, dest string, opts Options) (*CopyRecurse, error)

func (*CopyRecurse) Run

func (c *CopyRecurse) Run(ctx context.Context) error

type DirAction

type DirAction int
const (
	DirMatch DirAction = iota
	DirFallThrough
	DirSkip
)

type Options

type Options struct {
	// Set UID for copied files/directories.
	UID *uint32

	// Set GID for copied files/directories.
	GID *uint32

	// Function decides should we match a directory while walking, fall through it to continue searching for matches or skip it.
	// If not defined, but matchFile is defined, then it always returns DirFallThrough.
	// If not defined and matchFile is undefined, then it always returns DirMatch.
	MatchDir func(path string) (DirAction, error)

	// Function decides whether should we match a file while walking.
	// If not defined, then it always returns true.
	MatchFile func(path string) (bool, error)

	AbortIfDestParentDirNotExists bool
}

Jump to

Keyboard shortcuts

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