use EvalSymlinks in deleteDB

This commit is contained in:
vyzo 2021-07-27 10:08:07 +03:00
parent c03859c1b5
commit cbaffab9dd

View File

@ -447,28 +447,12 @@ func (b *Blockstore) doCopy(from, to *badger.DB, filter func(cid.Cid) bool) erro
func (b *Blockstore) deleteDB(path string) {
// follow symbolic links, otherwise the data wil be left behind
lpath := path
for {
fi, err := os.Lstat(lpath)
lpath, err := filepath.EvalSymlinks(path)
if err != nil {
log.Warnf("error stating %s: %s", lpath, err)
log.Warnf("error resolving symlinks in %s", path)
return
}
if fi.Mode()&os.ModeSymlink == 0 {
break
}
log.Infof("resolving symbolic link %s", lpath)
newpath, err := os.Readlink(lpath)
if err != nil {
log.Warnf("error resolving symbolic link %s: %s", lpath, err)
return
}
log.Infof("resolved symbolic link %s -> %s", lpath, newpath)
lpath = newpath
}
log.Infof("removing data directory %s", lpath)
if err := os.RemoveAll(lpath); err != nil {
log.Warnf("error deleting db at %s: %s", lpath, err)