aboutsummaryrefslogtreecommitdiff
path: root/Command/WebApp.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-05-21 15:41:36 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-05-21 15:41:54 -0400
commit4220e2ab4c360f03378072ca387c5faa1825d8ec (patch)
tree43ca9a58c02c372f2d5cb8e5204525f74ecc1598 /Command/WebApp.hs
parent676a655c895324fbcc6d6c0d83d1c74d6bafc01f (diff)
webapp: More robust startup when annex directory is not a git repo or not intialized by git-annex.
Diffstat (limited to 'Command/WebApp.hs')
-rw-r--r--Command/WebApp.hs23
1 files changed, 13 insertions, 10 deletions
diff --git a/Command/WebApp.hs b/Command/WebApp.hs
index 5256e8bb8..575d17330 100644
--- a/Command/WebApp.hs
+++ b/Command/WebApp.hs
@@ -59,13 +59,14 @@ start' :: Bool -> Maybe HostName -> CommandStart
start' allowauto listenhost = do
liftIO ensureInstalled
ifM isInitialized
- ( go
- , auto
+ ( maybe notinitialized (go <=< needsUpgrade) =<< getVersion
+ , if allowauto
+ then liftIO $ startNoRepo []
+ else notinitialized
)
stop
where
- go = do
- cannotrun <- needsUpgrade . fromMaybe (error "annex.version is not set.. seems this repository has not been initialized by git-annex") =<< getVersion
+ go cannotrun = do
browser <- fromRepo webBrowser
f <- liftIO . absPath =<< fromRepo gitAnnexHtmlShim
listenhost' <- if isJust listenhost
@@ -87,15 +88,14 @@ start' allowauto listenhost = do
then maybe noop (`hPutStrLn` url) origout
else openBrowser browser htmlshim url origout origerr
)
- auto
- | allowauto = liftIO $ startNoRepo []
- | otherwise = do
- d <- liftIO getCurrentDirectory
- error $ "no git repository in " ++ d
checkpid = do
pidfile <- fromRepo gitAnnexPidFile
liftIO $ isJust <$> checkDaemon pidfile
checkshim f = liftIO $ doesFileExist f
+ notinitialized = do
+ g <- Annex.gitRepo
+ liftIO $ cannotStartIn (Git.repoLocation g) "repository has not been initialized by git-annex"
+ liftIO $ firstRun listenhost
{- When run without a repo, start the first available listed repository in
- the autostart file. If none, it's our first time being run! -}
@@ -116,7 +116,7 @@ startNoRepo _ = do
Annex.new =<< Git.CurrentRepo.get
case v of
Left e -> do
- warningIO $ "unable to start webapp in " ++ d ++ ": " ++ show e
+ cannotStartIn d (show e)
go listenhost ds
Right state -> void $ Annex.eval state $ do
whenM (fromRepo Git.repoIsLocalBare) $
@@ -124,6 +124,9 @@ startNoRepo _ = do
callCommandAction $
start' False listenhost
+cannotStartIn :: FilePath -> String -> IO ()
+cannotStartIn d reason = warningIO $ "unable to start webapp in repository " ++ d ++ ": " ++ reason
+
{- Run the webapp without a repository, which prompts the user, makes one,
- changes to it, starts the regular assistant, and redirects the
- browser to its url.