From 4ec362918e08386312df348ea14094cbf1d95cbc Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Wed, 1 Mar 2017 17:01:52 +0530 Subject: [PATCH] listIncompleteUploads returns upload size like other SDKs (#15) --- docs/API.md | 18 +----------------- examples/listIncompleteUploads.hs | 20 ++++++++++++-------- src/Network/Minio.hs | 1 - src/Network/Minio/Data.hs | 3 ++- src/Network/Minio/ListOps.hs | 13 ++++++++++++- src/Network/Minio/XmlParser.hs | 6 +----- test/LiveServer.hs | 5 +++-- test/Network/Minio/XmlParser/Test.hs | 2 +- 8 files changed, 32 insertions(+), 36 deletions(-) diff --git a/docs/API.md b/docs/API.md index 5d59804..b64fc62 100644 --- a/docs/API.md +++ b/docs/API.md @@ -198,7 +198,7 @@ __UploadInfo record type__ |:---|:---| :---| |`uiKey` | _Object_ |Name of incompletely uploaded object | |`uiUploadId` | _String_ |Upload ID of incompletely uploaded object | -|`` | __ |Size of incompletely uploaded object | +|`uiSize` | _Int64_ |Size of incompletely uploaded object | __Example__ @@ -219,22 +219,6 @@ main = do ``` - -### listIncompleteParts :: Bucket -> Object -> UploadId -> C.Producer Minio ObjectPartInfo - -List parts of an ongoing multipart upload. - -__Parameters__ - -In the expression `listIncompleteParts bucketName objectName uploadId` -the parameters are: - -|Param |Type |Description | -|:---|:---| :---| -| `bucketName` | _Bucket_ (alias for `Text`) | Name of the bucket | -| `objectName` | _Object_ (alias for `Text`) | Name of the object | -| `uploadId` | _UploadId_ (alias for `Text`) | The identifier for the multipart upload | - __Return Value__ |Return type |Description | diff --git a/examples/listIncompleteUploads.hs b/examples/listIncompleteUploads.hs index c57d875..bb58367 100755 --- a/examples/listIncompleteUploads.hs +++ b/examples/listIncompleteUploads.hs @@ -2,12 +2,11 @@ -- stack --resolver lts-6.27 runghc --package minio-hs {-# Language OverloadedStrings #-} -import Network.Minio +import Network.Minio -import qualified Data.Conduit as C -import qualified Data.Conduit.Combinators as CC -import Data.Default (Default(..)) -import Prelude +import Data.Conduit (($$)) +import Data.Conduit.Combinators (sinkList) +import Prelude -- | The following example uses minio's play server at -- https://play.minio.io:9000. The endpoint and associated @@ -23,12 +22,17 @@ main = do -- Performs a recursive listing of incomplete uploads under bucket "test" -- on a local minio server. - res <- runResourceT $ runMinio def $ do - listIncompleteUploads bucket Nothing True C.$$ CC.sinkList + res <- runResourceT $ runMinio minioPlayCI $ do + listIncompleteUploads bucket Nothing True $$ sinkList print res {- Following is the output of the above program on a local Minio server. - Right [UploadInfo {uiKey = "multipartObj", uiUploadId = "0ff9ccb9-d7ff-4def-9a98-571abefd7e2a", uiInitTime = 2017-02-10 12:19:04.951 UTC}] + Right [UploadInfo { uiKey = "go1.6.2.linux-amd64.tar.gz" + , uiUploadId = "063eb592-bdd7-4a0c-be48-34fb3ceb63e2" + , uiInitTime = 2017-03-01 10:16:25.698 UTC + , uiSize = 17731794 + } + ] -} diff --git a/src/Network/Minio.hs b/src/Network/Minio.hs index c7ad652..c354092 100644 --- a/src/Network/Minio.hs +++ b/src/Network/Minio.hs @@ -42,7 +42,6 @@ module Network.Minio , listObjects , listIncompleteUploads - , listIncompleteParts -- * Object Operations ---------------------- diff --git a/src/Network/Minio/Data.hs b/src/Network/Minio/Data.hs index 9c04e5d..b4cb8c6 100644 --- a/src/Network/Minio/Data.hs +++ b/src/Network/Minio/Data.hs @@ -184,7 +184,7 @@ data ListUploadsResult = ListUploadsResult { lurHasMore :: Bool , lurNextKey :: Maybe Text , lurNextUpload :: Maybe Text - , lurUploads :: [UploadInfo] + , lurUploads :: [(Object, UploadId, UTCTime)] , lurCPrefixes :: [Text] } deriving (Show, Eq) @@ -193,6 +193,7 @@ data UploadInfo = UploadInfo { uiKey :: Object , uiUploadId :: UploadId , uiInitTime :: UTCTime + , uiSize :: Int64 } deriving (Show, Eq) -- | Represents result from a listing of objects in a bucket. diff --git a/src/Network/Minio/ListOps.hs b/src/Network/Minio/ListOps.hs index 191fa2f..1f8202f 100644 --- a/src/Network/Minio/ListOps.hs +++ b/src/Network/Minio/ListOps.hs @@ -37,10 +37,21 @@ listIncompleteUploads bucket prefix recurse = loop Nothing Nothing res <- lift $ listIncompleteUploads' bucket prefix delimiter nextKeyMarker nextUploadIdMarker - CL.sourceList $ lurUploads res + + aggrSizes <- lift $ forM (lurUploads res) $ \((uKey, uId, _)) -> do + lPartsResult <- listIncompleteParts' bucket uKey uId Nothing Nothing + return $ foldl (\sizeSofar p -> opiSize p + sizeSofar) 0 + $ lprParts lPartsResult + + CL.sourceList $ + map (\((uKey, uId, uInitTime), size) -> + UploadInfo uKey uId uInitTime size + ) $ zip (lurUploads res) aggrSizes + when (lurHasMore res) $ loop nextKeyMarker nextUploadIdMarker + -- | List object parts of an ongoing multipart upload for given -- bucket, object and uploadId. listIncompleteParts :: Bucket -> Object -> UploadId diff --git a/src/Network/Minio/XmlParser.hs b/src/Network/Minio/XmlParser.hs index 4811234..36c7378 100644 --- a/src/Network/Minio/XmlParser.hs +++ b/src/Network/Minio/XmlParser.hs @@ -25,9 +25,6 @@ import Network.Minio.Utils (s3TimeFormat) -- | Helper functions. -uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d -uncurry3 f (a, b, c) = f a b c - uncurry4 :: (a -> b -> c -> d -> e) -> (a, b, c, d) -> e uncurry4 f (a, b, c, d) = f a b c d @@ -137,8 +134,7 @@ parseListUploadsResponse xmldata = do uploadInitTimes <- mapM parseS3XMLTime uploadInitTimeStr let - uploads = map (uncurry3 UploadInfo) $ - zip3 uploadKeys uploadIds uploadInitTimes + uploads = zip3 uploadKeys uploadIds uploadInitTimes return $ ListUploadsResult hasMore nextKey nextUpload uploads prefixes diff --git a/test/LiveServer.hs b/test/LiveServer.hs index 0135826..24fe037 100644 --- a/test/LiveServer.hs +++ b/test/LiveServer.hs @@ -20,6 +20,7 @@ import System.Environment (lookupEnv) import Network.Minio import Network.Minio.Data +import Network.Minio.ListOps import Network.Minio.PutObject import Network.Minio.S3API import Network.Minio.Utils @@ -221,7 +222,7 @@ liveServerUnitTests = testGroup "Unit tests against a live server" step "cleanup" forM_ (lurUploads incompleteUploads) $ - \(UploadInfo _ uid _) -> abortMultipartUpload bucket object uid + \(_, uid, _) -> abortMultipartUpload bucket object uid step "Basic listIncompleteParts Test" let @@ -271,7 +272,7 @@ liveServerUnitTests = testGroup "Unit tests against a live server" liftIO $ (length uploads) @?= 10 step "cleanup" - forM_ uploads $ \(UploadInfo _ uid _) -> + forM_ uploads $ \(UploadInfo _ uid _ _) -> abortMultipartUpload bucket object uid step "High-level listIncompleteParts Test" diff --git a/test/Network/Minio/XmlParser/Test.hs b/test/Network/Minio/XmlParser/Test.hs index d68286f..1e354eb 100644 --- a/test/Network/Minio/XmlParser/Test.hs +++ b/test/Network/Minio/XmlParser/Test.hs @@ -146,7 +146,7 @@ testParseListIncompleteUploads = do \\ \" expectedListResult = ListUploadsResult False (Just "sample.jpg") (Just "Xgw4MJT6ZPAVxpY0SAuGN7q4uWJJM22ZYg1W99trdp4tpO88.PT6.MhO0w2E17eutfAvQfQWoajgE_W2gpcxQw--") uploads prefixes - uploads = [UploadInfo "sample.jpg" "Agw4MJT6ZPAVxpY0SAuGN7q4uWJJM22ZYg1N99trdp4tpO88.PT6.MhO0w2E17eutfAvQfQWoajgE_W2gpcxQw--" initTime] + uploads = [("sample.jpg", "Agw4MJT6ZPAVxpY0SAuGN7q4uWJJM22ZYg1N99trdp4tpO88.PT6.MhO0w2E17eutfAvQfQWoajgE_W2gpcxQw--", initTime)] initTime = UTCTime (fromGregorian 2010 11 26) 69857 prefixes = ["photos/", "videos/"]