From 0caabf1328d3db16aeda222dc080b701d17c92f1 Mon Sep 17 00:00:00 2001 From: vyzo Date: Wed, 28 Jul 2021 16:15:39 +0300 Subject: [PATCH] improve detection of relative links --- blockstore/badger/blockstore.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/blockstore/badger/blockstore.go b/blockstore/badger/blockstore.go index 3d1862283..094b8eb6c 100644 --- a/blockstore/badger/blockstore.go +++ b/blockstore/badger/blockstore.go @@ -370,9 +370,17 @@ func (b *Blockstore) movingGC() error { // symlink creates a symlink from path to linkPath; the link is relative if the two are // in the same directory func (b *Blockstore) symlink(path, linkTo string) error { - pathDir := filepath.Dir(path) - linkDir := filepath.Dir(linkTo) - if pathDir == linkDir { + resolvedPathDir, err := filepath.EvalSymlinks(filepath.Dir(path)) + if err != nil { + return fmt.Errorf("error resolving links in %s: %w", path, err) + } + + resolvedLinkDir, err := filepath.EvalSymlinks(filepath.Dir(linkTo)) + if err != nil { + return fmt.Errorf("error resolving links in %s: %W", linkTo, err) + } + + if resolvedPathDir == resolvedLinkDir { path = filepath.Base(path) }