/*
goredo -- djb's redo implementation on pure Go
-Copyright (C) 2020-2021 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2020-2023 Sergey Matveev <stargrave@stargrave.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
CleanupFull = "full"
CleanupLog = "log"
CleanupTmp = "tmp"
+ CleanupLock = "lock"
)
var DryRun *bool
if err != nil {
return err
}
+ defer dir.Close()
for {
- fis, err := dir.Readdir(1 << 10)
+ entries, err := dir.ReadDir(1 << 10)
if err != nil {
if err == io.EOF {
break
return err
}
var pth string
- for _, fi := range fis {
- pth = cwdMustRel(root, fi.Name())
+ for _, entry := range entries {
+ pth = cwdMustRel(root, entry.Name())
switch what {
case CleanupLog:
- if strings.HasSuffix(fi.Name(), LogSuffix) ||
- strings.HasSuffix(fi.Name(), LogRecSuffix) {
+ if strings.HasSuffix(entry.Name(), LogSuffix) ||
+ strings.HasSuffix(entry.Name(), LogRecSuffix) {
+ fmt.Println(pth)
+ if !*DryRun {
+ if err = os.Remove(pth); err != nil {
+ return err
+ }
+ }
+ }
+ case CleanupLock:
+ if strings.HasSuffix(entry.Name(), LockSuffix) {
fmt.Println(pth)
if !*DryRun {
if err = os.Remove(pth); err != nil {
}
}
case CleanupTmp:
- if strings.HasPrefix(fi.Name(), TmpPrefix) {
+ if strings.HasPrefix(entry.Name(), TmpPrefix) {
fmt.Println(pth)
if !*DryRun {
if err = os.Remove(pth); err != nil {
}
}
}
- return dir.Close()
+ return nil
}
func cleanupWalker(root, what string) error {
}
defer dir.Close()
for {
- fis, err := dir.Readdir(1 << 10)
+ entries, err := dir.ReadDir(1 << 10)
if err != nil {
if err == io.EOF {
break
}
return err
}
- for _, fi := range fis {
- pth := path.Join(root, fi.Name())
- pthRel := cwdMustRel(root, fi.Name())
- if fi.IsDir() {
- if fi.Name() == RedoDir {
+ for _, entry := range entries {
+ pth := path.Join(root, entry.Name())
+ pthRel := cwdMustRel(root, entry.Name())
+ if entry.IsDir() {
+ if entry.Name() == RedoDir {
if what == CleanupFull {
fmt.Println(pthRel)
if !*DryRun {
} else {
err = redoDirClean(pth, what)
}
+ } else if (what == CleanupTmp || what == CleanupFull) &&
+ strings.HasPrefix(entry.Name(), TmpPrefix) {
+ fmt.Println(pthRel)
+ if !*DryRun {
+ err = os.RemoveAll(pth)
+ }
} else {
err = cleanupWalker(pth, what)
}
continue
}
if (what == CleanupTmp || what == CleanupFull) &&
- strings.HasPrefix(fi.Name(), TmpPrefix) {
+ strings.HasPrefix(entry.Name(), TmpPrefix) {
fmt.Println(pthRel)
if !*DryRun {
if err = os.Remove(pth); err != nil {
}
}
}
- return dir.Close()
+ return nil
}