fail before suing when not in a git-annex repo

This commit is contained in:
Joey Hess 2016-12-20 17:46:14 -04:00
parent f7ca2b92fb
commit 86401f84e2
No known key found for this signature in database
GPG key ID: C910D9222512E3C7

View file

@ -32,12 +32,15 @@ seek = withWords start
start :: [String] -> CommandStart start :: [String] -> CommandStart
start os = do start os = do
uuid <- getUUID
when (uuid == NoUUID) $
giveup "This can only be run in a git-annex repository."
#ifndef mingw32_HOST_OS #ifndef mingw32_HOST_OS
curruserid <- liftIO getEffectiveUserID curruserid <- liftIO getEffectiveUserID
if curruserid == 0 if curruserid == 0
then case readish =<< headMaybe os of then case readish =<< headMaybe os of
Nothing -> giveup "Need user-id parameter." Nothing -> giveup "Need user-id parameter."
Just userid -> go userid Just userid -> go uuid userid
else do else do
liftIO $ putStrLn "Need root access to enable tor..." liftIO $ putStrLn "Need root access to enable tor..."
gitannex <- liftIO readProgramFile gitannex <- liftIO readProgramFile
@ -48,13 +51,10 @@ start os = do
[ "Failed to run as root:" , gitannex ] ++ toCommand ps [ "Failed to run as root:" , gitannex ] ++ toCommand ps
) )
#else #else
go 0 go uuid 0
#endif #endif
where where
go userid = do go uuid userid = do
uuid <- getUUID
when (uuid == NoUUID) $
giveup "This can only be run in a git-annex repository."
(onionaddr, onionport) <- liftIO $ (onionaddr, onionport) <- liftIO $
addHiddenService "tor-annex" userid (fromUUID uuid) addHiddenService "tor-annex" userid (fromUUID uuid)
storeP2PAddress $ TorAnnex onionaddr onionport storeP2PAddress $ TorAnnex onionaddr onionport