diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4a22ce8515b..b3cac89ba2d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -29,7 +29,7 @@ jobs: - id: gen_output run: | if [ "${{ github.event.action }}" == 'labeled' ] ; then - if [ ${{ github.event.label.name == '${{ env.BUILD_LABEL }}' }} ] ; then + if [ "${{ github.event.label.name }}" == "${{ env.BUILD_LABEL }}" ] ; then echo run_release_workflow="yes" >> "$GITHUB_OUTPUT" else echo run_release_workflow="no" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/reusable-release.yml b/.github/workflows/reusable-release.yml index 81cf9db0aa2..618ba83031e 100644 --- a/.github/workflows/reusable-release.yml +++ b/.github/workflows/reusable-release.yml @@ -364,7 +364,6 @@ jobs: TARBALL_EXT: "zip" DISTRO: na CABAL_DIR: "C:\\Users\\runneradmin\\AppData\\Roaming\\cabal" - GHCUP_INSTALL_BASE_PREFIX: "/c" strategy: fail-fast: false matrix: diff --git a/Cabal/src/Distribution/Compat/Internal/TempFile.hs b/Cabal/src/Distribution/Compat/Internal/TempFile.hs index 0d20c69ec4a..f95568fc97d 100644 --- a/Cabal/src/Distribution/Compat/Internal/TempFile.hs +++ b/Cabal/src/Distribution/Compat/Internal/TempFile.hs @@ -10,10 +10,11 @@ module Distribution.Compat.Internal.TempFile import Distribution.Compat.Exception +import GHC.IORef (IORef, atomicModifyIORef'_, newIORef) import System.FilePath (()) - import System.IO (Handle, openBinaryTempFile, openBinaryTempFileWithDefaultPermissions, openTempFile) import System.IO.Error (isAlreadyExistsError) +import System.IO.Unsafe (unsafePerformIO) import System.Posix.Internals (c_getpid) #if defined(mingw32_HOST_OS) || defined(ghcjs_HOST_OS) @@ -28,17 +29,21 @@ openNewBinaryFile = openBinaryTempFileWithDefaultPermissions createTempDirectory :: FilePath -> String -> IO FilePath createTempDirectory dir template = do pid <- c_getpid - findTempName pid - where - findTempName x = do - let relpath = template ++ "-" ++ show x - dirpath = dir relpath - r <- tryIO $ mkPrivateDir dirpath - case r of - Right _ -> return relpath - Left e - | isAlreadyExistsError e -> findTempName (x + 1) - | otherwise -> ioError e + let findTempName = do + (counter, _) <- atomicModifyIORef'_ tempDirectoryCounter (+ 1) + let relpath = template ++ "-" ++ show pid ++ show counter + dirpath = dir relpath + r <- tryIO $ mkPrivateDir dirpath + case r of + Right _ -> pure relpath + Left e + | isAlreadyExistsError e -> findTempName + | otherwise -> ioError e + findTempName + +tempDirectoryCounter :: IORef Word +tempDirectoryCounter = unsafePerformIO $ newIORef 0 +{-# NOINLINE tempDirectoryCounter #-} mkPrivateDir :: String -> IO () #if defined(mingw32_HOST_OS) || defined(ghcjs_HOST_OS) diff --git a/changelog.d/pr-11872.md b/changelog.d/pr-11872.md new file mode 100644 index 00000000000..1fa197eb65a --- /dev/null +++ b/changelog.d/pr-11872.md @@ -0,0 +1,7 @@ +--- +synopsis: Improve name assigning for temporary folders +packages: [Cabal,cabal-install] +prs: 11872 +--- + +Now `createTempDirectory` from `Distribution.Compat.Internal.TempFile` uses a global counter as a part of temporary folder name template, so that probing is less likely to fail. The change should be invisible for users.