[Django] #27836: File Storage API: No way to delete directories?!?

20 views
Skip to first unread message

Django

unread,
Feb 14, 2017, 6:02:55 AM2/14/17
to django-...@googlegroups.com
#27836: File Storage API: No way to delete directories?!?
-------------------------------------+-------------------------------------
Reporter: jedie | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: File | Version: master
uploads/storage |
Severity: Normal | Keywords: file storage API
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
It seems not possible to cleanup orphaned directories via storage API [1]

The problem: The default filesystem storage will call `os.rename` 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/

--
Ticket URL: <https://code.djangoproject.com/ticket/27836>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 14, 2017, 6:08:16 AM2/14/17
to django-...@googlegroups.com
#27836: File Storage API: No way to delete directories?!?
-------------------------------------+-------------------------------------
Reporter: jedie | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: File | Version: master
uploads/storage |
Severity: Normal | Resolution:

Keywords: file storage API | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by jedie:

Old description:

> It seems not possible to cleanup orphaned directories via storage API [1]
>
> The problem: The default filesystem storage will call `os.rename` 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/

New description:

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/

--

--
Ticket URL: <https://code.djangoproject.com/ticket/27836#comment:1>

Django

unread,
Feb 14, 2017, 1:47:58 PM2/14/17
to django-...@googlegroups.com
#27836: Add a way to delete directories through the file Storage API
--------------------------------------+------------------------------------
Reporter: jedie | Owner: nobody
Type: New feature | Status: new
Component: File uploads/storage | Version: master
Severity: Normal | Resolution:
Keywords: file storage API | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted
* type: Cleanup/optimization => New feature


Comment:

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?

--
Ticket URL: <https://code.djangoproject.com/ticket/27836#comment:2>

Django

unread,
Feb 22, 2017, 8:39:50 AM2/22/17
to django-...@googlegroups.com
#27836: Add a way to delete directories through the file Storage API
-------------------------------------+-------------------------------------
Reporter: jedie | Owner:
| ChillarAnand
Type: New feature | Status: assigned

Component: File | Version: master
uploads/storage |
Severity: Normal | Resolution:
Keywords: file storage API | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by ChillarAnand):

* status: new => assigned
* owner: nobody => ChillarAnand


--
Ticket URL: <https://code.djangoproject.com/ticket/27836#comment:3>

Django

unread,
Feb 22, 2017, 9:47:16 AM2/22/17
to django-...@googlegroups.com
#27836: Add a way to delete directories through the file Storage API
-------------------------------------+-------------------------------------
Reporter: jedie | Owner:
| ChillarAnand
Type: New feature | Status: assigned
Component: File | Version: master
uploads/storage |
Severity: Normal | Resolution:
Keywords: file storage API | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by ChillarAnand):

* cc: anand21nanda@… (added)
* has_patch: 0 => 1


Comment:

Fixed in [https://github.com/django/django/pull/8097 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/27836#comment:4>

Django

unread,
Feb 24, 2017, 4:20:20 PM2/24/17
to django-...@googlegroups.com
#27836: Add a way to delete directories through the file Storage API
-------------------------------------+-------------------------------------
Reporter: jedie | Owner:
| ChillarAnand
Type: New feature | Status: closed

Component: File | Version: master
uploads/storage |
Severity: Normal | Resolution: fixed
Keywords: file storage API | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"e4025563ea87b0e3acb1d617ebfcc0b8789f75e7" e402556]:
{{{
#!CommitTicketReference repository=""
revision="e4025563ea87b0e3acb1d617ebfcc0b8789f75e7"
Fixed #27836 -- Allowed FileSystemStorage.delete() to remove directories.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27836#comment:5>

Django

unread,
Mar 1, 2017, 12:52:38 PM3/1/17
to django-...@googlegroups.com
#27836: Add a way to delete directories through the file Storage API
-------------------------------------+-------------------------------------
Reporter: jedie | Owner:
| ChillarAnand
Type: New feature | Status: closed
Component: File | Version: master
uploads/storage |
Severity: Normal | Resolution: fixed
Keywords: file storage API | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"9cbf48693dcd8df6cb22c183dcc94e7ce62b2921" 9cbf4869]:
{{{
#!CommitTicketReference repository=""
revision="9cbf48693dcd8df6cb22c183dcc94e7ce62b2921"
Refs #27836 -- Fixed cleanup exception in file_storage test.

TemporaryDirectory tries to delete the directory that was already removed.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27836#comment:6>

Reply all
Reply to author
Forward
0 new messages