class Dir d where
  localDir :: d -> IO FilePath

data Package = Cabal Directory 
               | SourceTree Directory
                 deriving (Read,Show,Typeable,Data)


-- A (possibly remote) directory that can be mapped to a local one.
data Directory = Local FilePath
               | Darcs {url::URL,darcsVersion::DarcsVersion,subDirectory::FilePath} deriving (Read,Show,Typeable,Data)

data DarcsVersion = Patch String | Tag String deriving (Read,Show,Typeable,Data)

instance Dir Directory where
  localDir (Local f) = return f

  localDir (Darcs {url=url,darcsVersion=Patch patch,subDirectory=subDir}) = do 
    tmp <- createTempDir 0 "haskelld"
    darcsOut <- runDarcsCommand tmp "get" ["--lazy","--to-match","hash "++ patch,url,"fs"]
    print darcsOut
    let (ExitSuccess,"",out) = darcsOut 
    print out
    return $ tmp </> "fs" </> subDir

type URL = String
