listIncompleteUploads lists all incomplete uploads.
(ctx context.Context, bucketName, objectPrefix string, recursive bool)
| 863 | |
| 864 | // listIncompleteUploads lists all incomplete uploads. |
| 865 | func (c *Client) listIncompleteUploads(ctx context.Context, bucketName, objectPrefix string, recursive bool) <-chan ObjectMultipartInfo { |
| 866 | // Allocate channel for multipart uploads. |
| 867 | objectMultipartStatCh := make(chan ObjectMultipartInfo, 1) |
| 868 | // Delimiter is set to "/" by default. |
| 869 | delimiter := "/" |
| 870 | if recursive { |
| 871 | // If recursive do not delimit. |
| 872 | delimiter = "" |
| 873 | } |
| 874 | // Validate bucket name. |
| 875 | if err := s3utils.CheckValidBucketName(bucketName); err != nil { |
| 876 | defer close(objectMultipartStatCh) |
| 877 | objectMultipartStatCh <- ObjectMultipartInfo{ |
| 878 | Err: err, |
| 879 | } |
| 880 | return objectMultipartStatCh |
| 881 | } |
| 882 | // Validate incoming object prefix. |
| 883 | if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil { |
| 884 | defer close(objectMultipartStatCh) |
| 885 | objectMultipartStatCh <- ObjectMultipartInfo{ |
| 886 | Err: err, |
| 887 | } |
| 888 | return objectMultipartStatCh |
| 889 | } |
| 890 | go func(objectMultipartStatCh chan<- ObjectMultipartInfo) { |
| 891 | defer func() { |
| 892 | if contextCanceled(ctx) { |
| 893 | objectMultipartStatCh <- ObjectMultipartInfo{ |
| 894 | Err: ctx.Err(), |
| 895 | } |
| 896 | } |
| 897 | close(objectMultipartStatCh) |
| 898 | }() |
| 899 | |
| 900 | // object and upload ID marker for future requests. |
| 901 | var objectMarker string |
| 902 | var uploadIDMarker string |
| 903 | for { |
| 904 | // list all multipart uploads. |
| 905 | result, err := c.listMultipartUploadsQuery(ctx, bucketName, objectMarker, uploadIDMarker, objectPrefix, delimiter, 0) |
| 906 | if err != nil { |
| 907 | objectMultipartStatCh <- ObjectMultipartInfo{ |
| 908 | Err: err, |
| 909 | } |
| 910 | return |
| 911 | } |
| 912 | objectMarker = result.NextKeyMarker |
| 913 | uploadIDMarker = result.NextUploadIDMarker |
| 914 | |
| 915 | // Send all multipart uploads. |
| 916 | for _, obj := range result.Uploads { |
| 917 | // Calculate total size of the uploaded parts if 'aggregateSize' is enabled. |
| 918 | select { |
| 919 | // Send individual uploads here. |
| 920 | case objectMultipartStatCh <- obj: |
| 921 | // If the context is canceled |
| 922 | case <-ctx.Done(): |
no test coverage detected