@@ -18,11 +18,11 @@ import Distribution.Version (thisVersion)
1818import Stackage.Types
1919import System.Directory (doesDirectoryExist,
2020 removeDirectoryRecursive)
21−import System.Directory (getAppUserDataDirectory)
22−import System.Directory (canonicalizePath,
23− createDirectoryIfMissing)
21+import System.Directory (getAppUserDataDirectory
22+ ,canonicalizePath,
23+ createDirectoryIfMissing, doesFileExist)
2424import System.Environment (getEnvironment)
25−import System.FilePath ((</>))
25+import System.FilePath ((</>), (<.>))
2626
2727-- | Allow only packages with permissive licenses.
2828allowPermissive :: [String] -- ^ list of explicitly allowed packages
@@ -148,3 +148,16 @@ fixBuildSettings settings' = do
148148 createDirectoryIfMissing True root'
149149 root <- canonicalizePath root'
150150 return settings' { sandboxRoot = root }
151+
152+-- | Check if a tarball exists in the tarball directory and, if so, use that
153+-- instead of the given name.
154+replaceTarball :: BuildSettings
155+ -> String
156+ -> IO String
157+replaceTarball bs pkgname = do
158+ exists <- doesFileExist fp
159+ if exists
160+ then canonicalizePath fp
161+ else return pkgname
162+ where
163+ fp = tarballDir bs </> pkgname <.> "tar.gz"