Skip to content

Commit

Permalink
Do not overwrite more specific matches when finding storage providers (
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck authored Jul 30, 2021
1 parent aa309f6 commit fcb7a30
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions changelog/unreleased/fix-finding-storage-providers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Do not overwrite more specific matches when finding storage providers

Depending on the order of rules in the registry it could happend that more specific matches (e.g. /home/Shares) were
overwritten by more general ones (e.g. /home). This PR makes sure that the registry always returns the most specific
match.

https://github.com/cs3org/reva/pull/1937
4 changes: 4 additions & 0 deletions pkg/storage/registry/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ func (b *reg) FindProviders(ctx context.Context, ref *provider.Reference) ([]*re
continue
}
if m := r.FindString(fn); m != "" {
if match != nil && len(match.ProviderPath) > len(m) {
// Do not overwrite existing longer match
continue
}
match = &registrypb.ProviderInfo{
ProviderPath: m,
Address: addr,
Expand Down
5 changes: 4 additions & 1 deletion pkg/storage/registry/static/static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

var _ = Describe("Static", func() {

totalProviders, rootProviders, eosProviders := 32, 30, 28
totalProviders, rootProviders, eosProviders := 33, 31, 29

handler, err := static.New(map[string]interface{}{
"home_provider": "/home",
Expand Down Expand Up @@ -75,6 +75,9 @@ var _ = Describe("Static", func() {
"123e4567-e89b-12d3-a456-426655440001": map[string]interface{}{
"address": "home-01-home",
},
"/eos/": map[string]interface{}{
"address": "unspecific-rule-that-should-never-been-hit",
},
},
})
Expect(err).ToNot(HaveOccurred())
Expand Down

0 comments on commit fcb7a30

Please sign in to comment.