watchdrain

package module
v0.0.0-...-61bbbae Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 8 Imported by: 0

README

watchdrain is a simple command line tool that monitors a directory until it is empty of files.

I wrote it as an exercise to experiment with Go channels, goroutines, and testing in Go.

How to Install

Using go run

git clone https://github.com/mabego/watchdrain.git
cd watchdrain
go run ./cmd/watchdrain/main.go <dir>

Building a binary

git clone https://github.com/mabego/watchdrain.git
cd watchdrain
sudo go build -o /usr/local/bin/watchdrain ./cmd/watchdrain/
watchdrain <dir>

CLI Options

watchdrain -h
watchdrain watches a directory until it is empty of files
Usage of watchdrain:
watchdrain <dir>
  -threshold uint
        Stop watching a directory if file create events exceed remove events by a threshold
        threshold = create events - remove events
        The lowest threshold is 1. Increase to allow more create events while watching.
  -timer duration
        Set a timer. Default is 5 minutes. (default 5m0s)
  -v    Log file create and remove events
watchdrain -timer 1m -threshold 1 -v <dir>

Documentation

Index

Constants

View Source
const (
	Create event = iota
	Remove
)

Events that trigger a notification to eventCh

Variables

View Source
var (
	// ErrThresholdExceeded is returned when file creation events exceed removal events by a set threshold
	ErrThresholdExceeded = errors.New("threshold exceeded")
	ErrTimerEnded        = errors.New("timer ended")
)

Functions

This section is empty.

Types

type Dir

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

Dir represents a directory to watch drain of files

func NewDir

func NewDir(dirName string) (*Dir, error)

NewDir returns a new Dir to watch drain

func (*Dir) WatchDrain

func (d *Dir) WatchDrain(opt *Options) (bool, error)

WatchDrain watches a directory until it is empty of files or a timer ends or a threshold is exceeded

type Options

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

Options for WatchDrain

func NewOptions

func NewOptions(timer time.Duration, threshold uint, verbose bool) *Options

NewOptions returns Options, including an eventCh channel if a threshold is set

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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