diff --git a/registry/storage/driver/azure/azure.go b/registry/storage/driver/azure/azure.go index 601bf528323..d2a6654682d 100644 --- a/registry/storage/driver/azure/azure.go +++ b/registry/storage/driver/azure/azure.go @@ -404,20 +404,9 @@ func (d *driver) listBlobs(ctx context.Context, virtPath string) ([]string, erro virtPath += "/" } - // we will replace the root directory prefix before returning blob names - blobPrefix := d.blobName("") - - // This is to cover for the cases when the rootDirectory of the driver is either "" or "/". - // In those cases, there is no root prefix to replace and we must actually add a "/" to all - // results in order to keep them as valid paths as recognized by storagedriver.PathRegexp - prefix := "" - if blobPrefix == "" { - prefix = "/" - } - out := []string{} - listPrefix := d.blobName(virtPath) + pager := d.client.NewListBlobsFlatPager(&container.ListBlobsFlatOptions{ Prefix: &listPrefix, }) @@ -431,7 +420,14 @@ func (d *driver) listBlobs(ctx context.Context, virtPath string) ([]string, erro return nil, fmt.Errorf("required blob property Name is missing while listing blobs under: %s", listPrefix) } name := *blob.Name - out = append(out, strings.Replace(name, blobPrefix, prefix, 1)) + + // This is to cover for the cases when the rootDirectory of the driver is either "" or "/". + // In those cases, there is no root prefix to replace and we must actually add a "/" to all + // results in order to keep them as valid paths as recognized by storagedriver.PathRegexp + if !strings.HasPrefix(name, "/") { // add leading '/' + name = "/" + name + } + out = append(out, name) } } @@ -446,7 +442,9 @@ func (d *driver) blobName(path string) string { return path } - return strings.TrimLeft(strings.TrimRight(d.rootDirectory, "/")+path, "/") + trimmedRoot := strings.TrimRight(d.rootDirectory, "/") + trimmedPath := strings.TrimLeft(path, "/") + return trimmedRoot + "/" + trimmedPath } func is404(err error) bool {