| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9ba049a commit 16ab4c2
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3849,6 +3849,7 @@ def compose( | |||
| 3849 | 3849 | if_metageneration_match=None, | |
| 3850 | 3850 | if_source_generation_match=None, | |
| 3851 | 3851 | retry=DEFAULT_RETRY_IF_GENERATION_SPECIFIED, | |
| 3852 | + delete_source_objects=None, | ||
| 3852 | 3853 | ): | |
| 3853 | 3854 | """Concatenate source blobs into this one. | |
| 3854 | 3855 | ||
@@ -3908,6 +3909,11 @@ def compose( | |||
| 3908 | 3909 | Change the value to ``DEFAULT_RETRY`` or another `google.api_core.retry.Retry` object | |
| 3909 | 3910 | to enable retries regardless of generation precondition setting. | |
| 3910 | 3911 | See [Configuring Retries](https://cloud.google.com/python/docs/reference/storage/latest/retry_timeout). | |
| 3912 | + | ||
| 3913 | + :type delete_source_objects: bool | ||
| 3914 | + :param delete_source_objects: | ||
| 3915 | + (Optional) If True, the source objects will be deleted after a | ||
| 3916 | + successful composition. | ||
| 3911 | 3917 | """ | |
| 3912 | 3918 | with create_trace_span(name="Storage.Blob.compose"): | |
| 3913 | 3919 | sources_len = len(sources) | |
@@ -3964,6 +3970,9 @@ def compose( | |||
| 3964 | 3970 | "destination": self._properties.copy(), | |
| 3965 | 3971 | } | |
| 3966 | 3972 | ||
| 3973 | + if delete_source_objects is not None: | ||
| 3974 | + request["deleteSourceObjects"] = delete_source_objects | ||
| 3975 | + | ||
| 3967 | 3976 | if self.user_project is not None: | |
| 3968 | 3977 | query_params["userProject"] = self.user_project | |
| 3969 | 3978 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1209,3 +1209,23 @@ def test_blob_download_as_bytes_single_shot_download( | |||
| 1209 | 1209 | ||
| 1210 | 1210 | result_single_shot_download = blob.download_as_bytes(single_shot_download=True) | |
| 1211 | 1211 | assert result_single_shot_download == payload | |
| 1212 | + | ||
| 1213 | + | ||
| 1214 | + def test_blob_compose_delete_source_objects(shared_bucket, blobs_to_delete): | ||
| 1215 | + payload_1 = b"AAA\n" | ||
| 1216 | + source_1 = shared_bucket.blob("source-1-delete") | ||
| 1217 | + source_1.upload_from_string(payload_1) | ||
| 1218 | + blobs_to_delete.append(source_1) | ||
| 1219 | + | ||
| 1220 | + payload_2 = b"BBB\n" | ||
| 1221 | + source_2 = shared_bucket.blob("source-2-delete") | ||
| 1222 | + source_2.upload_from_string(payload_2) | ||
| 1223 | + blobs_to_delete.append(source_2) | ||
| 1224 | + | ||
| 1225 | + destination = shared_bucket.blob("destination-delete") | ||
| 1226 | + destination.compose([source_1, source_2], delete_source_objects=True) | ||
| 1227 | + blobs_to_delete.append(destination) | ||
| 1228 | + | ||
| 1229 | + assert destination.download_as_bytes() == payload_1 + payload_2 | ||
| 1230 | + assert not source_1.exists() | ||
| 1231 | + assert not source_2.exists() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4874,6 +4874,43 @@ def test_compose_w_metageneration_match(self): | |||
| 4874 | 4874 | _target_object=destination, | |
| 4875 | 4875 | ) | |
| 4876 | 4876 | ||
| 4877 | + def test_compose_w_delete_source_objects(self): | ||
| 4878 | + source_1_name = "source-1" | ||
| 4879 | + source_2_name = "source-2" | ||
| 4880 | + destination_name = "destination" | ||
| 4881 | + delete_source_objects = True | ||
| 4882 | + api_response = {} | ||
| 4883 | + client = mock.Mock(spec=["_post_resource"]) | ||
| 4884 | + client._post_resource.return_value = api_response | ||
| 4885 | + bucket = _Bucket(client=client) | ||
| 4886 | + source_1 = self._make_one(source_1_name, bucket=bucket) | ||
| 4887 | + source_2 = self._make_one(source_2_name, bucket=bucket) | ||
| 4888 | + destination = self._make_one(destination_name, bucket=bucket) | ||
| 4889 | + | ||
| 4890 | + destination.compose( | ||
| 4891 | + sources=[source_1, source_2], | ||
| 4892 | + delete_source_objects=delete_source_objects, | ||
| 4893 | + ) | ||
| 4894 | + | ||
| 4895 | + expected_path = f"/b/name/o/{destination_name}/compose" | ||
| 4896 | + expected_data = { | ||
| 4897 | + "sourceObjects": [ | ||
| 4898 | + {"name": source_1.name, "generation": source_1.generation}, | ||
| 4899 | + {"name": source_2.name, "generation": source_2.generation}, | ||
| 4900 | + ], | ||
| 4901 | + "destination": {}, | ||
| 4902 | + "deleteSourceObjects": delete_source_objects, | ||
| 4903 | + } | ||
| 4904 | + expected_query_params = {} | ||
| 4905 | + client._post_resource.assert_called_once_with( | ||
| 4906 | + expected_path, | ||
| 4907 | + expected_data, | ||
| 4908 | + query_params=expected_query_params, | ||
| 4909 | + timeout=self._get_default_timeout(), | ||
| 4910 | + retry=DEFAULT_RETRY_IF_GENERATION_SPECIFIED, | ||
| 4911 | + _target_object=destination, | ||
| 4912 | + ) | ||
| 4913 | + | ||
| 4877 | 4914 | def test_rewrite_w_response_wo_resource(self): | |
| 4878 | 4915 | source_name = "source" | |
| 4879 | 4916 | dest_name = "dest" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments