made filesystem backend actually detect the lack of a key
Getty Ritter
9 years ago
| 4 | 4 | import Data.ByteString.Base64 |
| 5 | 5 | import qualified Data.ByteString.Char8 as BS |
| 6 | 6 | import Database.Tansu.Internal (Database(..)) |
| 7 |
import System.Directory (createDirectoryIfMissing |
|
| 7 | import System.Directory (createDirectoryIfMissing, doesFileExist) | |
| 8 | 8 | import System.FilePath.Posix ((</>)) |
| 9 | 9 | |
| 10 | 10 | filePathSet :: FilePath -> ByteString -> ByteString -> IO () |
| 15 | 15 | filePathGet :: FilePath -> ByteString -> IO (Maybe ByteString) |
| 16 | 16 | filePathGet path key = do |
| 17 | 17 | let keyPath = path </> BS.unpack (encode key) |
| 18 |
|
|
| 18 | exists <- doesFileExist keyPath | |
| 19 | if exists | |
| 20 | then Just `fmap` BS.readFile keyPath | |
| 21 | else return Nothing | |
| 19 | 22 | |
| 20 | 23 | withFilesystemDb :: FilePath -> (Database -> IO a) -> IO a |
| 21 | 24 | withFilesystemDb path comp = do |