[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 15:01:44 UTC 2010


The following commit has been merged in the master branch:
commit 4a8d2616d3633825886f9eeaf43f6e02c27b0d60
Author: John Goerzen <jgoerzen at complete.org>
Date:   Mon Aug 15 20:52:00 2005 +0100

    Added bracketCWD, brackettmpdirCWD

diff --git a/MissingH/Path.hs b/MissingH/Path.hs
index 58ff2d0..dd0d9a8 100644
--- a/MissingH/Path.hs
+++ b/MissingH/Path.hs
@@ -1,6 +1,6 @@
 {-# LANGUAGE CPP #-}
 {- arch-tag: Path utilities main file
-Copyright (C) 2004 John Goerzen <jgoerzen at complete.org>
+Copyright (C) 2004-2005 John Goerzen <jgoerzen at complete.org>
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 {- |
    Module     : MissingH.Path
-   Copyright  : Copyright (C) 2004 John Goerzen
+   Copyright  : Copyright (C) 2004-2005 John Goerzen
    License    : GNU GPL, version 2 or above
 
    Maintainer : John Goerzen, 
@@ -37,8 +37,9 @@ module MissingH.Path(-- * Name processing
                      splitExt, absNormPath, secureAbsNormPath,
                      -- * Directory Processing
                      recurseDir, recurseDirStat, recursiveRemove,
+                     bracketCWD,
                      -- * Temporary Directories
-                     mktmpdir, brackettmpdir
+                     mktmpdir, brackettmpdir, brackettmpdirCWD
                     )
 where
 import Data.List
@@ -142,3 +143,19 @@ brackettmpdir :: String -> (String -> IO a) -> IO a
 brackettmpdir x action = do tmpdir <- mktmpdir x
                             finally (action tmpdir) 
                                     (recursiveRemove SystemFS tmpdir)
+
+{- | Changes the current working directory to the given path,
+executes the given I\/O action, then changes back to the original directory,
+even if the I\/O action raised an exception. -}
+bracketCWD :: FilePath -> IO a -> IO a
+bracketCWD fp action =
+    do oldcwd <- getCurrentDirectory
+       setCurrentDirectory fp
+       finally action (setCurrentDirectory oldcwd)
+
+{- | Runs the given I\/O action with the CWD set to the given tmp dir,
+removing the tmp dir and changing CWD back afterwards, even if there
+was an exception. -}
+brackettmpdirCWD :: String -> (String -> IO a) -> IO a
+brackettmpdirCWD template action =
+    brackettmpdir template (\newdir -> bracketCWD newdir action)
\ No newline at end of file

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list