aboutsummaryrefslogtreecommitdiff
path: root/Utility/Gpg.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-05-15 23:32:17 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-05-16 01:03:52 -0400
commit4dc2000f97236089a8613cc6b0bf9846fea6abfa (patch)
tree83df60ef702246b0b71bc99e141d4a8bf1990438 /Utility/Gpg.hs
parent973180b077e60b5d12d7c57d926878d11d7f2105 (diff)
adeiu, MissingH
Removed dependency on MissingH, instead depending on the split library. After laying groundwork for this since 2015, it was mostly straightforward. Added Utility.Tuple and Utility.Split. Eyeballed System.Path.WildMatch while implementing the same thing. Since MissingH's progress meter display was being used, I re-implemented my own. Bonus: Now progress is displayed for transfers of files of unknown size. This commit was sponsored by Shane-o on Patreon.
Diffstat (limited to 'Utility/Gpg.hs')
-rw-r--r--Utility/Gpg.hs20
1 files changed, 8 insertions, 12 deletions
diff --git a/Utility/Gpg.hs b/Utility/Gpg.hs
index f6173cdb4..336711b3f 100644
--- a/Utility/Gpg.hs
+++ b/Utility/Gpg.hs
@@ -14,11 +14,9 @@ import qualified Build.SysConfig as SysConfig
#ifndef mingw32_HOST_OS
import System.Posix.Types
import qualified System.Posix.IO
-import System.Path
import Utility.Env
-#else
-import Utility.Tmp
#endif
+import Utility.Tmp
import Utility.Format (decode_c)
import Control.Concurrent
@@ -336,23 +334,21 @@ keyBlock public ls = unlines
{- Runs an action using gpg in a test harness, in which gpg does
- not use ~/.gpg/, but a directory with the test key set up to be used. -}
testHarness :: GpgCmd -> IO a -> IO a
-testHarness cmd a = do
- orig <- getEnv var
- bracket setup (cleanup orig) (const a)
+testHarness cmd a = withTmpDir "gpgtmpXXXXXX" $ \tmpdir ->
+ bracket (setup tmpdir) (cleanup tmpdir) (const a)
where
var = "GNUPGHOME"
- setup = do
- base <- getTemporaryDirectory
- dir <- mktmpdir $ base </> "gpgtmpXXXXXX"
- setEnv var dir True
+ setup tmpdir = do
+ orig <- getEnv var
+ setEnv var tmpdir True
-- For some reason, recent gpg needs a trustdb to be set up.
_ <- pipeStrict cmd [Param "--trust-model", Param "auto", Param "--update-trustdb"] []
_ <- pipeStrict cmd [Param "--import", Param "-q"] $ unlines
[testSecretKey, testKey]
- return dir
+ return orig
- cleanup orig tmpdir = do
+ cleanup tmpdir orig = do
removeDirectoryRecursive tmpdir
-- gpg-agent may be shutting down at the same time
-- and may delete its socket at the same time as