file2key should return Nothing if the backend is empty

This failed a quickcheck test on the filename "-a"
This commit is contained in:
Joey Hess 2013-11-11 15:41:31 -04:00
parent 2f1af69878
commit 4b32a6c711

View file

@ -60,7 +60,9 @@ key2file Key { keyBackendName = b, keySize = s, keyMtime = m, keyName = n } =
_ ?: _ = ""
file2key :: FilePath -> Maybe Key
file2key s = if key == Just stubKey || (keyName <$> key) == Just "" then Nothing else key
file2key s
| key == Just stubKey || (keyName <$> key) == Just "" || (keyBackendName <$> key) == Just "" = Nothing
| otherwise = key
where
key = startbackend stubKey s
@ -91,6 +93,4 @@ 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)
prop_idempotent_key_decode f = maybe True (\k -> key2file k == f) (file2key f)