module Database.PlistBuddy.Open
(
openPlist
) where
import Control.Concurrent
import Control.Exception
import Data.IORef
import Database.PlistBuddy.Types
import Database.PlistBuddy.Command
import System.Posix.Pty
import System.IO.Error (catchIOError)
handleIOErrors :: IO a -> IO a
handleIOErrors m =
m `catchIOError` \ e -> throw $ PlistBuddyException $ "IO error, " ++ show e
openPlist :: FilePath -> IO Plist
openPlist fileName = handleIOErrors $ do
(pty,ph) <- spawnWithPty
Nothing
False
"/usr/libexec/PlistBuddy"
["-x",fileName]
(80,24)
myWritePty pty "#\n"
_ <- recvReply0 pty
attr <- getTerminalAttributes pty
setTerminalAttributes pty ((attr `withoutMode` EnableEcho) `withoutMode` ProcessInput) Immediately
lock <- newMVar ()
dirty <- newIORef $ Just False
return $ Plist pty lock ph False fileName (const $ return $ ()) (return ()) dirty