better ~/ handling

This commit is contained in:
Joey Hess 2012-08-02 07:47:50 -04:00
parent 112ce4f49c
commit 9a038b4a9b
3 changed files with 12 additions and 6 deletions

View file

@ -64,12 +64,9 @@ webAppThread mst dstatus transferqueue postfirstrun onstartup = do
Just st -> go port webapp =<< runThreadState st (fromRepo gitAnnexHtmlShim) Just st -> go port webapp =<< runThreadState st (fromRepo gitAnnexHtmlShim)
where where
getreldir Nothing = return Nothing getreldir Nothing = return Nothing
getreldir (Just st) = do getreldir (Just st) = Just <$>
dir <- absPath =<< runThreadState st (fromRepo repoPath) (relHome =<< absPath
home <- myHomeDir =<< runThreadState st (fromRepo repoPath))
return $ Just $ if dirContains home dir
then relPathDirToFile home dir
else dir
go port webapp htmlshim = do go port webapp htmlshim = do
writeHtmlShim webapp port htmlshim writeHtmlShim webapp port htmlshim
maybe noop (\a -> a (myUrl webapp port "/") htmlshim) onstartup maybe noop (\a -> a (myUrl webapp port "/") htmlshim) onstartup

View file

@ -22,6 +22,7 @@ import qualified Git.Construct
import qualified Git.Config import qualified Git.Config
import qualified Annex import qualified Annex
import Locations.UserConfig import Locations.UserConfig
import Utility.FreeDesktop
import Yesod import Yesod
import Data.Text (Text) import Data.Text (Text)

View file

@ -132,6 +132,14 @@ runPreserveOrder a files = preserveOrder files <$> a files
myHomeDir :: IO FilePath myHomeDir :: IO FilePath
myHomeDir = homeDirectory <$> (getUserEntryForID =<< getEffectiveUserID) myHomeDir = homeDirectory <$> (getUserEntryForID =<< getEffectiveUserID)
{- Converts paths in the home directory to use ~/ -}
relHome :: FilePath -> IO String
relHome path = do
home <- myHomeDir
return $ if dirContains home path
then "~/" ++ relPathDirToFile home path
else path
{- Checks if a command is available in PATH. -} {- Checks if a command is available in PATH. -}
inPath :: String -> IO Bool inPath :: String -> IO Bool
inPath command = getSearchPath >>= anyM indir inPath command = getSearchPath >>= anyM indir