Commit c0eb8420 authored by Mikhail Glushenkov's avatar Mikhail Glushenkov
Browse files

cabal-install: Use 'getModTime' consistently everywhere.

We can't do the same for the Cabal lib because of the MIN_VERSION macros.
parent 9baef546
...@@ -69,10 +69,10 @@ import Distribution.Simple.Setup ...@@ -69,10 +69,10 @@ import Distribution.Simple.Setup
import Distribution.Simple.Utils import Distribution.Simple.Utils
( die, debug, info, cabalVersion, findPackageDesc, comparing ( die, debug, info, cabalVersion, findPackageDesc, comparing
, createDirectoryIfMissingVerbose, installExecutableFile , createDirectoryIfMissingVerbose, installExecutableFile
, existsAndIsMoreRecentThan, moreRecentFile
, copyFileVerbose, rewriteFile, intercalate ) , copyFileVerbose, rewriteFile, intercalate )
import Distribution.Client.Utils import Distribution.Client.Utils
( inDir, tryCanonicalizePath ) ( inDir, tryCanonicalizePath
, existsAndIsMoreRecentThan, moreRecentFile )
import Distribution.System ( Platform(..), buildPlatform ) import Distribution.System ( Platform(..), buildPlatform )
import Distribution.Text import Distribution.Text
( display ) ( display )
......
...@@ -6,10 +6,12 @@ module Distribution.Client.Utils ( MergeResult(..) ...@@ -6,10 +6,12 @@ module Distribution.Client.Utils ( MergeResult(..)
, removeExistingFile , removeExistingFile
, makeAbsoluteToCwd, filePathToByteString , makeAbsoluteToCwd, filePathToByteString
, byteStringToFilePath, tryCanonicalizePath , byteStringToFilePath, tryCanonicalizePath
, canonicalizePathNoThrow ) , canonicalizePathNoThrow
, moreRecentFile, existsAndIsMoreRecentThan )
where where
import Distribution.Compat.Exception ( catchIO ) import Distribution.Compat.Exception ( catchIO )
import Distribution.Client.Compat.Time ( getModTime )
import Distribution.Simple.Setup ( Flag(..) ) import Distribution.Simple.Setup ( Flag(..) )
import qualified Data.ByteString.Lazy as BS import qualified Data.ByteString.Lazy as BS
import Control.Monad import Control.Monad
...@@ -160,3 +162,26 @@ tryCanonicalizePath path = do ...@@ -160,3 +162,26 @@ tryCanonicalizePath path = do
canonicalizePathNoThrow :: FilePath -> IO FilePath canonicalizePathNoThrow :: FilePath -> IO FilePath
canonicalizePathNoThrow path = do canonicalizePathNoThrow path = do
canonicalizePath path `catchIO` (\_ -> return path) canonicalizePath path `catchIO` (\_ -> return path)
--------------------
-- Modification time
-- | Like Distribution.Simple.Utils.moreRecentFile, but uses getModTime instead
-- of getModificationTime for higher precision. We can't merge the two because
-- Distribution.Client.Time uses MIN_VERSION macros.
moreRecentFile :: FilePath -> FilePath -> IO Bool
moreRecentFile a b = do
exists <- doesFileExist b
if not exists
then return True
else do tb <- getModTime b
ta <- getModTime a
return (ta > tb)
-- | Like 'moreRecentFile', but also checks that the first file exists.
existsAndIsMoreRecentThan :: FilePath -> FilePath -> IO Bool
existsAndIsMoreRecentThan a b = do
exists <- doesFileExist a
if not exists
then return False
else a `moreRecentFile` b
...@@ -94,7 +94,8 @@ import Distribution.Client.Sandbox.Timestamp (maybeAddCompilerTimestampRecord) ...@@ -94,7 +94,8 @@ import Distribution.Client.Sandbox.Timestamp (maybeAddCompilerTimestampRecord)
import Distribution.Client.Sandbox.Types (UseSandbox(..), whenUsingSandbox) import Distribution.Client.Sandbox.Types (UseSandbox(..), whenUsingSandbox)
import Distribution.Client.Init (initCabal) import Distribution.Client.Init (initCabal)
import qualified Distribution.Client.Win32SelfUpgrade as Win32SelfUpgrade import qualified Distribution.Client.Win32SelfUpgrade as Win32SelfUpgrade
import Distribution.Client.Utils (determineNumJobs) import Distribution.Client.Utils (determineNumJobs
,existsAndIsMoreRecentThan)
import Distribution.PackageDescription import Distribution.PackageDescription
( Executable(..) ) ( Executable(..) )
...@@ -111,8 +112,7 @@ import qualified Distribution.Simple.LocalBuildInfo as LBI ...@@ -111,8 +112,7 @@ import qualified Distribution.Simple.LocalBuildInfo as LBI
import Distribution.Simple.Program (defaultProgramConfiguration) import Distribution.Simple.Program (defaultProgramConfiguration)
import qualified Distribution.Simple.Setup as Cabal import qualified Distribution.Simple.Setup as Cabal
import Distribution.Simple.Utils import Distribution.Simple.Utils
( cabalVersion, die, notice, info ( cabalVersion, die, notice, info, topHandler )
, existsAndIsMoreRecentThan, topHandler )
import Distribution.Text import Distribution.Text
( display ) ( display )
import Distribution.Verbosity as Verbosity import Distribution.Verbosity as Verbosity
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment