diff options
author | Joey Hess <joey@kitenet.net> | 2013-10-16 12:46:24 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-10-16 12:46:24 -0400 |
commit | 3a31b000bbe0db0948f0422020f7381909b93e57 (patch) | |
tree | 9fc63f92be8415d15bd4ac82f47b9079683092ed /Types/Key.hs | |
parent | 12a038aa806f16004f4e4afa8f3ee9fa752eae29 (diff) |
tighten file2key to not produce invalid keys with no keyName
A file named "foo-" or "foo-bar" was taken as a key's file, with a backend
of "foo", and an empty keyName. This led to various problems, especially
because converting that key back to a file did not yeild the same filename.
Diffstat (limited to 'Types/Key.hs')
-rw-r--r-- | Types/Key.hs | 10 |
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) |