#2808: createDirectoryIfMissing should be atomic
------------------------------------+---------------------------------------
    Reporter:  EricKow              |        Owner:  igloo           
        Type:  merge                |       Status:  new             
    Priority:  normal               |    Milestone:  6.10.2          
   Component:  libraries/directory  |      Version:  6.10.1          
    Severity:  normal               |   Resolution:                  
    Keywords:                       |   Difficulty:  Unknown         
    Testcase:                       |           Os:  Unknown/Multiple
Architecture:  Unknown/Multiple     |  
------------------------------------+---------------------------------------
Changes (by simonmar):

  * owner:  simonmar => igloo
  * type:  bug => merge

Comment:

 I've fixed the obvious race condition, but as Duncan says it's not
 possible to make this function completely race-free.  I think this is
 enough to keep Eric happy, though.

 {{{
 Wed Nov 26 11:56:06 GMT 2008  Simon Marlow <[EMAIL PROTECTED]>
   * add test for createDirectoryIfMissing (#2808)

 Wed Nov 26 12:36:59 GMT 2008  Simon Marlow <[EMAIL PROTECTED]>
   * avoid race conditions in createDirectoryIfMissing (#2808)
 }}}

 For reference the code is now:

 {{{
 createDirectoryIfMissing create_parents "" = return ()
 createDirectoryIfMissing create_parents path0
  = do  r <- try $ createDirectory path
        case (r :: Either IOException ()) of
           Right _ -> return ()
           Left e
              | isAlreadyExistsError e -> return ()
              | isDoesNotExistError  e && create_parents -> do
                  createDirectoryIfMissing True (dropFileName path)
                  createDirectoryIfMissing True path
              | otherwise -> throw e
   where
     -- we want createDirectoryIfMissing "a/" to behave like
     -- createDirectoryIfMissing "a".  Also, unless we apply
     -- dropTrailingPathSeparator first, dropFileName won't drop
     -- anything from "a/".
     path = dropTrailingPathSeparator path0
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2808#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to