Skip to content

Commit 604b629

Browse files
committed
Fix commercialhaskell#4726: On Windows, warn on 'programs' path with space, no 8dot3 name
In module `Stack.Config`, function `configFromConfigMonoid`, a stack user is warned if the stack 'programs' path contains a space character and does not have an alternative short ('8 dot 3') name,warned of the implications for packages that make use of the GNU project's `configure` shell script. New modules `System.Info.ShortPathName` are added to `src/windows` and `src/unix` to rexport `getShortPathName` from the `System.Win32.Info` module of the `Win32` package in the case of Windows and do nothing in the case of Unix-like operating systems. This avoids the need for C preprocessor (CPP) directives in `Stack.Config`. `ChangeLog.md` is updated, accordingly. Tested on Windows 10 with 'programs' paths that do and do not contain space characters and, in the latter case, with paths that do and do not have '8 dot 3' names. Tested with paths that do not yet exist when stack is first run.
1 parent 5d1ad0d commit 604b629

5 files changed

Lines changed: 37 additions & 0 deletions

File tree

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ Other enhancements:
239239
[#2226](https://github.com/commercialhaskell/stack/issues/2226)
240240
* Windows terminal width detection is now done. See
241241
[#3588](https://github.com/commercialhaskell/stack/issues/3588)
242+
* On Windows, informs users if the 'programs' path contains a space character
243+
and further warns users if that path does not have an alternative short
244+
('8 dot 3') name, referencing the `local-programs-path` configuration option.
245+
See [#4726](https://github.com/commercialhaskell/stack/issues/4726)
242246

243247
Bug fixes:
244248

package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ library:
243243
- Stack.Unpack
244244
- Stack.Upgrade
245245
- Stack.Upload
246+
- System.Info.ShortPathName
246247
- System.Permissions
247248
- System.Process.Pager
248249
- System.Terminal

src/Stack/Config.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import Stack.Types.SourceMap
7575
import Stack.Types.Version
7676
import System.Console.ANSI (hSupportsANSIWithoutEmulation)
7777
import System.Environment
78+
import System.Info.ShortPathName (getShortPathName)
7879
import System.PosixCompat.Files (fileOwner, getFileStatus)
7980
import System.PosixCompat.User (getEffectiveUserID)
8081
import RIO.List (unzip)
@@ -270,6 +271,20 @@ configFromConfigMonoid
270271
configLocalProgramsBase <- case getFirst configMonoidLocalProgramsBase of
271272
Nothing -> getDefaultLocalProgramsBase configStackRoot configPlatform origEnv
272273
Just path -> return path
274+
let localProgramsFilePath = toFilePath configLocalProgramsBase
275+
when (osIsWindows && ' ' `elem` localProgramsFilePath) $ do
276+
ensureDir configLocalProgramsBase
277+
-- getShortPathName returns the long path name when a short name does not
278+
-- exist.
279+
shortLocalProgramsFilePath <-
280+
liftIO $ getShortPathName localProgramsFilePath
281+
when (' ' `elem` shortLocalProgramsFilePath) $ do
282+
logWarn $ "Stack's 'programs' path contains a space character and " <>
283+
"has no alternative short ('8 dot 3') name. This will cause " <>
284+
"problems with packages that use the GNU project's 'configure' " <>
285+
"shell script. Use the 'local-programs-path' configuation option " <>
286+
"to specify an alternative path. The current 'shortest' path is: " <>
287+
display (T.pack shortLocalProgramsFilePath)
273288
platformOnlyDir <- runReaderT platformOnlyRelDir (configPlatform, configPlatformVariant)
274289
let configLocalPrograms = configLocalProgramsBase </> platformOnlyDir
275290

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{-# LANGUAGE NoImplicitPrelude #-}
2+
3+
module System.Info.ShortPathName
4+
( getShortPathName
5+
) where
6+
7+
import RIO.FilePath (FilePath)
8+
import RIO.Prelude (pure)
9+
import RIO.Prelude.Types (IO)
10+
11+
getShortPathName :: FilePath -> IO FilePath
12+
getShortPathName = pure
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module System.Info.ShortPathName
2+
( getShortPathName
3+
) where
4+
5+
import System.Win32.Info (getShortPathName)

0 commit comments

Comments
 (0)