[Django] #26691: Don't check for a file's existence before deleting

1 view
Skip to first unread message

Django

unread,
May 31, 2016, 11:51:25 AM5/31/16
to django-...@googlegroups.com
#26691: Don't check for a file's existence before deleting
------------------------------------------------+------------------------
Reporter: jdufresne | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: File uploads/storage | Version: master
Severity: Normal | Keywords:
Triage Stage: Accepted | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
There are a couple places in Django (file-based cache and
`FileSystemStorage`) that do a file-existence check before removing a
file). This leads to an unnecessary race condition. It's easier to simply
try to delete the file and pass silently if the file doesn't exist.

[https://github.com/django/django/pull/6652 PR]

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

Django

unread,
May 31, 2016, 12:17:50 PM5/31/16
to django-...@googlegroups.com
#26691: Don't check for a file's existence before deleting
--------------------------------------+------------------------------------
Reporter: jdufresne | Owner: nobody
Type: Cleanup/optimization | Status: closed

Component: File uploads/storage | Version: master
Severity: Normal | Resolution: fixed

Keywords: | 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: new => closed
* resolution: => fixed


Comment:

In [changeset:"359be1c8702ede41e7fe823ed13350795ba96a61" 359be1c8]:
{{{
#!CommitTicketReference repository=""
revision="359be1c8702ede41e7fe823ed13350795ba96a61"
Fixed #26691 -- Removed checking for a file's existence before deleting.

File operations always raise a ENOENT error when a file doesn't exist.
Checking the file exists before the operation adds a race condition
condition where the file could be removed between operations. As the
operation already raises an error on a missing file, avoid this race and
avoid checking the file exists twice. Instead only check a file exists
by catching the ENOENT error.
}}}

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

Reply all
Reply to author
Forward
0 new messages