Skip to content

Azure listdir against root directory with location option, returns files outside location #1543

@LincolnPuzey

Description

@LincolnPuzey

With the Azure backend, using listdir against the root directory and with location option configured, e.g.

# Settings
STORAGES = {
    "default": {
        "BACKEND": "storages.backends.azure_storage.AzureStorage",
        "OPTIONS": {
            ...
            "azure_container": "test-container",
            "location": "test-location",
        },
    },
}

# In your code somewhere
storages["default"].listdir("")

will return file outside the location directory.
E.g. if the files in test-container are

/test-location/some-file.txt
/something-else.txt

Both will be returned by the listdir call.

This is because location is only added when a non-empty path is provided to listdir:

def list_all(self, path=""):
"""Return all files for a given path"""
if path:
path = self._get_valid_path(path)

For comparison, S3 does not have this bug, location is always added

def listdir(self, name):
path = self._normalize_name(clean_name(name))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions