packages feed

dirfiles 0.1.0.4 → 0.1.0.8

raw patch · 2 files changed

+23/−5 lines, 2 files

Files

Data/Library.hs view
@@ -1,4 +1,7 @@-{-# LANGUAGE OverloadedStrings,TemplateHaskell, BangPatterns #-}+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-}  module Data.Library  ( Library , ItemId@@ -14,15 +17,19 @@ , new , unsafeGetItem , getItem+, getItemMaybe+, showError+, isDir -- , testItems )  where-import Data.Text (Text)+import Data.Text (Text, pack) import Data.IntSet (IntSet, insert) import qualified Data.IntSet as IS import Data.Sequence (Seq, (|>)) import qualified Data.Sequence as Seq+import Data.Data (Typeable) import Data.Time.Clock (UTCTime) import Data.Library.UUIRI (UUIRI, iri, uuid, toUUIRI) import Control.Applicative ((<$>), (<*>))@@ -38,7 +45,6 @@ -- | A Library is just a rebranded Seq type Library = Seq LibraryItem - type ItemId = Int  empty :: Library@@ -117,6 +123,11 @@                      in case item of                              Deleted -> Left $ ItemNotFound i                             _ -> Right item++-- | getItem tailored to return an Error if the 2nd argument is Nothing+getItemMaybe :: ItemId -> Maybe Library -> Either Error LibraryItem+getItemMaybe i (Just l) = getItem i l+getItemMaybe _ Nothing = Left InvalidContainer --- // --- -- HELPERS itemOpInDir :: (Int -> IntSet -> IntSet) -> LibraryItem -> LibraryItem @@ -154,7 +165,7 @@     , itemDateModified :: !UTCTime     , itemParent       :: !ItemId -- root dir has parent = 0     , itemType         :: !(Either Directory UUIRI)-    } +    } deriving (Typeable)  {- testItems t = @@ -217,11 +228,16 @@ -- | Some errors that might occur data Error = InvalidDestination ItemId            | ItemNotFound ItemId+           | InvalidContainer            | MovingRoot+           deriving(Eq, Ord, Typeable) instance Show Error where     show (InvalidDestination i) = "Invalid destination with id " ++ (show i)     show (ItemNotFound i) = "Item with id " ++ (show i) ++ " not found"     show MovingRoot = "Cannot move root directory"++showError :: Error -> Text+showError e = pack $ show e {- newFileTextIO :: Text -> Text -> IO FileText newFileTextIO n c = do@@ -229,5 +245,6 @@     return $ newFileText n t c -} +$(deriveSafeCopy 0 'base ''Error) $(deriveSafeCopy 0 'base ''Directory) $(deriveSafeCopy 0 'base ''LibraryItem)
dirfiles.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                dirfiles-version:             0.1.0.4+version:             0.1.0.8 -- synopsis:             description:         Simple datatype to represent a library with files and folders license:             BSD3@@ -27,5 +27,6 @@                ,    unordered-containers >=0.2 && <0.3                ,    safecopy >=0.8                 ,    hblock >=0.1 +   -- hs-source-dirs:         default-language:    Haskell2010