show errors

This commit is contained in:
Joey Hess 2013-01-02 13:46:40 -04:00
parent 402f59710a
commit 24c6eae1b5

View file

@ -59,12 +59,11 @@ chunkStream = map (\n -> ".chunk" ++ show n) [1 :: Integer ..]
- and passes it to an action, which should chunk and store the data, - and passes it to an action, which should chunk and store the data,
- and return the destinations it stored to, or [] on error. Then - and return the destinations it stored to, or [] on error. Then
- calls the storer to write the chunk count (if chunking). Finally, the - calls the storer to write the chunk count (if chunking). Finally, the
- fianlizer is called to rename the tmp into the dest - finalizer is called to rename the tmp into the dest
- (and do any other cleanup). - (and do any other cleanup).
-} -}
storeChunks :: Key -> FilePath -> FilePath -> ChunkSize -> ([FilePath] -> IO [FilePath]) -> (FilePath -> String -> IO ()) -> (FilePath -> FilePath -> IO ()) -> IO Bool storeChunks :: Key -> FilePath -> FilePath -> ChunkSize -> ([FilePath] -> IO [FilePath]) -> (FilePath -> String -> IO ()) -> (FilePath -> FilePath -> IO ()) -> IO Bool
storeChunks key tmp dest chunksize storer recorder finalizer = storeChunks key tmp dest chunksize storer recorder finalizer = either onerr return
either (const $ return False) return
=<< (E.try go :: IO (Either E.SomeException Bool)) =<< (E.try go :: IO (Either E.SomeException Bool))
where where
go = do go = do
@ -74,6 +73,9 @@ storeChunks key tmp dest chunksize storer recorder finalizer =
recorder chunkcount (show $ length stored) recorder chunkcount (show $ length stored)
finalizer tmp dest finalizer tmp dest
return (not $ null stored) return (not $ null stored)
onerr e = do
print e
return False
basef = tmp ++ keyFile key basef = tmp ++ keyFile key
tmpdests tmpdests
@ -92,21 +94,22 @@ storeChunks key tmp dest chunksize storer recorder finalizer =
- writes a whole L.ByteString at a time. - writes a whole L.ByteString at a time.
-} -}
storeChunked :: ChunkSize -> [FilePath] -> (FilePath -> L.ByteString -> IO ()) -> L.ByteString -> IO [FilePath] storeChunked :: ChunkSize -> [FilePath] -> (FilePath -> L.ByteString -> IO ()) -> L.ByteString -> IO [FilePath]
storeChunked chunksize dests storer content = storeChunked chunksize dests storer content = either onerr return
either (const $ return []) return
=<< (E.try (go chunksize dests) :: IO (Either E.SomeException [FilePath])) =<< (E.try (go chunksize dests) :: IO (Either E.SomeException [FilePath]))
where where
go _ [] = return [] -- no dests!? go _ [] = return [] -- no dests!?
go Nothing (d:_) = do go Nothing (d:_) = do
storer d content storer d content
return [d] return [d]
go (Just sz) _ go (Just sz) _
-- always write a chunk, even if the data is 0 bytes -- always write a chunk, even if the data is 0 bytes
| L.null content = go Nothing dests | L.null content = go Nothing dests
| otherwise = storechunks sz [] dests content | otherwise = storechunks sz [] dests content
onerr e = do
print e
return []
storechunks _ _ [] _ = return [] -- ran out of dests storechunks _ _ [] _ = return [] -- ran out of dests
storechunks sz useddests (d:ds) b storechunks sz useddests (d:ds) b
| L.null b = return $ reverse useddests | L.null b = return $ reverse useddests