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.
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>
* 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>
* status: new => assigned
* owner: nobody => ChillarAnand
--
Ticket URL: <https://code.djangoproject.com/ticket/27836#comment:3>
* 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>
* 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>
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>