webapp: avoid infinite loop on start

If the autostart file lists a repository, for which a directory exists,
but there's not actually a valid git repo in there, the web app used to
try to use it, and see it wasn't valid, and then try to autostart again.

The ensuing runaway loop also ate memory, although not as fast as I was led
to belive was happening to someone on IRC yesterday. So that guy may have
had a different problem. But this seems otherwise a reasonable fit for the
circumstances described, if git-annex was started before something that
occurred during desktop login that made the repository available.
This commit is contained in:
Joey Hess 2012-10-11 12:08:11 -04:00
parent 7aef34f501
commit c0aec874a2

View file

@ -39,9 +39,12 @@ seek :: [CommandSeek]
seek = [withNothing start]
start :: CommandStart
start = notBareRepo $ do
start = start' True
start' :: Bool -> CommandStart
start' allowauto = notBareRepo $ do
liftIO $ ensureInstalled
ifM isInitialized ( go , liftIO startNoRepo )
ifM isInitialized ( go , auto )
stop
where
go = do
@ -52,6 +55,11 @@ start = notBareRepo $ do
, startDaemon True True $ Just $
const $ openBrowser browser
)
auto
| allowauto = liftIO startNoRepo
| otherwise = do
d <- liftIO getCurrentDirectory
error $ "no repository for " ++ d
checkpid = do
pidfile <- fromRepo gitAnnexPidFile
liftIO $ isJust <$> checkDaemon pidfile
@ -74,7 +82,7 @@ autoStart autostartfile = do
(d:_) -> do
changeWorkingDirectory d
state <- Annex.new =<< Git.CurrentRepo.get
void $ Annex.eval state $ doCommand start
void $ Annex.eval state $ doCommand $ start' False
{- Run the webapp without a repository, which prompts the user, makes one,
- changes to it, starts the regular assistant, and redirects the