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,26 +447,10 @@ 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)
if err != nil {
log.Warnf("error stating %s: %s", lpath, err)
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
lpath, err := filepath.EvalSymlinks(path)
if err != nil {
log.Warnf("error resolving symlinks in %s", path)
return
}
log.Infof("removing data directory %s", lpath)