From 0a69db51f2551a83a693af36bce360aa43390f90 Mon Sep 17 00:00:00 2001 From: joe Date: Wed, 30 Apr 2014 20:03:01 -0400 Subject: writeKeyToFile now operates on InputFile intead of FilePath --- KeyRing.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'KeyRing.hs') diff --git a/KeyRing.hs b/KeyRing.hs index 7392395..e93d4a3 100644 --- a/KeyRing.hs +++ b/KeyRing.hs @@ -879,6 +879,7 @@ writeStamped0 ctx (FileDesc fd) stamp dowrite bs = do writeStamped0 ctx inp stamp dowrite bs = do let fname = resolveInputFile ctx inp forM_ fname $ \fname -> do + createDirectoryIfMissing True $ takeDirectory fname dowrite (Right fname) bs setFileTimes fname stamp stamp @@ -1556,7 +1557,7 @@ rsaPrivateKeyFromPacket _ = Nothing writeKeyToFile :: - Bool -> String -> FilePath -> Packet -> IO [(FilePath, KikiReportAction)] + Bool -> String -> InputFile -> Packet -> IO [(InputFile, KikiReportAction)] writeKeyToFile False "PEM" fname packet = case key_algorithm packet of RSA -> do @@ -1568,12 +1569,11 @@ writeKeyToFile False "PEM" fname packet = dta = Base64.encode (L.unpack bs) output = writePEM "RSA PRIVATE KEY" dta stamp = toEnum . fromEnum $ timestamp packet - createDirectoryIfMissing True (takeDirectory fname) handleIO_ (return [(fname, FailedFileWrite)]) $ do saved_mask <- setFileCreationMask 0o077 -- Note: The key's timestamp is included in it's fingerprint. -- Therefore, we should attempt to preserve it. - writeStamped (InputFileContext "" "") (ArgFile fname) stamp output + writeStamped (InputFileContext "" "") fname stamp output setFileCreationMask saved_mask return [(fname, ExportedSubkey)] algo -> return [(fname, UnableToExport algo $ fingerprint packet)] @@ -1587,12 +1587,13 @@ writePEMKeys doDecrypt db exports = do let ds' = map functorToEither ds if null (lefts ds') then do - rs <- mapM (uncurry $ writeKeyToFile False "PEM") + rs <- mapM (\(f,p) -> writeKeyToFile False "PEM" (ArgFile f) p) (rights ds') - return $ KikiSuccess (concat rs) + return $ KikiSuccess (map (first resolve) $ concat rs) else do return (head $ lefts ds') where + resolve f = concat $ resolveInputFile (InputFileContext "" "") f decryptKeys (fname,subspec,[p],_) = do pun <- doDecrypt p try pun $ \pun -> do -- cgit v1.2.3