summaryrefslogtreecommitdiff
path: root/Types/Key.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Types/Key.hs')
-rw-r--r--Types/Key.hs10
1 files changed, 8 insertions, 2 deletions
diff --git a/Types/Key.hs b/Types/Key.hs
index 2ddb3f50e..f900ece2b 100644
--- a/Types/Key.hs
+++ b/Types/Key.hs
@@ -14,7 +14,8 @@ module Types.Key (
key2file,
file2key,
- prop_idempotent_key_encode
+ prop_idempotent_key_encode,
+ prop_idempotent_key_decode
) where
import System.Posix.Types
@@ -59,7 +60,7 @@ key2file Key { keyBackendName = b, keySize = s, keyMtime = m, keyName = n } =
_ ?: _ = ""
file2key :: FilePath -> Maybe Key
-file2key s = if key == Just stubKey then Nothing else key
+file2key s = if key == Just stubKey || (keyName <$> key) == Just "" then Nothing else key
where
key = startbackend stubKey s
@@ -88,3 +89,8 @@ instance Arbitrary Key where
prop_idempotent_key_encode :: Key -> Bool
prop_idempotent_key_encode k = Just k == (file2key . key2file) k
+
+prop_idempotent_key_decode :: FilePath -> Bool
+prop_idempotent_key_decode f
+ | null f = True -- skip illegal empty filename
+ | otherwise = maybe True (\k -> key2file k == f) (file2key f)