Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#27836 closed New feature (fixed)

Add a way to delete directories through the file Storage API

Reported by: jedie Owned by: ChillarAnand
Component: File uploads/storage Version: dev
Severity: Normal Keywords: file storage API
Cc: anand21nanda@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by jedie)

It seems not possible to cleanup orphaned directories via storage API [1]

The problem: The default filesystem storage will call os.remove(name) on storage.delete(name) usage. So it's only possible to delete a file and not a directory.

Usecase:
I store files (via models.FileField) in a sub-directory with a random token (via upload_to callback).
I delete the file via post_delete model signal and call storage.delete(file.path)
Now i can only delete the sub directory if i implement a own routine and use os.rmdir(path) if the default filesystem storage is used.

[1] https://docs.djangoproject.com/en/dev/ref/files/storage/

Change History (6)

comment:1 by jedie, 8 years ago

Description: modified (diff)

comment:2 by Tim Graham, 8 years ago

Summary: File Storage API: No way to delete directories?!?Add a way to delete directories through the file Storage API
Triage Stage: UnreviewedAccepted
Type: Cleanup/optimizationNew feature

I wonder if it would be feasible and a good idea to allow FileSystemStorage.delete() to distinguish between files and directories and issue os.remove() or os.rmdir() as necessary?

comment:3 by ChillarAnand, 8 years ago

Owner: changed from nobody to ChillarAnand
Status: newassigned

comment:4 by ChillarAnand, 8 years ago

Cc: anand21nanda@… added
Has patch: set

Fixed in PR

comment:5 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In e402556:

Fixed #27836 -- Allowed FileSystemStorage.delete() to remove directories.

comment:6 by Tim Graham <timograham@…>, 8 years ago

In 9cbf4869:

Refs #27836 -- Fixed cleanup exception in file_storage test.

TemporaryDirectory tries to delete the directory that was already removed.

Note: See TracTickets for help on using tickets.
Back to Top