From fce9fe335b902776b683420ea2ee45461b0fd97c Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 25 Mar 2019 23:33:10 -0700 Subject: [PATCH] stack upgrade: Call getExecutablePath before overwriting ourself Fixes: #4462 Signed-off-by: Anders Kaseorg --- src/Stack/Setup.hs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Stack/Setup.hs b/src/Stack/Setup.hs index a8469a48dc..600e2141cc 100644 --- a/src/Stack/Setup.hs +++ b/src/Stack/Setup.hs @@ -1957,12 +1957,16 @@ downloadStackExe platforms0 archiveInfo destDir checkPath testExe = do platform <- view platformL + -- We need to call getExecutablePath before we overwrite the + -- currently running binary: after that, Linux will append + -- (deleted) to the filename. + currExe <- liftIO getExecutablePath + liftIO $ do setFileExecutable (toFilePath tmpFile) testExe tmpFile - currExe <- getExecutablePath case platform of Platform _ Cabal.Windows | FP.equalFilePath (toFilePath destFile) currExe -> do old <- parseAbsFile (toFilePath destFile ++ ".old") @@ -1975,7 +1979,7 @@ downloadStackExe platforms0 archiveInfo destDir checkPath testExe = do logInfo $ "New stack executable available at " <> fromString (toFilePath destFile) - when checkPath $ performPathChecking destFile + when checkPath $ performPathChecking destFile currExe `catchAny` (logError . displayShow) where @@ -2034,9 +2038,9 @@ downloadStackExe platforms0 archiveInfo destDir checkPath testExe = do performPathChecking :: HasConfig env => Path Abs File -- ^ location of the newly downloaded file + -> String -- ^ currently running executable -> RIO env () -performPathChecking newFile = do - executablePath <- liftIO getExecutablePath +performPathChecking newFile executablePath = do executablePath' <- parseAbsFile executablePath unless (toFilePath newFile == executablePath) $ do logInfo $ "Also copying stack executable to " <> fromString executablePath