shithub: furgit

ref: df1f2fb3daa1acd25c88510f259d5535fb482126
dir: /ref/store/files/update_cleanup_parents.go/

View raw version
package files

import (
	"errors"
	"os"
	"path"
)

func (executor *refUpdateExecutor) tryRemoveEmptyParents(name string) {
	loc := executor.store.loosePath(name)
	executor.tryRemoveEmptyParentPaths(loc.root, loc.path)
}

func (executor *refUpdateExecutor) tryRemoveEmptyParentPaths(kind rootKind, name string) {
	root := executor.store.rootFor(kind)
	dir := path.Dir(name)

	for dir != "." && dir != "/" {
		err := root.Remove(dir)
		if err != nil {
			if errors.Is(err, os.ErrNotExist) {
				return
			}

			return
		}

		dir = path.Dir(dir)
	}
}