will walk up the directory tree removing all encountered empty directories, not just the one containing this file
(fs billy.Filesystem, name string)
| 1024 | // will walk up the directory tree removing all encountered empty |
| 1025 | // directories, not just the one containing this file |
| 1026 | func rmFileAndDirsIfEmpty(fs billy.Filesystem, name string) error { |
| 1027 | if err := util.RemoveAll(fs, name); err != nil { |
| 1028 | return err |
| 1029 | } |
| 1030 | |
| 1031 | dir := filepath.Dir(name) |
| 1032 | for { |
| 1033 | removed, err := removeDirIfEmpty(fs, dir) |
| 1034 | if err != nil && !os.IsNotExist(err) { |
| 1035 | return err |
| 1036 | } |
| 1037 | |
| 1038 | if !removed { |
| 1039 | // directory was not empty and not removed, |
| 1040 | // stop checking parents |
| 1041 | break |
| 1042 | } |
| 1043 | |
| 1044 | // move to parent directory |
| 1045 | dir = filepath.Dir(dir) |
| 1046 | } |
| 1047 | |
| 1048 | return nil |
| 1049 | } |
| 1050 | |
| 1051 | // removeDirIfEmpty will remove the supplied directory `dir` if |
| 1052 | // `dir` is empty |
no test coverage detected
searching dependent graphs…