MCPcopy Create free account
hub / github.com/go-git/go-git / removeDirIfEmpty

Function removeDirIfEmpty

worktree.go:1081–1097  ·  view source on GitHub ↗

removeDirIfEmpty will remove the supplied directory `dir` if `dir` is empty returns true if the directory was removed

(fs billy.Filesystem, dir string)

Source from the content-addressed store, hash-verified

1079// `dir` is empty
1080// returns true if the directory was removed
1081func removeDirIfEmpty(fs billy.Filesystem, dir string) (bool, error) {
1082 files, err := fs.ReadDir(dir)
1083 if err != nil {
1084 return false, err
1085 }
1086
1087 if len(files) > 0 {
1088 return false, nil
1089 }
1090
1091 err = fs.Remove(dir)
1092 if err != nil {
1093 return false, err
1094 }
1095
1096 return true, nil
1097}
1098
1099type indexBuilder struct {
1100 entries map[string]*index.Entry

Callers 2

doCleanMethod · 0.85
rmFileAndDirsIfEmptyFunction · 0.85

Calls 2

ReadDirMethod · 0.45
RemoveMethod · 0.45

Tested by

no test coverage detected