Skip to content

Commit fa2a354

Browse files
committed
Fix #4843: Redundant hash in ghcide cache path
Reasoning: The upstream logic might send unit ID that already has a hash appended to it to prevent collision. Later in the pipeline , the getCacheDirsDefault function blindly appends the opts hash again to generate the cache path. This results in a duplicated hash (main-<hash>-<hash>). This patch does a simple isSuffixOf check to ensure the hash is only appended by the getCacheDirsDefalut if wansn't already appened upstream, keeping the cache directory clean.
1 parent b3b71b7 commit fa2a354

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,11 @@ setODir f d =
12201220

12211221
getCacheDirsDefault :: String -> [String] -> IO CacheDirs
12221222
getCacheDirsDefault prefix opts = do
1223-
dir <- Just <$> getXdgDirectory XdgCache (cacheDir </> prefix ++ "-" ++ opts_hash)
1223+
let suffix = "-"++opts_hash
1224+
dirName = if suffix `isSuffixOf` prefix
1225+
then prefix
1226+
else prefix ++ suffix
1227+
dir <- Just <$> getXdgDirectory XdgCache (cacheDir </> dirName)
12241228
return $ CacheDirs dir dir dir
12251229
where
12261230
-- Create a unique folder per set of different GHC options, assuming that each different set of

0 commit comments

Comments
 (0)