2 goredo -- redo implementation on pure Go
3 Copyright (C) 2020 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
35 func redoDirClean(root, what string) error {
36 root, err := filepath.Abs(root)
40 dir, err := os.Open(root)
45 fis, err := dir.Readdir(1 << 10)
53 for _, fi := range fis {
54 pth = cwdMustRel(root, fi.Name())
57 if strings.HasSuffix(fi.Name(), LogSuffix) {
59 if err = os.Remove(pth); err != nil {
64 if strings.HasPrefix(fi.Name(), TmpPrefix) {
66 if err = os.Remove(pth); err != nil {
71 log.Fatalln("unknown cleanup target")
78 func cleanupWalker(root, what string) error {
79 root, err := filepath.Abs(root)
83 dir, err := os.Open(root)
89 fis, err := dir.Readdir(1 << 10)
97 for _, fi := range fis {
98 pth = cwdMustRel(root, fi.Name())
100 if fi.Name() == RedoDir {
101 if what == CleanupFull {
103 err = os.RemoveAll(pth)
105 err = redoDirClean(pth, what)
108 err = cleanupWalker(pth, what)
115 if (what == CleanupTmp || what == CleanupFull) &&
116 strings.HasPrefix(fi.Name(), TmpPrefix) {
118 if err = os.Remove(pth); err != nil {