118 lines
2.6 KiB
Go
118 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
tarGzSuffix = ".tar.gz"
|
|
defaultListen = "127.0.0.1:18080"
|
|
defaultInterval = 15 * time.Second
|
|
defaultStableFor = 30 * time.Second
|
|
maxLogLines = 200
|
|
settingsFileName = "unc_tar_watcher_settings.json"
|
|
genericDedupeNameSize = "name_size"
|
|
genericDedupeNameHash = "name_hash"
|
|
)
|
|
|
|
type archiveRule struct {
|
|
enabled bool
|
|
sourceDir string
|
|
zipDir string
|
|
unzipDir string
|
|
}
|
|
|
|
type genericRule struct {
|
|
enabled bool
|
|
sourceDir string
|
|
targetDir string
|
|
extensions []string
|
|
dedupeMode string
|
|
}
|
|
|
|
type config struct {
|
|
interval time.Duration
|
|
stableFor time.Duration
|
|
stableScans int
|
|
mode string
|
|
recursive bool
|
|
archive archiveRule
|
|
generic genericRule
|
|
}
|
|
|
|
type fileSnapshot struct {
|
|
size int64
|
|
modTime time.Time
|
|
}
|
|
|
|
type fileState struct {
|
|
lastObserved fileSnapshot
|
|
stableCount int
|
|
handledKey string
|
|
lastDecision string
|
|
}
|
|
|
|
type candidate struct {
|
|
path string
|
|
info os.FileInfo
|
|
}
|
|
|
|
type formValues struct {
|
|
ArchiveEnabled bool `json:"archive_enabled"`
|
|
ArchiveSourceDir string `json:"archive_source_dir"`
|
|
ArchiveZipDir string `json:"archive_zip_dir"`
|
|
ArchiveUnzipDir string `json:"archive_unzip_dir"`
|
|
GenericEnabled bool `json:"generic_enabled"`
|
|
GenericSourceDir string `json:"generic_source_dir"`
|
|
GenericTargetDir string `json:"generic_target_dir"`
|
|
GenericExts string `json:"generic_exts"`
|
|
GenericDedupe string `json:"generic_dedupe"`
|
|
Interval string `json:"interval"`
|
|
StableFor string `json:"stable_for"`
|
|
StableScans string `json:"stable_scans"`
|
|
Mode string `json:"mode"`
|
|
Recursive bool `json:"recursive"`
|
|
}
|
|
|
|
type legacyFormValues struct {
|
|
SourceDir string `json:"source_dir"`
|
|
ZipDir string `json:"zip_dir"`
|
|
UnzipDir string `json:"unzip_dir"`
|
|
Interval string `json:"interval"`
|
|
StableFor string `json:"stable_for"`
|
|
StableScans string `json:"stable_scans"`
|
|
Mode string `json:"mode"`
|
|
Recursive bool `json:"recursive"`
|
|
}
|
|
|
|
type pageData struct {
|
|
Running bool
|
|
StartedAt string
|
|
LastMessage string
|
|
LastError string
|
|
SubmitMessage string
|
|
SubmitError string
|
|
SettingsPath string
|
|
Form formValues
|
|
Logs []string
|
|
}
|
|
|
|
type app struct {
|
|
mu sync.RWMutex
|
|
cancel context.CancelFunc
|
|
runID int64
|
|
running bool
|
|
startedAt time.Time
|
|
lastMessage string
|
|
lastError string
|
|
cfg config
|
|
form formValues
|
|
logs []string
|
|
settingsPath string
|
|
}
|
|
|
|
type processFunc func(string) (string, bool, error)
|