ref: af08c84539f9353718604988ba27ae3c466860fc
dir: /refstore/files/transaction_cleanup_parents.go/
package files
import (
"errors"
"os"
"path"
)
func (tx *Transaction) tryRemoveEmptyParents(name string) {
loc := tx.store.loosePath(name)
tx.tryRemoveEmptyParentPaths(loc.root, loc.path)
}
func (tx *Transaction) tryRemoveEmptyParentPaths(kind rootKind, name string) {
root := tx.store.rootFor(kind)
dir := path.Dir(name)
for dir != "." && dir != "/" {
err := root.Remove(dir)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return
}
var pathErr *os.PathError
if errors.As(err, &pathErr) {
return
}
return
}
dir = path.Dir(dir)
}
}