#9433: File locking broken on AFP mounts
-------------------------------------------+--------------------------------
          Reporter:  rndblnch              |         Owner:  rndblnch
            Status:  new                   |     Milestone:          
         Component:  File uploads/storage  |       Version:  1.0     
        Resolution:                        |      Keywords:          
             Stage:  Accepted              |     Has_patch:  1       
        Needs_docs:  0                     |   Needs_tests:  0       
Needs_better_patch:  0                     |  
-------------------------------------------+--------------------------------
Comment (by rndblnch):

 after getting some feedback on the django-developers mailing list [0], i'm
 back with another proposed way for fixing this issue.

 i understand that my case is special and that solving it according to the
 {{{not_supported_locks.diff}}} patch proposed above may not be optimal.
 what i propose is to provide a way to replace the locks module if needed
 at user will.
 in the new attached patch against trunk ({{{inject_locks.patch}}}), this
 is done by adding a {{{locks}}} parameter that defaults to
 {{{django.core.files.locks}}} to the class/functions that use it (i.e.
 django.core.files.move.file_move_safe and
 django.core.files.storage.FileSystemStorage).

 it is then possible to fix the bug from the application code by defining a
 {{{patched_locks.py}}} module like this one:
 {{{
 from django.core.files import locks

 def ignore(*args): pass

 def patch(f, Error=IOError, errno=45, fallback=ignore):
         def g(*args):
                 try:
                         f(*args)
                 except Error, e:
                         if e.errno == errno:
                                 fallback(*args)
                         else:
                                 raise
         g.__name__ = f.__name__
         g.__doc__  = g.__doc__
         return g

 lock   = patch(locks.lock)
 unlock = patch(locks.unlock)

 LOCK_EX = locks.LOCK_EX
 LOCK_SH = locks.LOCK_SH
 LOCK_NB = locks.LOCK_NB
 }}}

 and in the {{{models.py}}} code that use a FileField:

 {{{
 from django.db import models
 from django.core.files.storage import FileSystemStorage
 import patched_locks

 class Test(models.Model):
         document =
 models.FileField(storage=FileSystemStorage(locks=patched_locks))
 }}}

 doing so will also allow to make the FileSystemStorage class easier to
 test.
 hope this solution helps.

 0. patch review wanted (ticket #9433)
 <[http://groups.google.com/group/django-
 developers/browse_thread/thread/e53852d7ec79bbd5#]>

-- 
Ticket URL: <http://code.djangoproject.com/ticket/9433#comment:5>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to