default repository location

Unifying poll results, it's Annex in lowercase. :)

When cwd is HOME, use ~/Desktop/annex, unless there's no Desktop directory;
then use use ~/annex

If cwd is not $HOME, use cwd
This commit is contained in:
Joey Hess 2012-07-31 21:06:30 -04:00
parent bab80bf24a
commit e81e8913d9

View file

@ -19,7 +19,7 @@ import Logs.Trust
import Annex.UUID (getUUID)
import Yesod
import Data.Text (Text, pack)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Char
@ -96,10 +96,24 @@ checkRepositoryPath p = do
expandTilde home ('~':path) = home </> path
expandTilde _ path = path
{- If run in the home directory, default to putting it in ~/Desktop/annex,
- when a Desktop directory exists, and ~/annex otherwise.
-
- If run in another directory, the user probably wants to put it there. -}
defaultRepositoryPath :: IO FilePath
defaultRepositoryPath = do
cwd <- liftIO $ getCurrentDirectory
home <- myHomeDir
if home == cwd
then ifM (doesDirectoryExist $ home </> "Desktop")
(return "~/Desktop/annex", return "~")
else return cwd
addRepositoryForm :: Form RepositoryPath
addRepositoryForm msg = do
cwd <- liftIO $ getCurrentDirectory
(pathRes, pathView) <- mreq (repositoryPathField True) "" (Just $ pack $ cwd ++ "/")
path <- T.pack . addTrailingPathSeparator
<$> liftIO defaultRepositoryPath
(pathRes, pathView) <- mreq (repositoryPathField True) ""(Just path)
let (err, errmsg) = case pathRes of
FormMissing -> (False, "")
FormFailure l -> (True, concat $ map T.unpack l)