Skip to content

Commit 59e285e

Browse files
authored
Merge pull request #6207 from commercialhaskell/fix6206
Fix #6206 Use short temp path in `withUnpackedTarball7z`
2 parents 1f7d629 + 21d64c5 commit 59e285e

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/Stack/Setup.hs

+12-8
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import Network.HTTP.StackClient
6565
)
6666
import Network.HTTP.Simple ( getResponseHeader )
6767
import Path
68-
( (</>), addExtension, dirname, filename, parent, parseAbsDir
68+
( (</>), addExtension, filename, parent, parseAbsDir
6969
, parseAbsFile, parseRelDir, parseRelFile, toFilePath
7070
)
7171
import Path.CheckInstall ( warnInstallSearchPathIssues )
@@ -74,7 +74,7 @@ import Path.Extra ( toFilePathNoTrailingSep )
7474
import Path.IO
7575
( canonicalizePath, doesFileExist, ensureDir, executable
7676
, getPermissions, ignoringAbsence, listDir, removeDirRecur
77-
, renameDir, renameFile, resolveFile', withTempDir
77+
, renameDir, renameFile, resolveFile'
7878
)
7979
import RIO.List
8080
( headMaybe, intercalate, intersperse, isPrefixOf
@@ -2322,12 +2322,16 @@ withUnpackedTarball7z name si archiveFile archiveType destDir = do
23222322
Nothing -> prettyThrowIO $ TarballFileInvalid name archiveFile
23232323
Just x -> parseRelFile $ T.unpack x
23242324
run7z <- setup7z si
2325-
-- Truncate the name of the temporary directory, to reduce risk of Windows'
2326-
-- default file path length of 260 characters being exceeded.
2327-
let tmpName = take 15 (toFilePathNoTrailingSep (dirname destDir)) ++ "-tmp"
2325+
-- We use a short name for the temporary directory to reduce the risk of a
2326+
-- filepath length of more than 260 characters, which can be problematic for
2327+
-- 7-Zip even if Long Filepaths are enabled on Windows.
2328+
let tmpName = "tmp"
23282329
ensureDir (parent destDir)
23292330
withRunInIO $ \run ->
2330-
withTempDir (parent destDir) tmpName $ \tmpDir ->
2331+
-- We use the system temporary directory to reduce the risk of a filepath
2332+
-- length of more than 260 characters, which can be problematic for
2333+
-- 7-Zip even if Long Filepaths are enabled on Windows.
2334+
withSystemTempDir tmpName $ \tmpDir ->
23312335
run $ do
23322336
liftIO $ ignoringAbsence (removeDirRecur destDir)
23332337
run7z tmpDir archiveFile
@@ -2340,8 +2344,8 @@ expectSingleUnpackedDir ::
23402344
=> Path Abs File
23412345
-> Path Abs Dir
23422346
-> m (Path Abs Dir)
2343-
expectSingleUnpackedDir archiveFile destDir = do
2344-
contents <- listDir destDir
2347+
expectSingleUnpackedDir archiveFile unpackDir = do
2348+
contents <- listDir unpackDir
23452349
case contents of
23462350
([dir], _ ) -> pure dir
23472351
_ -> prettyThrowIO $ UnknownArchiveStructure archiveFile

0 commit comments

Comments
 (0)