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, err = filepath.Rel(Cwd, path.Join(root, fi.Name()))
61 if strings.HasSuffix(fi.Name(), LogSuffix) {
63 if err = os.Remove(pth); err != nil {
68 if strings.HasPrefix(fi.Name(), TmpPrefix) {
70 if err = os.Remove(pth); err != nil {
75 log.Fatalln("unknown cleanup target")
82 func cleanupWalker(root, what string) error {
83 root, err := filepath.Abs(root)
87 dir, err := os.Open(root)
93 fis, err := dir.Readdir(1 << 10)
101 for _, fi := range fis {
102 pth, err = filepath.Rel(Cwd, path.Join(root, fi.Name()))
107 if fi.Name() == RedoDir {
108 if what == CleanupFull {
110 err = os.RemoveAll(pth)
112 err = redoDirClean(pth, what)
115 err = cleanupWalker(pth, what)
122 if (what == CleanupTmp || what == CleanupFull) &&
123 strings.HasPrefix(fi.Name(), TmpPrefix) {
125 if err = os.Remove(pth); err != nil {