Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mayCopyFilePath :: (MonadMask m, Katip m) => FilePath -> FilePath -> m ()
- mayCopyFilePath srcPath destPath = retryOnException $ do
- shouldCopy <- liftIO $ shouldCopyFile srcPath destPath
- if shouldCopy
- then do
- logInfo $ "Copying <" <> srcPath <> "> to <" <> destPath <> ">."
- liftIO $ copyFile srcPath destPath
- else do
- logDebug $ "Skipping <" <> srcPath <> "> to <" <> destPath <> ">."
- where
- shouldCopyFile srcPath destPath = do
- destExists <- doesFileExist destPath
- if not destExists
- then pure True
- else do
- srcTime <- getModificationTime srcPath
- destTime <- getModificationTime destPath
- srcSize <- getFileSize srcPath
- destSize <- getFileSize destPath
- pure (srcTime > destTime || (srcSize > 0 && destSize == 0))
- retryOnException f =
- recoverAll (exponentialBackoff 1_000_000 <> limitRetries 5) $ \(RetryStatus iterNum cmDelay _) -> do
- logWarn @Text $ "Retrying: " <> show iterNum <> "; cumulative delay: " <> show cmDelay <> "µs."
- f
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement