listIncompleteUploads returns upload size like other SDKs (#15)

This commit is contained in:
Krishnan Parthasarathi 2017-03-01 17:01:52 +05:30 committed by Aditya Manthramurthy
parent 004a6ef79a
commit 4ec362918e
8 changed files with 32 additions and 36 deletions

View File

@ -198,7 +198,7 @@ __UploadInfo record type__
|:---|:---| :---|
|`uiKey` | _Object_ |Name of incompletely uploaded object |
|`uiUploadId` | _String_ |Upload ID of incompletely uploaded object |
|`<TODO>` | _<needs fix>_ |Size of incompletely uploaded object |
|`uiSize` | _Int64_ |Size of incompletely uploaded object |
__Example__
@ -219,22 +219,6 @@ main = do
```
<a name="listIncompleteParts"></a>
### 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 |

View File

@ -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
}
]
-}

View File

@ -42,7 +42,6 @@ module Network.Minio
, listObjects
, listIncompleteUploads
, listIncompleteParts
-- * Object Operations
----------------------

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -146,7 +146,7 @@ testParseListIncompleteUploads = do
\</CommonPrefixes>\
\</ListMultipartUploadsResult>"
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/"]