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) { func (b *Blockstore) deleteDB(path string) {
// follow symbolic links, otherwise the data wil be left behind // follow symbolic links, otherwise the data wil be left behind
lpath := path lpath, err := filepath.EvalSymlinks(path)
for { if err != nil {
fi, err := os.Lstat(lpath) log.Warnf("error resolving symlinks in %s", path)
if err != nil { return
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
} }
log.Infof("removing data directory %s", lpath) log.Infof("removing data directory %s", lpath)