cleanCapsule :: FilePath -- Capsule location
               -> IO ()
  cleanCapsule capsule = 
    let cacheDirs = [
              "var/cache/pacman/pkg"
            , "var/log"
          ]
        rmdir dir = do
          debugM "hgc" $ "Removing directory " ++ dir
          removeDirectoryRecursive dir
          mkdir dir
        isDir dir = do
          exists <- doesDirectoryExist dir
          unless (exists) $ debugM "hgc" $ "Directory " ++ dir ++ " does not exist."
          return exists
    in do 
      debugM "hgc" ("Cleaning capsule " ++ capsule)
      join . (liftM $ mapM_ rmdir) . filterM isDir $ 
        map (\a -> capsule </> "rootfs" </> a) cacheDirs
cleanCapsule :: FilePath -- Capsule location
               -> IO ()
cleanCapsule capsule = 
    let cacheDirs = [
              "var/cache/pacman/pkg"
            , "var/log"
          ]
        rmdir dir = do
          debugM "hgc" $ "Removing directory " ++ dir
          removeDirectoryRecursive dir
          mkdir dir
        isDir dir = do
          exists <- doesDirectoryExist dir
          unless (exists) $ debugM "hgc" $ "Directory " ++ dir ++ " does not exist."
          return exists
    in do 
      debugM "hgc" ("Cleaning capsule " ++ capsule)
      join . (liftM $ mapM_ rmdir) . filterM isDir $ 
        map (\a -> capsule </> "rootfs" </> a) cacheDirs
cleanCapsule capsule = 
    let cacheDirs = [
              "var/cache/pacman/pkg"
            , "var/log"
          ]
        rmdir dir = do
          debugM "hgc" $ "Removing directory " ++ dir
          removeDirectoryRecursive dir
          mkdir dir
        isDir dir = do
          exists <- doesDirectoryExist dir
          unless (exists) $ debugM "hgc" $ "Directory " ++ dir ++ " does not exist."
          return exists
    in do 
      debugM "hgc" ("Cleaning capsule " ++ capsule)
      join . (liftM $ mapM_ rmdir) . filterM isDir $ 
        map (\a -> capsule </> "rootfs" </> a) cacheDirs