Opened 9 years ago

Closed 9 years ago

#26691 closed Cleanup/optimization (fixed)

Don't check for a file's existence before deleting

Reported by: Jon Dufresne Owned by: nobody
Component: File uploads/storage Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

PR

Change History (1)

comment:1 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 359be1c8:

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.

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