diff --git a/changelog/unreleased/fix-finding-storage-providers.md b/changelog/unreleased/fix-finding-storage-providers.md new file mode 100644 index 0000000000..640f70ff14 --- /dev/null +++ b/changelog/unreleased/fix-finding-storage-providers.md @@ -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 \ No newline at end of file diff --git a/pkg/storage/registry/static/static.go b/pkg/storage/registry/static/static.go index 418e2d5708..05125f05b7 100644 --- a/pkg/storage/registry/static/static.go +++ b/pkg/storage/registry/static/static.go @@ -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 = ®istrypb.ProviderInfo{ ProviderPath: m, Address: addr, diff --git a/pkg/storage/registry/static/static_test.go b/pkg/storage/registry/static/static_test.go index f96bd55d77..6b46c7c32b 100644 --- a/pkg/storage/registry/static/static_test.go +++ b/pkg/storage/registry/static/static_test.go @@ -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", @@ -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())