[darcs-users] darcs patch: refactor get_global, make it more cross-platform

David Roundy droundy at darcs.net
Mon Oct 27 18:43:23 UTC 2008


On Sun, Oct 26, 2008 at 03:15:38PM -0700, Simon Michael wrote:
> Sun Oct 26 15:03:54 PDT 2008  Simon Michael <simon at joyful.com>
>   * refactor get_global, make it more cross-platform
>   get_global fetches global preferences from the user's ~/.darcs directory.
>   This patch uses the more portable getAppUserDataDirectory, so global
>   prefs will work on windows without requiring a HOME environment
>   variable, and will be stored in the standard windows app data dir
>   (eg C:/Documents And Settings/user/Application Data/darcs).
>   Cf http://hackage.haskell.org/trac/ghc/ticket/1838 .
>   It also reduces the use of error-hiding catchall.

Applied, thanks!

(and as always, thanks for sending docs with the change!)

> hunk ./src/Darcs/Repository/Prefs.lhs 237
>  is_darcsdir fp = darcsdir `isPrefixOf` fp
>  boring_file_filter :: IO ([FilePath] -> [FilePath])
>  
> -get_global f = (getEnv "HOME" >>= get_preffile.(++("/.darcs/"++f)))
> -               `catchall` return []
> +global_prefs_dir :: IO (Maybe FilePath)
> +global_prefs_dir = (getAppUserDataDirectory "darcs" >>= return.Just)
> +                   `catchall` (return Nothing)
> +
> +get_global f = do
> +  dir <- global_prefs_dir
> +  case dir of
> +    (Just d) -> get_preffile $ d </> f
> +    Nothing -> return []

The parens around Just d here aren't needed.  Not a big deal, but it's
worth learning, as code is generally clearer without extra parentheses
(which is why we aren't all using lisp...).  :)

The parens around return Nothing above also aren't needed, but they're
in a somewhat more confusing section of code, so they could be seen as
clarifying.

David


More information about the darcs-users mailing list