diff options
| author | Shulhan <ms@kilabit.info> | 2018-05-26 20:31:05 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2018-05-27 02:12:39 +0700 |
| commit | f39c1b5787f5408c8720b2b80f9208d86e2d8e00 (patch) | |
| tree | e0c9e4e2639aa438ccd12e48e3736178039ebcfb /common.go | |
| parent | 78690021d83ed5e4ca9dac0eb37da730faf5df22 (diff) | |
| download | beku-f39c1b5787f5408c8720b2b80f9208d86e2d8e00.tar.xz | |
env.Remove: remove empty directory recursively on "src" and "pkg"
Diffstat (limited to 'common.go')
| -rw-r--r-- | common.go | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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. |
