Skip to content

Commit 2ca1b45

Browse files
committed
Revert "Merge pull request #3 from jasagredo/js/fix-local-noindex-windows"
This reverts commit 417a1db, reversing changes made to 0eabec2.
1 parent 324b811 commit 2ca1b45

File tree

7 files changed

+35
-48
lines changed

7 files changed

+35
-48
lines changed

cabal-install/cabal-install.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ library
230230
echo >= 0.1.3 && < 0.2,
231231
edit-distance >= 0.2.2 && < 0.3,
232232
exceptions >= 0.10.4 && < 0.11,
233-
file-uri >= 0.1 && < 0.2,
234233
filepath >= 1.4.0.0 && < 1.6,
235234
HTTP >= 4000.1.5 && < 4000.5,
236235
mtl >= 2.0 && < 2.4,

cabal-install/src/Distribution/Client/Config.hs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ import Distribution.Utils.NubList
110110
)
111111

112112
import qualified Data.ByteString as BS
113-
import qualified Data.ByteString.Char8 as BS8
114113
import qualified Data.Map as M
115114
import Distribution.Client.Errors
116115
import Distribution.Client.HttpUtils
@@ -208,10 +207,6 @@ import Distribution.Simple.Utils
208207
, warn
209208
)
210209
import Distribution.Solver.Types.ConstraintSource
211-
import Distribution.System
212-
( OS (Windows)
213-
, buildOS
214-
)
215210
import Distribution.Utils.Path (getSymbolicPath, unsafeMakeSymbolicPath)
216211
import Distribution.Verbosity
217212
( normal
@@ -220,7 +215,6 @@ import Network.URI
220215
( URI (..)
221216
, URIAuth (..)
222217
, parseURI
223-
, uriToString
224218
)
225219
import System.Directory
226220
( XdgDirectory (XdgCache, XdgConfig, XdgState)
@@ -240,11 +234,6 @@ import System.FilePath
240234
import System.IO.Error
241235
( isDoesNotExistError
242236
)
243-
import System.URI.File
244-
( FileURI (..)
245-
, ParseSyntax (..)
246-
, parseFileURI
247-
)
248237
import Text.PrettyPrint
249238
( ($+$)
250239
)
@@ -1060,12 +1049,12 @@ readConfigFile initial file =
10601049
else ioError ioe
10611050

10621051
createDefaultConfigFile :: Verbosity -> [String] -> FilePath -> IO SavedConfig
1063-
createDefaultConfigFile verbosity extraLines filepath = do
1052+
createDefaultConfigFile verbosity extraLines filePath = do
10641053
commentConf <- commentSavedConfig
10651054
initialConf <- initialSavedConfig
10661055
extraConf <- parseExtraLines verbosity extraLines
1067-
notice verbosity $ "Writing default configuration to " ++ filepath
1068-
writeConfigFile filepath commentConf (initialConf `mappend` extraConf)
1056+
notice verbosity $ "Writing default configuration to " ++ filePath
1057+
writeConfigFile filePath commentConf (initialConf `mappend` extraConf)
10691058
return initialConf
10701059

10711060
writeConfigFile :: FilePath -> SavedConfig -> SavedConfig -> IO ()
@@ -1703,18 +1692,8 @@ postProcessRepo lineno reponameStr repo0 = do
17031692
-- TODO: check that there are no authority, query or fragment
17041693
-- Note: the trailing colon is important
17051694
"file+noindex:" -> do
1706-
-- defer to file-uri package which is more accurate when parsing Windows
1707-
-- paths
1708-
let uri' = BS8.pack $ "file:" ++ uriToString id ((remoteRepoURI repo0) { uriScheme = "" }) []
1709-
case parseFileURI (if buildOS == Windows then ExtendedWindows else ExtendedPosix) uri' of
1710-
Left{} -> fail $ "Invalid path in URI: " <> show (remoteRepoURI repo0)
1711-
Right uri'' ->
1712-
return
1713-
$ Left
1714-
$ LocalRepo
1715-
reponame
1716-
(BS8.unpack $ filePath uri'')
1717-
(uriFragment (remoteRepoURI repo0) == "#shared-cache")
1695+
let uri = remoteRepoURI repo0
1696+
return $ Left $ LocalRepo reponame (uriPath uri) (uriFragment uri == "#shared-cache")
17181697
_ -> do
17191698
let repo = repo0{remoteRepoName = reponame}
17201699

cabal-install/src/Distribution/Client/GlobalFlags.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import qualified Hackage.Security.Client.Repository.Remote as Sec.Remote
6969
import qualified Hackage.Security.Util.Path as Sec
7070
import qualified Hackage.Security.Util.Pretty as Sec
7171

72-
import qualified System.FilePath as FilePath
72+
import qualified System.FilePath.Posix as FilePath.Posix
7373

7474
-- ------------------------------------------------------------
7575

@@ -192,9 +192,9 @@ withRepoContext'
192192
ignoreExpiry
193193
extraPaths = \callback -> do
194194
for_ localNoIndexRepos $ \local ->
195-
unless (FilePath.isAbsolute (localRepoPath local)) $
195+
unless (FilePath.Posix.isAbsolute (localRepoPath local)) $
196196
warn verbosity $
197-
"file+noindex " ++ unRepoName (localRepoName local) ++ " repository path (" ++ show (localRepoPath local) ++ ") is not absolute; this is fragile, and not recommended"
197+
"file+noindex " ++ unRepoName (localRepoName local) ++ " repository path is not absolute; this is fragile, and not recommended"
198198

199199
transportRef <- newMVar Nothing
200200
let httpLib =

cabal-install/src/Distribution/Client/IndexUtils.hs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ import Distribution.Compat.Directory (listDirectory)
142142
import Distribution.Compat.Time (getFileAge, getModTime)
143143
import Distribution.Utils.Generic (fstOf3)
144144
import Distribution.Utils.Structured (Structured (..), nominalStructure, structuredDecodeFileOrFail, structuredEncodeFile)
145-
import System.Directory (doesDirectoryExist, doesFileExist, makeAbsolute)
145+
import System.Directory (doesDirectoryExist, doesFileExist)
146146
import System.FilePath
147147
( normalise
148148
, splitDirectories
@@ -900,9 +900,7 @@ withIndexEntries verbosity (RepoIndex _repoCtxt (RepoLocalNoIndex (LocalRepo nam
900900
entries
901901
case tarballPackageDescription of
902902
Just ce -> return (Just ce)
903-
Nothing -> do
904-
tarFile' <- makeAbsolute tarFile
905-
dieWithException verbosity $ CannotReadCabalFile expectFilename tarFile'
903+
Nothing -> dieWithException verbosity $ CannotReadCabalFile expectFilename tarFile
906904

907905
let (prefs, gpds) =
908906
partitionEithers $
@@ -977,8 +975,7 @@ withIndexEntries verbosity (RepoIndex _repoCtxt (RepoLocalNoIndex (LocalRepo nam
977975
-- Here we show the _failure_ to parse the `.cabal` file as
978976
-- a warning. This will impact which versions/packages are
979977
-- available in your index, so users should know!
980-
tarFile' <- makeAbsolute tarFile
981-
warn verbosity $ "In " <> tarFile' <> ": " <> displayException exception
978+
warn verbosity $ "In " <> tarFile <> ": " <> displayException exception
982979
pure Nothing
983980
Right genericPackageDescription ->
984981
pure $ Just $ CacheGPD genericPackageDescription bytes

cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ normalizeOutput nenv =
4646
. resub (posixRegexEscape "tmp/src-" ++ "[0-9]+") "<TMPDIR>"
4747
. resub (posixRegexEscape (normalizerTmpDir nenv) ++ sameDir) "<ROOT>/"
4848
. resub (posixRegexEscape (normalizerCanonicalTmpDir nenv) ++ sameDir) "<ROOT>/"
49+
. (if buildOS == Windows
50+
then
51+
-- OK. Here's the deal. In `./Prelude.hs`, `withRepoNoUpdate` sets
52+
-- `repoUri` to the tmpdir but with backslashes replaced with
53+
-- slashes. This is because Windows treats backslashes and forward
54+
-- slashes largely the same in paths, and backslashes aren't allowed
55+
-- in a URL like `file+noindex://...`.
56+
--
57+
-- But that breaks the regexes above, which expect the paths to have
58+
-- backslashes.
59+
--
60+
-- Honestly this whole `normalizeOutput` thing is super janky and
61+
-- worth rewriting from the ground up. To you, poor soul in the
62+
-- future, here is one more hack upon a great pile. Hey, at least all
63+
-- the `PackageTests` function as a test suite for this thing...
64+
resub (posixRegexEscape (backslashToSlash $ normalizerTmpDir nenv) ++ sameDir) "<ROOT>/"
65+
. resub (posixRegexEscape (backslashToSlash $ normalizerCanonicalTmpDir nenv) ++ sameDir) "<ROOT>/"
66+
else id)
4967
-- Munge away C: prefix on filenames (Windows). We convert C:\\ to \\.
5068
. (if buildOS == Windows then resub "([A-Z]):\\\\" "\\\\" else id)
5169
. appEndo (F.fold (map (Endo . packageIdRegex) (normalizerKnownPackages nenv)))

cabal-testsuite/src/Test/Cabal/Prelude.hs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -608,15 +608,11 @@ withRepoNoUpdate repo_dir m = do
608608
withReaderT (\env' -> env' { testHaveRepo = True }) m
609609
-- TODO: Arguably should undo everything when we're done...
610610
where
611-
repoUri env ="file+noindex://"
612-
++ (if isWindows
613-
-- Windows paths need a preceeding slash to be compliant with file
614-
-- URI RFCs (8089 and 3986). In particular to be an instance of
615-
-- @path-absolute@.
616-
then ('/' :) . map (\x -> case x of
617-
'\\' -> '/'
618-
_ -> x)
619-
else id) (testRepoDir env)
611+
repoUri env ="file+noindex://" ++ (if isWindows
612+
then map (\x -> case x of
613+
'\\' -> '/'
614+
_ -> x)
615+
else id) (testRepoDir env)
620616

621617
-- | Given a directory (relative to the 'testCurrentDir') containing
622618
-- a series of directories representing packages, generate an

doc/config.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,7 @@ repository.
198198

199199
``cabal`` will construct the index automatically from the
200200
``package-name-version.tar.gz`` files in the directory, and will use optional
201-
corresponding ``package-name-version.cabal`` files as new revisions. Note that
202-
Windows should use three slashes too, as in
203-
``file+noindex:///C:/absolute/path/to/directory``.
201+
corresponding ``package-name-version.cabal`` files as new revisions.
204202

205203
For example, if ``/absolute/path/to/directory`` looks like
206204
::

0 commit comments

Comments
 (0)