summaryrefslogtreecommitdiff
path: root/Types
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-03-10 13:12:24 -0400
committerJoey Hess <joeyh@joeyh.name>2017-03-10 13:35:31 -0400
commitc8e1e3dadaf96106850104d4a7f0d49b12ba8b9d (patch)
tree15e06427471c1bc12dee1b6be6435357c66d6285 /Types
parent2cd7496210895f52650127c17fdf04747d712400 (diff)
AssociatedFile newtype
To prevent any further mistakes like 301aff34c42d896038c42e0a0bc7b1cf71e0ad22 This commit was sponsored by Francois Marier on Patreon.
Diffstat (limited to 'Types')
-rw-r--r--Types/ActionItem.hs12
-rw-r--r--Types/Key.hs3
-rw-r--r--Types/Transfer.hs6
3 files changed, 10 insertions, 11 deletions
diff --git a/Types/ActionItem.hs b/Types/ActionItem.hs
index d9beb049da..73d8451017 100644
--- a/Types/ActionItem.hs
+++ b/Types/ActionItem.hs
@@ -13,8 +13,6 @@ import Key
import Types.Transfer
import Git.FilePath
-import Data.Maybe
-
data ActionItem
= ActionItemAssociatedFile AssociatedFile
| ActionItemKey
@@ -37,15 +35,15 @@ instance MkActionItem (Transfer, TransferInfo) where
mkActionItem = uncurry ActionItemFailedTransfer
actionItemDesc :: ActionItem -> Key -> String
-actionItemDesc (ActionItemAssociatedFile (Just f)) _ = f
-actionItemDesc (ActionItemAssociatedFile Nothing) k = key2file k
+actionItemDesc (ActionItemAssociatedFile (AssociatedFile (Just f))) _ = f
+actionItemDesc (ActionItemAssociatedFile (AssociatedFile Nothing)) k = key2file k
actionItemDesc ActionItemKey k = key2file k
actionItemDesc (ActionItemBranchFilePath bfp) _ = descBranchFilePath bfp
-actionItemDesc (ActionItemFailedTransfer _ i) k =
- fromMaybe (key2file k) (associatedFile i)
+actionItemDesc (ActionItemFailedTransfer _ i) k =
+ actionItemDesc (ActionItemAssociatedFile (associatedFile i)) k
actionItemWorkTreeFile :: ActionItem -> Maybe FilePath
-actionItemWorkTreeFile (ActionItemAssociatedFile af) = af
+actionItemWorkTreeFile (ActionItemAssociatedFile (AssociatedFile af)) = af
actionItemWorkTreeFile _ = Nothing
actionItemTransferDirection :: ActionItem -> Maybe Direction
diff --git a/Types/Key.hs b/Types/Key.hs
index 9df1144aaa..44ebe3ca0a 100644
--- a/Types/Key.hs
+++ b/Types/Key.hs
@@ -23,7 +23,8 @@ data Key = Key
} deriving (Eq, Ord, Read, Show)
{- A filename may be associated with a Key. -}
-type AssociatedFile = Maybe FilePath
+newtype AssociatedFile = AssociatedFile (Maybe FilePath)
+ deriving (Show, Eq, Ord)
{- There are several different varieties of keys. -}
data KeyVariety
diff --git a/Types/Transfer.hs b/Types/Transfer.hs
index 349eccf4be..ade8fc7630 100644
--- a/Types/Transfer.hs
+++ b/Types/Transfer.hs
@@ -36,13 +36,13 @@ data TransferInfo = TransferInfo
, transferTid :: Maybe ThreadId
, transferRemote :: Maybe Remote
, bytesComplete :: Maybe Integer
- , associatedFile :: Maybe FilePath
+ , associatedFile :: AssociatedFile
, transferPaused :: Bool
}
deriving (Show, Eq, Ord)
stubTransferInfo :: TransferInfo
-stubTransferInfo = TransferInfo Nothing Nothing Nothing Nothing Nothing Nothing False
+stubTransferInfo = TransferInfo Nothing Nothing Nothing Nothing Nothing (AssociatedFile Nothing) False
data Direction = Upload | Download
deriving (Eq, Ord, Show, Read)
@@ -64,5 +64,5 @@ instance Arbitrary TransferInfo where
<*> pure Nothing -- remote not needed
<*> arbitrary
-- associated file cannot be empty (but can be Nothing)
- <*> arbitrary `suchThat` (/= Just "")
+ <*> (AssociatedFile <$> arbitrary `suchThat` (/= Just ""))
<*> arbitrary