Skip to content

Commit

Permalink
path/resolver: Fix recursive path resolution
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wking committed May 8, 2015
1 parent cd37b67 commit 10669e8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion path/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 10669e8

Please sign in to comment.