MCPcopy
hub / github.com/go-git/go-git / rmFileAndDirsIfEmpty

Function rmFileAndDirsIfEmpty

worktree.go:1026–1049  ·  view source on GitHub ↗

will walk up the directory tree removing all encountered empty directories, not just the one containing this file

(fs billy.Filesystem, name string)

Source from the content-addressed store, hash-verified

1024// will walk up the directory tree removing all encountered empty
1025// directories, not just the one containing this file
1026func 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

Callers 1

checkoutChangeMethod · 0.85

Calls 1

removeDirIfEmptyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…