diff --git a/registry/storage/driver/azure/azure.go b/registry/storage/driver/azure/azure.go index 4e6d9a20..028239fd 100644 --- a/registry/storage/driver/azure/azure.go +++ b/registry/storage/driver/azure/azure.go @@ -63,7 +63,8 @@ func New(params *Parameters) (*Driver, error) { d := &driver{ azClient: azClient, client: client, - rootDirectory: params.RootDirectory} + rootDirectory: params.RootDirectory, + } return &Driver{baseEmbed: baseEmbed{Base: base.Base{StorageDriver: d}}}, nil } @@ -420,6 +421,13 @@ func (d *driver) listBlobs(ctx context.Context, virtPath string) ([]string, erro } func (d *driver) blobName(path string) string { + // avoid returning an empty blob name. + // this will happen when rootDirectory is unset, and path == "/", + // which is what we get from the storage driver health check Stat call. + if d.rootDirectory == "" && path == "/" { + return path + } + return strings.TrimLeft(strings.TrimRight(d.rootDirectory, "/")+path, "/") } diff --git a/registry/storage/driver/testsuites/testsuites.go b/registry/storage/driver/testsuites/testsuites.go index 58f6b6d6..27923aa3 100644 --- a/registry/storage/driver/testsuites/testsuites.go +++ b/registry/storage/driver/testsuites/testsuites.go @@ -824,6 +824,15 @@ func (suite *DriverSuite) TestStatCall(c *check.C) { c.Assert(fi.Path(), check.Equals, dirPath) c.Assert(fi.Size(), check.Equals, int64(0)) c.Assert(fi.IsDir(), check.Equals, true) + + // The storage healthcheck performs this exact call to Stat. + // PathNotFoundErrors are not considered health check failures. + _, err = suite.StorageDriver.Stat(suite.ctx, "/") + // Some drivers will return a not found here, while others will not + // return an error at all. If we get an error, ensure it's a not found. + if err != nil { + c.Assert(err, check.FitsTypeOf, storagedriver.PathNotFoundError{}) + } } // TestPutContentMultipleTimes checks that if storage driver can overwrite the content