summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-07-31 21:06:30 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-07-31 21:06:30 -0400
commite81e8913d9c663cbe680224e6237433e7508e7d3 (patch)
treec6da3df4d8b9b095291f0b04bb7fab7ffae1f2dd
parentbab80bf24ada54f8dec2a35bbb77219441719f6a (diff)
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
-rw-r--r--Assistant/WebApp/Configurators.hs20
1 files changed, 17 insertions, 3 deletions
diff --git a/Assistant/WebApp/Configurators.hs b/Assistant/WebApp/Configurators.hs
index 59acb763a..d646e6fb7 100644
--- a/Assistant/WebApp/Configurators.hs
+++ b/Assistant/WebApp/Configurators.hs
@@ -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)