@@ -133,7 +133,7 @@ import Text.PrettyPrint
133
133
import Text.PrettyPrint.HughesPJ
134
134
( text , Doc )
135
135
import System.Directory
136
- ( createDirectoryIfMissing , getHomeDirectory , getXdgDirectory , XdgDirectory (XdgCache , XdgConfig , XdgState ), renameFile , getAppUserDataDirectory , doesDirectoryExist )
136
+ ( createDirectoryIfMissing , getHomeDirectory , getXdgDirectory , XdgDirectory (XdgCache , XdgConfig , XdgState ), renameFile , getAppUserDataDirectory , doesDirectoryExist , doesFileExist )
137
137
import Network.URI
138
138
( URI (.. ), URIAuth (.. ), parseURI )
139
139
import System.FilePath
@@ -590,12 +590,28 @@ initialSavedConfig = do
590
590
}
591
591
}
592
592
593
- -- | If @CABAL\_DIR@ is set or @~/.cabal@ exists, return that
594
- -- directory. Otherwise returns Nothing. If this function returns
595
- -- Nothing, then it implies that we are not using a single directory
596
- -- for everything, but instead use XDG paths. Fundamentally, this
597
- -- function is used to implement transparent backwards compatibility
598
- -- with pre-XDG versions of cabal-install.
593
+ -- | Issue a warning if both @$XDG_CONFIG_HOME/cabal/config@ and
594
+ -- @~/.cabal@ exists.
595
+ warnOnTwoConfigs :: Verbosity -> IO ()
596
+ warnOnTwoConfigs verbosity = do
597
+ defaultDir <- getAppUserDataDirectory " cabal"
598
+ dotCabalExists <- doesDirectoryExist defaultDir
599
+ xdgCfg <- getXdgDirectory XdgConfig (" cabal" </> " config" )
600
+ xdgCfgExists <- doesFileExist xdgCfg
601
+ when (dotCabalExists && xdgCfgExists) $
602
+ warn verbosity $
603
+ " Both " <> defaultDir <>
604
+ " and " <> xdgCfg <>
605
+ " exist - ignoring the former.\n " <>
606
+ " It is advisable to remove one of them. In that case, we will use the remaining one by default (unless '$CABAL_DIR' is explicitly set)."
607
+
608
+ -- | If @CABAL\_DIR@ is set, return @Just@ its value. Otherwise, if
609
+ -- @~/.cabal@ exists and @$XDG_CONFIG_HOME/cabal/config@ does not
610
+ -- exist, return @Just "~/.cabal"@. Otherwise, return @Nothing@. If
611
+ -- this function returns Nothing, then it implies that we are not
612
+ -- using a single directory for everything, but instead use XDG paths.
613
+ -- Fundamentally, this function is used to implement transparent
614
+ -- backwards compatibility with pre-XDG versions of cabal-install.
599
615
maybeGetCabalDir :: IO (Maybe FilePath )
600
616
maybeGetCabalDir = do
601
617
mDir <- lookupEnv " CABAL_DIR"
@@ -604,9 +620,11 @@ maybeGetCabalDir = do
604
620
Nothing -> do
605
621
defaultDir <- getAppUserDataDirectory " cabal"
606
622
dotCabalExists <- doesDirectoryExist defaultDir
607
- return $ if dotCabalExists
608
- then Just defaultDir
609
- else Nothing
623
+ xdgCfg <- getXdgDirectory XdgConfig (" cabal" </> " config" )
624
+ xdgCfgExists <- doesFileExist xdgCfg
625
+ if dotCabalExists && not xdgCfgExists
626
+ then return $ Just defaultDir
627
+ else return Nothing
610
628
611
629
-- | The default behaviour of cabal-install is to use the XDG
612
630
-- directory standard. However, if @CABAL_DIR@ is set, we instead use
@@ -759,6 +777,7 @@ defaultHackageRemoteRepoKeyThreshold = 3
759
777
--
760
778
loadConfig :: Verbosity -> Flag FilePath -> IO SavedConfig
761
779
loadConfig verbosity configFileFlag = do
780
+ warnOnTwoConfigs verbosity
762
781
config <- loadRawConfig verbosity configFileFlag
763
782
extendToEffectiveConfig config
764
783
0 commit comments