will walk up the directory tree removing all encountered empty directories, not just the one containing this file
(fs billy.Filesystem, name string)
| 1051 | // will walk up the directory tree removing all encountered empty |
| 1052 | // directories, not just the one containing this file |
| 1053 | func rmFileAndDirsIfEmpty(fs billy.Filesystem, name string) error { |
| 1054 | if err := util.RemoveAll(fs, name); err != nil { |
| 1055 | return err |
| 1056 | } |
| 1057 | |
| 1058 | dir := filepath.Dir(name) |
| 1059 | for { |
| 1060 | removed, err := removeDirIfEmpty(fs, dir) |
| 1061 | if err != nil { |
| 1062 | return err |
| 1063 | } |
| 1064 | |
| 1065 | if !removed { |
| 1066 | // directory was not empty and not removed, |
| 1067 | // stop checking parents |
| 1068 | break |
| 1069 | } |
| 1070 | |
| 1071 | // move to parent directory |
| 1072 | dir = filepath.Dir(dir) |
| 1073 | } |
| 1074 | |
| 1075 | return nil |
| 1076 | } |
| 1077 | |
| 1078 | // removeDirIfEmpty will remove the supplied directory `dir` if |
| 1079 | // `dir` is empty |
no test coverage detected