lazymove

package module
Version: v0.0.0-...-79d437e Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2020 License: MIT Imports: 10 Imported by: 0

README

GoDoc

lazymove

Lazily move files from one directory to another. This is useful when you have slower long-term storage but want to be able to write new files quickly. You can write to the fast disk, and use lazymove to lazily and asynchronously move the files to the slower storage, such as a network mount.

See godoc for API usage, or use the command:

Usage: ./lazymove [Options...] <SourceDir> <DestDir>
Options:
  -minDirAge duration
    	Minimum age to remove empty dirs (default 1h0m0s)
  -minFileAge duration
    	Minimum age to move files (default 5m0s)
  -timeout duration
    	How often to look for files to move (default 5m0s)

The mover will lazily move files from SourceDir into DestDir. It will do this move iteration each timeout, only moving (copy, delete) files from SourceDir to DestDir with modification times older than minFileAge, and only removing empty directories from SourceDir with times older than minDirAge.

Documentation

Index

Constants

View Source
const (
	// DefaultTimeout is the default value for Mover.Timeout
	DefaultTimeout = 5 * time.Minute
	// DefaultMinFileAge is the default value for Mover.MinFileAge
	DefaultMinFileAge = 5 * time.Minute
	// DefaultMinDirAge is the default value for Mover.MinDirAge
	DefaultMinDirAge = time.Hour
)

Variables

This section is empty.

Functions

func DefaultErrorFunc

func DefaultErrorFunc(m *Mover, err error) (resume bool)

DefaultErrorFunc is the default function for Mover.ErrorFunc, it logs to log.Printf and returns resume=true.

Types

type MoveAbortedError

type MoveAbortedError struct {
	Mover *Mover
	Err   error // what caused the abort
}

MoveAbortedError is used with Mover.ErrorFunc, see Mover for more info. Mover is the *Mover that was aborted, and Err is the error that aborted the interation. Note that this intentionally does not Unwrap Err.

func (*MoveAbortedError) Error

func (err *MoveAbortedError) Error() string

type Mover

type Mover struct {
	SourceDir  string
	DestDir    string
	Timeout    time.Duration                     // default is DefaultTimeout
	MinFileAge time.Duration                     // default is DefaultMinFileAge
	MinDirAge  time.Duration                     // default is DefaultMinDirAge
	ErrorFunc  func(*Mover, error) (resume bool) // default is DefaultErrorFunc
	// contains filtered or unexported fields
}

Mover will lazily move files from SourceDir into DestDir. It will do this iteration each Timeout, only moving files with modification times older than MinFileAge, and only removing empty directories with times older than MinDirAge. ErrorFunc is called on any errors that occur during a move, true can be returned to resume moving, or false to abort. If ErrorFunc returns false, it aborts the rest of the move iteration, and it is called again with a *MoveAbortedError, in this case the return value controls whether Run will resume or return. Behavior is undefined if SourceDir refers to the same location as DestDir. Do not modify fields after calling Run.

func (*Mover) Run

func (m *Mover) Run(ctx context.Context) error

Run the mover. Returns if the ctx is done, or ErrorFunc says so (see Mover)

Source Files

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL