aboutsummaryrefslogtreecommitdiff
path: root/common.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2018-05-26 20:31:05 +0700
committerShulhan <ms@kilabit.info>2018-05-27 02:12:39 +0700
commitf39c1b5787f5408c8720b2b80f9208d86e2d8e00 (patch)
treee0c9e4e2639aa438ccd12e48e3736178039ebcfb /common.go
parent78690021d83ed5e4ca9dac0eb37da730faf5df22 (diff)
downloadbeku-f39c1b5787f5408c8720b2b80f9208d86e2d8e00.tar.xz
env.Remove: remove empty directory recursively on "src" and "pkg"
Diffstat (limited to 'common.go')
-rw-r--r--common.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/common.go b/common.go
index c4015c4..3630699 100644
--- a/common.go
+++ b/common.go
@@ -10,6 +10,7 @@ import (
"fmt"
"io"
"os"
+ "path/filepath"
"strings"
)
@@ -72,6 +73,32 @@ func IsTagVersion(version string) bool {
}
//
+// RmdirEmptyAll remove directory in path if it's empty until one of the
+// parent is not empty.
+//
+func RmdirEmptyAll(path string) error {
+ if len(path) == 0 {
+ return nil
+ }
+ fi, err := os.Stat(path)
+ if err != nil {
+ return RmdirEmptyAll(filepath.Dir(path))
+ }
+ if !fi.IsDir() {
+ return nil
+ }
+ if !IsDirEmpty(path) {
+ return nil
+ }
+ err = os.Remove(path)
+ if err != nil {
+ return err
+ }
+
+ return RmdirEmptyAll(filepath.Dir(path))
+}
+
+//
// confirm display a question to standard output and read for answer
// from "in" for simple "y" or "n" answer.
// If "in" is nil, it will set to standard input.