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
import Distribution.Simple.Utils
( die, debug, info, cabalVersion, findPackageDesc, comparing
, createDirectoryIfMissingVerbose, installExecutableFile
, existsAndIsMoreRecentThan, moreRecentFile
, copyFileVerbose, rewriteFile, intercalate )
import Distribution.Client.Utils
( inDir, tryCanonicalizePath )
( inDir, tryCanonicalizePath
, existsAndIsMoreRecentThan, moreRecentFile )
import Distribution.System ( Platform(..), buildPlatform )
import Distribution.Text
( display )
......
......@@ -6,10 +6,12 @@ module Distribution.Client.Utils ( MergeResult(..)
, removeExistingFile
, makeAbsoluteToCwd, filePathToByteString
, byteStringToFilePath, tryCanonicalizePath
, canonicalizePathNoThrow )
, canonicalizePathNoThrow
, moreRecentFile, existsAndIsMoreRecentThan )
where
import Distribution.Compat.Exception ( catchIO )
import Distribution.Client.Compat.Time ( getModTime )
import Distribution.Simple.Setup ( Flag(..) )
import qualified Data.ByteString.Lazy as BS
import Control.Monad
......@@ -160,3 +162,26 @@ tryCanonicalizePath path = do
canonicalizePathNoThrow :: FilePath -> IO FilePath
canonicalizePathNoThrow path = do
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)
import Distribution.Client.Sandbox.Types (UseSandbox(..), whenUsingSandbox)
import Distribution.Client.Init (initCabal)
import qualified Distribution.Client.Win32SelfUpgrade as Win32SelfUpgrade
import Distribution.Client.Utils (determineNumJobs)
import Distribution.Client.Utils (determineNumJobs
,existsAndIsMoreRecentThan)
import Distribution.PackageDescription
( Executable(..) )
......@@ -111,8 +112,7 @@ import qualified Distribution.Simple.LocalBuildInfo as LBI
import Distribution.Simple.Program (defaultProgramConfiguration)
import qualified Distribution.Simple.Setup as Cabal
import Distribution.Simple.Utils
( cabalVersion, die, notice, info
, existsAndIsMoreRecentThan, topHandler )
( cabalVersion, die, notice, info, topHandler )
import Distribution.Text
( display )
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