Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2022
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mayCopyFilePath :: (MonadMask m, Katip m) => FilePath -> FilePath -> m ()
  2. mayCopyFilePath srcPath destPath = retryOnException $ do
  3.   shouldCopy <- liftIO $ shouldCopyFile srcPath destPath
  4.   if shouldCopy
  5.     then do
  6.       logInfo $ "Copying <" <> srcPath <> "> to <" <> destPath <> ">."
  7.       liftIO $ copyFile srcPath destPath
  8.     else do
  9.       logDebug $ "Skipping <" <> srcPath <> "> to <" <> destPath <> ">."
  10.   where
  11.     shouldCopyFile srcPath destPath = do
  12.       destExists <- doesFileExist destPath
  13.       if not destExists
  14.         then pure True
  15.         else do
  16.           srcTime <- getModificationTime srcPath
  17.           destTime <- getModificationTime destPath
  18.           srcSize <- getFileSize srcPath
  19.           destSize <- getFileSize destPath
  20.           pure (srcTime > destTime || (srcSize > 0 && destSize == 0))
  21.     retryOnException f =
  22.       recoverAll (exponentialBackoff 1_000_000 <> limitRetries 5) $ \(RetryStatus iterNum cmDelay _) -> do
  23.         logWarn @Text $ "Retrying: " <> show iterNum <> "; cumulative delay: " <> show cmDelay <> "µs."
  24.         f
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement