>>>>> "Jan" == Jan Kort <[EMAIL PROTECTED]> writes:

  
    Jan> I can't seem to work around this behaviour, is it possible to
    Jan> force readFile to just open a file, read it entirely and close
    Jan> it before doing the next open ? I tried a few things with seq,
    Jan> but this doesn't work:

I tried to copy the file into a temporary, remove it and wait until it
does not exists any longer. However, that doesn't work either.
The message on Solaris was:

> ld.so.1: sh: fatal: libc.so.1: open failed: Too many open files

> Fail: interrupted
> Action: system
> Reason: system command interrupted rm newtmp

Although our file system may have synchronizations problems I was sure
the following would work:
----------------------------------------------------------------------
module Main where

import Directory
import System


waitWhileExistsFile :: String -> IO ()
waitWhileExistsFile name 
 = do
    exists <- doesFileExist name
    if exists 
      then waitWhileExistsFile name
      else return ()

safeReadEntireFile :: String -> IO String
safeReadEntireFile name 
 = do
    system("cp "++name++" newtmp");
    content <- readFile "newtmp"
    system("rm newtmp");
    waitWhileExistsFile "newtmp"
    return content


main :: IO ()
main = do
        xs <- mapM safeReadEntireFile (take 1000 (repeat "tmp"));
        print (length xs)
        return ()
----------------------------------------------------------------------

Reply via email to