@@ -82,9 +82,9 @@ import Path.CheckInstall ( warnInstallSearchPathIssues )
82
82
import Path.Extra ( toFilePathNoTrailingSep )
83
83
import Path.IO
84
84
( canonicalizePath , doesFileExist , ensureDir , executable
85
- , getPermissions , ignoringAbsence , listDir , removeDirRecur
86
- , removeFile , renameDir , renameFile , resolveFile'
87
- , withTempDir
85
+ , getPermissions , getTempDir , ignoringAbsence , listDir
86
+ , removeDirRecur , removeFile , renameDir , renameFile
87
+ , resolveFile' , withTempDir
88
88
)
89
89
import RIO.List
90
90
( headMaybe , intercalate , intersperse , isPrefixOf
@@ -2454,19 +2454,26 @@ withUnpackedTarball7z name si archiveFile archiveType destDir = do
2454
2454
Nothing -> prettyThrowIO $ TarballFileInvalid name archiveFile
2455
2455
Just x -> parseRelFile $ T. unpack x
2456
2456
run7z <- setup7z si
2457
- -- We use a short name for the temporary directory to reduce the risk of a
2458
- -- filepath length of more than 260 characters, which can be problematic for
2459
- -- 7-Zip even if Long Filepaths are enabled on Windows .
2457
+ -- We aim to reduce the risk of a filepath length of more than 260 characters,
2458
+ -- which can be problematic for 7-Zip if Windows is not 'long file paths'
2459
+ -- enabled. We use a short name for the temporary directory .. .
2460
2460
let tmpName = " stack-tmp"
2461
2461
destDrive = takeDrive destDir
2462
2462
ensureDir (parent destDir)
2463
+ tempDrive <- takeDrive <$> getTempDir
2464
+ -- We use a temporary directory with likely a short absolute path ...
2465
+ let withTempDir' = if tempDrive == destDrive
2466
+ then
2467
+ -- We use the system temporary directory if we can, as a Standard user
2468
+ -- may well not have permission to create a directory in the root of
2469
+ -- the system drive.
2470
+ withSystemTempDir
2471
+ else
2472
+ -- Otherwise we use a temporary directory in the root of the
2473
+ -- destination drive.
2474
+ withTempDir destDrive
2463
2475
withRunInIO $ \ run ->
2464
- -- We use a temporary directory in the same drive as that of 'destDir' to
2465
- -- reduce the risk of a filepath length of more than 260 characters, which can
2466
- -- be problematic for 7-Zip even if Long Filepaths are enabled on Windows. We
2467
- -- do not use the system temporary directory as it may be on a different
2468
- -- drive.
2469
- withTempDir destDrive tmpName $ \ tmpDir ->
2476
+ withTempDir' tmpName $ \ tmpDir ->
2470
2477
run $ do
2471
2478
liftIO $ ignoringAbsence (removeDirRecur destDir)
2472
2479
run7z tmpDir archiveFile
0 commit comments