-
-
Notifications
You must be signed in to change notification settings - Fork 889
Open
Description
I am trying to delete all files under a certain directory.
I am doing this by iterating over the result of listdir and passing each returned path to delete.
default = storages['default']
default.save("dir/test.txt", content=io.BytesIO(b"test"))
_, files = default.listdir("dir")
print(files)
for file in files:
default.delete(file)
_, files2 = default.listdir("dir")
print(files2)This normally works and gives output
["dir/test.txt"]
[]
However when I also use the location config option
STORAGES = {
"default": {
"BACKEND": "storages.backends.azure_storage.AzureStorage",
"OPTIONS": {
...
"azure_container": "test-container",
"location": "location",
},
},
}It stops working and gives output
['location/dir/test.txt']
['location/dir/test.txt']
I think this is because the location is being included in the output from listdir.
Which when passed to delete, the location is added to the path again, so the delete targets the wrong path.
The solution for me would be for listdir to strip the location. Not sure if that's the best solution in the big picture.
Metadata
Metadata
Assignees
Labels
No labels