From 10669e8b8c1d44ac7510fa17947956a408a85384 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 8 May 2015 16:07:01 -0700 Subject: [PATCH] path/resolver: Fix recursive path resolution I'm not entirely clear on Go's scoping (there's some text I can't quite parse here [1]), but it seems like the := version (because this is the first time we use 'err') was masking the function-level 'nd' just for this if block. That means that after we get out of the if block and return to the start of the for-loop for the next pass, nd.Links would still be pointing at the original object's links. This commit drops the :=, which fixes the earlier: $ ipfs ls QmXX7YRpU7nNBKfw75VG7Y1c3GwpSAGHRev67XVPgZFv9R/static/css Error: no link named "css" under QmXX7YRpU7nNBKfw75VG7Y1c3GwpSAGHRev67XVPgZFv9R so we get the intended: $ ipfs ls QmXX7YRpU7nNBKfw75VG7Y1c3GwpSAGHRev67XVPgZFv9R/static/css Qme4r3eA4h1revFBgCEv1HF1U7sLL4vvAyzRLWJhCFhwg2 7051 style.css It also means we're probably missing (or are unreliably using) a multi-level-path-resolving test. [1]: https://golang.org/ref/spec#Declarations_and_scope --- path/resolver.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/path/resolver.go b/path/resolver.go index b24f45f21..a08df8741 100644 --- a/path/resolver.go +++ b/path/resolver.go @@ -122,7 +122,8 @@ func (s *Resolver) ResolveLinks(ctx context.Context, ndd *merkledag.Node, names // fetch object for link and assign to nd ctx, cancel := context.WithTimeout(ctx, time.Minute) defer cancel() - nd, err := s.DAG.Get(ctx, next) + var err error + nd, err = s.DAG.Get(ctx, next) if err != nil { return append(result, nd), err }