Re: Possible race condition in base.py

2007-04-25 Thread Malcolm Tredinnick
Hi Enrico, On Wed, 2007-04-25 at 19:03 +1200, Enrico de Klerk wrote: > I think the race condition can be removed by doing something like this > (It's similar to what mkstemp does): > > while True: > try: > fd = os.open(os.path.join(settings.MEDIA_ROOT, filename), > os.O_RDWR | os.O_C

Re: Possible race condition in base.py

2007-04-25 Thread Enrico de Klerk
I think the race condition can be removed by doing something like this (It's similar to what mkstemp does): while True: try: fd = os.open(os.path.join(settings.MEDIA_ROOT, filename), os.O_RDWR | os.O_CREAT | os.O_EXCL) fp = os.fdopen(fd, 'wb') fp.write(raw_contents)

Re: Possible race condition in base.py

2007-04-24 Thread Malcolm Tredinnick
On Tue, 2007-04-24 at 21:06 +1200, Enrico de Klerk wrote: > Hi there, > > I've noticed a possible race condition in django/db/models/base.py. > > When a file field is saved in the _save_FIELD_file function it first > checks whether a file with the same name already exists, and then adds > unders

Possible race condition in base.py

2007-04-24 Thread Enrico de Klerk
Hi there, I've noticed a possible race condition in django/db/models/base.py. When a file field is saved in the _save_FIELD_file function it first checks whether a file with the same name already exists, and then adds underscores to the filename until it generates a unique name and then saves th