diff options
author | Joey Hess <joeyh@joeyh.name> | 2017-05-25 14:30:18 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2017-05-25 14:30:18 -0400 |
commit | 5c874fd5f5f6dcdf2889d3db7d4429553859ccd6 (patch) | |
tree | 643e3a575fa83c9eae4de36a882b9eeb5f6c912b /Utility | |
parent | 0c430fc08ea6a6b95bb975ed1eaf2c1012a6d67a (diff) |
Improve progress display when watching file size, in cases where a transfer does not resume.
This commit was supported by the NSF-funded DataLad project.
Diffstat (limited to 'Utility')
-rw-r--r-- | Utility/Metered.hs | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/Utility/Metered.hs b/Utility/Metered.hs index 626aa2ca1..a5dda5413 100644 --- a/Utility/Metered.hs +++ b/Utility/Metered.hs @@ -171,22 +171,27 @@ defaultChunkSize = 32 * k - chunkOverhead k = 1024 chunkOverhead = 2 * sizeOf (1 :: Int) -- GHC specific -{- Runs an action, watching a file as it grows and updating the meter. -} +{- Runs an action, watching a file as it grows and updating the meter. + - + - The file may already exist, and the action could throw the original file + - away and start over. To avoid reporting the original file size followed + - by a smaller size in that case, wait until the file starts growing + - before updating the meter for the first time. + -} watchFileSize :: (MonadIO m, MonadMask m) => FilePath -> MeterUpdate -> m a -> m a watchFileSize f p a = bracket - (liftIO $ forkIO $ watcher zeroBytesProcessed) + (liftIO $ forkIO $ watcher =<< getsz) (liftIO . void . tryIO . killThread) (const a) where watcher oldsz = do - v <- catchMaybeIO $ toBytesProcessed <$> getFileSize f - newsz <- case v of - Just sz | sz /= oldsz -> do - p sz - return sz - _ -> return oldsz threadDelay 500000 -- 0.5 seconds - watcher newsz + sz <- getsz + when (sz > oldsz) $ + p sz + watcher sz + getsz = catchDefaultIO zeroBytesProcessed $ + toBytesProcessed <$> getFileSize f data OutputHandler = OutputHandler { quietMode :: Bool |