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/>.
36 func redoDirClean(root, what string) error {
37 root, err := filepath.Abs(root)
41 dir, err := os.Open(root)
46 fis, err := dir.Readdir(1 << 10)
54 for _, fi := range fis {
55 pth = cwdMustRel(root, fi.Name())
58 if strings.HasSuffix(fi.Name(), LogSuffix) {
60 if err = os.Remove(pth); err != nil {
65 if strings.HasPrefix(fi.Name(), TmpPrefix) {
67 if err = os.Remove(pth); err != nil {
72 log.Fatalln("unknown cleanup target")
79 func cleanupWalker(root, what string) error {
80 root, err := filepath.Abs(root)
84 dir, err := os.Open(root)
90 fis, err := dir.Readdir(1 << 10)
97 for _, fi := range fis {
98 pth := path.Join(root, fi.Name())
99 pthRel := cwdMustRel(root, fi.Name())
101 if fi.Name() == RedoDir {
102 if what == CleanupFull {
104 err = os.RemoveAll(pth)
106 err = redoDirClean(pth, what)
109 err = cleanupWalker(pth, what)
116 if (what == CleanupTmp || what == CleanupFull) &&
117 strings.HasPrefix(fi.Name(), TmpPrefix) {
119 if err = os.Remove(pth); err != nil {