From a560d8b6678382af4394a0cb72ca0de0dff91b96 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 18 Mar 2025 22:16:23 +0000 Subject: [PATCH 01/15] move_object functioanlity working --- .../lib/google/cloud/storage/bucket.rb | 37 +++++++++++++++ .../lib/google/cloud/storage/service.rb | 38 +++++++++++++++ .../samples/acceptance/buckets_test.rb | 46 +++++++++++++++++++ .../samples/storage_move_object.rb | 38 +++++++++++++++ .../test/google/cloud/storage/bucket_test.rb | 26 +++++++++++ google-cloud-storage/test/helper.rb | 30 ++++++++++++ 6 files changed, 215 insertions(+) create mode 100644 google-cloud-storage/samples/storage_move_object.rb diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index f5ab081698a7..caba6511d426 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -3143,6 +3143,43 @@ def reload! end alias refresh! reload! + ## + # Moves object from source to destination path within bucket + # This Operation is being performed at server side + def move_file source_object, + destination_object, + if_generation_match: nil, + if_generation_not_match: nil, + if_metageneration_match: nil, + if_metageneration_not_match: nil, + if_source_generation_match: nil, + if_source_generation_not_match: nil, + if_source_metageneration_match: nil, + if_source_metageneration_not_match: nil, + user_project: nil, + fields: nil, + quota_user: nil, + user_ip: nil, + options: {} + ensure_service! + gapi = service.move_file name, + source_object, + destination_object, + if_generation_match: if_generation_match, + if_generation_not_match: if_generation_not_match, + if_metageneration_match: if_metageneration_match, + if_metageneration_not_match: if_metageneration_not_match, + if_source_generation_match: if_source_generation_match, + if_source_generation_not_match: if_source_generation_not_match, + if_source_metageneration_match: if_source_metageneration_match, + if_source_metageneration_not_match: if_source_metageneration_not_match, + user_project: user_project, + fields: fields, + quota_user: quota_user, + user_ip: user_ip, + options: options + end + ## # Determines whether the bucket exists in the Storage service. # diff --git a/google-cloud-storage/lib/google/cloud/storage/service.rb b/google-cloud-storage/lib/google/cloud/storage/service.rb index 5175b08928c9..fe0275be1de4 100644 --- a/google-cloud-storage/lib/google/cloud/storage/service.rb +++ b/google-cloud-storage/lib/google/cloud/storage/service.rb @@ -630,6 +630,44 @@ def patch_file bucket_name, end end + ## + # Moves object from source to destination path within bucket + def move_file name, + source_object, + destination_object, + if_generation_match: nil, + if_generation_not_match: nil, + if_metageneration_match: nil, + if_metageneration_not_match: nil, + if_source_generation_match: nil, + if_source_generation_not_match: nil, + if_source_metageneration_match: nil, + if_source_metageneration_not_match: nil, + user_project: nil, + fields: nil, + quota_user: nil, + user_ip: nil, + options: {} + execute do + service.move_object name, + source_object, + destination_object, + if_generation_match: if_generation_match, + if_generation_not_match: if_generation_not_match, + if_metageneration_match: if_metageneration_match, + if_metageneration_not_match: if_metageneration_not_match, + if_source_generation_match: if_source_generation_match, + if_source_generation_not_match: if_source_generation_not_match, + if_source_metageneration_match: if_source_metageneration_match, + if_source_metageneration_not_match: if_source_metageneration_not_match, + user_project: user_project(user_project), + fields: fields, + quota_user: quota_user, + user_ip: user_ip, + options: options + end + end + ## # Permanently deletes a file. def delete_file bucket_name, diff --git a/google-cloud-storage/samples/acceptance/buckets_test.rb b/google-cloud-storage/samples/acceptance/buckets_test.rb index f4f416744fd1..476ea9ae02a6 100644 --- a/google-cloud-storage/samples/acceptance/buckets_test.rb +++ b/google-cloud-storage/samples/acceptance/buckets_test.rb @@ -53,6 +53,7 @@ require_relative "../storage_set_retention_policy" require_relative "../storage_get_autoclass" require_relative "../storage_set_autoclass" +require_relative "../storage_move_object" describe "Buckets Snippets" do let(:storage_client) { Google::Cloud::Storage.new } @@ -581,4 +582,49 @@ bucket.public_access_prevention = :inherited end end + + describe "storage move object" do + let(:file_1_name) { "file_1_name_#{SecureRandom.hex}.txt" } + let(:file_2_name) { "file_2_name_#{SecureRandom.hex}.txt" } + let(:hns_bucket) { + hierarchical_namespace = Google::Apis::StorageV1::Bucket::HierarchicalNamespace.new enabled: true + + storage_client.create_bucket random_bucket_name do |b| + b.uniform_bucket_level_access = true + b.hierarchical_namespace = hierarchical_namespace + end + } + let(:create_file_hns) { + file_content = "A" * (3 * 1024 * 1024) # 3 MB of 'A' characters + file = StringIO.new file_content + hns_bucket.create_file file,file_1_name + } + it "obejct is moved and old object is deleted" do + create_file_hns + out, _err = capture_io do + move_object bucket_name: hns_bucket.name, source_file_name: file_1_name, destination_file_name: file_2_name + end + assert_includes out, "New File #{file_2_name} created\n" + refute_nil(hns_bucket.file(file_2_name)) + assert_nil(hns_bucket.file(file_1_name)) + end + + it "raises error for non hns bucket" do + file_content = "A" * (3 * 1024 * 1024) # 3 MB of 'A' characters + file = StringIO.new file_content + bucket.create_file file,file_1_name + exception = assert_raises(Google::Cloud::AlreadyExistsError) do + move_object bucket_name: bucket.name, source_file_name: file_1_name, destination_file_name: file_2_name + end + assert_equal "conflict: The bucket does not support hierarchical namespace.", exception.message + end + + it "raises error if source and destination are having same filename" do + create_file_hns + exception = assert_raises(Google::Cloud::InvalidArgumentError) do + move_object bucket_name: hns_bucket.name, source_file_name: file_1_name, destination_file_name: file_1_name + end + assert_equal "invalid: Source and destination object names must be different.", exception.message + end + end end diff --git a/google-cloud-storage/samples/storage_move_object.rb b/google-cloud-storage/samples/storage_move_object.rb new file mode 100644 index 000000000000..af4777f51a28 --- /dev/null +++ b/google-cloud-storage/samples/storage_move_object.rb @@ -0,0 +1,38 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START storage_move_object] +def move_object bucket_name:, source_file_name:, destination_file_name: + # The ID of your GCS bucket + # bucket_name = "your-unique-bucket-name" + + # The name of your GCS object + # source_file_name = "your-file-name" + + # The new object name which you want to craete + # destination_file_name = "your-new-file-name" + + require "google/cloud/storage" + + storage = Google::Cloud::Storage.new + bucket = storage.bucket bucket_name, skip_lookup: true + + bucket.move_file source_file_name, destination_file_name + fetch_file = bucket.file destination_file_name + puts "New File #{fetch_file.name} created\n" + +end +# [END storage_move_object] + +move_object bucket_name: ARGV.shift, source_file_name: ARGV.shift, destination_file_name: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index 1dc5babfab0b..a3daaa8c130d 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1381,6 +1381,32 @@ _(bucket.api_url).must_equal "#{new_url_root}/b/#{bucket_name}" mock.verify end + describe "storage move object" do + it "moves a file object for bucket" do + file_name = "file.ext" + file_2_name = "file1.ext" + mock = Minitest::Mock.new + mock.expect :move_object,Google::Apis::StorageV1::Object.from_json(random_file_hash(bucket.name, file_2_name).to_json),[ bucket.name, file_name,file_2_name],**move_object_args + bucket.service.mocked_service = mock + file = bucket.move_file file_name, file_2_name + mock.verify + _(file).must_be_kind_of Google::Apis::StorageV1::Object + end + + it "raises error if source and destination are having same filename" do + file_name = "file.ext" + file_2_name = "file1.ext" + mock = Minitest::Mock.new + mock.expect :move_object, [ bucket.name, file_name,file_name] do + raise Google::Cloud::InvalidArgumentError, "invalid: Source and destination object names must be different." + end + bucket.service.mocked_service = mock + exception = assert_raises(Google::Cloud::InvalidArgumentError) do + bucket.move_file file_name, file_name + end + assert_equal "invalid: Source and destination object names must be different.", exception.message + end + end def create_file_gapi bucket=nil, name = nil Google::Apis::StorageV1::Object.from_json random_file_hash(bucket, name).to_json diff --git a/google-cloud-storage/test/helper.rb b/google-cloud-storage/test/helper.rb index 239104d6171b..5d37f92feb26 100644 --- a/google-cloud-storage/test/helper.rb +++ b/google-cloud-storage/test/helper.rb @@ -457,6 +457,36 @@ def patch_object_args generation: nil, } end + def move_object_args if_generation_match: nil, + if_generation_not_match: nil, + if_metageneration_match: nil, + if_metageneration_not_match: nil, + if_source_generation_match: nil, + if_source_generation_not_match: nil, + if_source_metageneration_match: nil, + if_source_metageneration_not_match: nil, + user_project: nil, + fields: nil, + quota_user: nil, + user_ip: nil, + options: {} + { + if_generation_match: if_generation_match, + if_generation_not_match: if_generation_not_match, + if_metageneration_match: if_metageneration_match, + if_metageneration_not_match: if_metageneration_not_match, + if_source_generation_match: if_source_generation_match, + if_source_generation_not_match: if_source_generation_not_match, + if_source_metageneration_match: if_source_metageneration_match, + if_source_metageneration_not_match: if_source_metageneration_not_match, + user_project: user_project, + fields: fields, + quota_user: quota_user, + user_ip: user_ip, + options: options + } + end + def delete_object_args generation: nil, if_generation_match: nil, if_generation_not_match: nil, From 6ae30b36c2c94edcfd3c658630151adf78f71687 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 19 Mar 2025 12:44:39 +0000 Subject: [PATCH 02/15] adding doc --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index caba6511d426..ecaccad07233 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -3146,6 +3146,13 @@ def reload! ## # Moves object from source to destination path within bucket # This Operation is being performed at server side + # @param [String] source_object The file name existing on bucket + # @param [String] destination_object The new file name to be created on bucket + # @example + # require "google/cloud/storage" + # storage = Google::Cloud::Storage.new + # bucket = storage.bucket bucket_name, skip_lookup: true + # bucket.move_file source_file_name, destination_file_name def move_file source_object, destination_object, if_generation_match: nil, From dde9e8df3d40856bad8b96513a258193c8cfb5f1 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 19 Mar 2025 13:15:25 +0000 Subject: [PATCH 03/15] fixing lint issue --- .../lib/google/cloud/storage/bucket.rb | 34 +++++++++---------- .../samples/acceptance/buckets_test.rb | 22 ++++++------ 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index ecaccad07233..590584de3692 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -3147,7 +3147,7 @@ def reload! # Moves object from source to destination path within bucket # This Operation is being performed at server side # @param [String] source_object The file name existing on bucket - # @param [String] destination_object The new file name to be created on bucket + # @param [String] destination_object The new filename to be created on bucket # @example # require "google/cloud/storage" # storage = Google::Cloud::Storage.new @@ -3169,22 +3169,22 @@ def move_file source_object, user_ip: nil, options: {} ensure_service! - gapi = service.move_file name, - source_object, - destination_object, - if_generation_match: if_generation_match, - if_generation_not_match: if_generation_not_match, - if_metageneration_match: if_metageneration_match, - if_metageneration_not_match: if_metageneration_not_match, - if_source_generation_match: if_source_generation_match, - if_source_generation_not_match: if_source_generation_not_match, - if_source_metageneration_match: if_source_metageneration_match, - if_source_metageneration_not_match: if_source_metageneration_not_match, - user_project: user_project, - fields: fields, - quota_user: quota_user, - user_ip: user_ip, - options: options + service.move_file name, + source_object, + destination_object, + if_generation_match: if_generation_match, + if_generation_not_match: if_generation_not_match, + if_metageneration_match: if_metageneration_match, + if_metageneration_not_match: if_metageneration_not_match, + if_source_generation_match: if_source_generation_match, + if_source_generation_not_match: if_source_generation_not_match, + if_source_metageneration_match: if_source_metageneration_match, + if_source_metageneration_not_match: if_source_metageneration_not_match, + user_project: user_project, + fields: fields, + quota_user: quota_user, + user_ip: user_ip, + options: options end ## diff --git a/google-cloud-storage/samples/acceptance/buckets_test.rb b/google-cloud-storage/samples/acceptance/buckets_test.rb index 476ea9ae02a6..7bc6f59704d9 100644 --- a/google-cloud-storage/samples/acceptance/buckets_test.rb +++ b/google-cloud-storage/samples/acceptance/buckets_test.rb @@ -586,19 +586,18 @@ describe "storage move object" do let(:file_1_name) { "file_1_name_#{SecureRandom.hex}.txt" } let(:file_2_name) { "file_2_name_#{SecureRandom.hex}.txt" } - let(:hns_bucket) { + let :hns_bucket do hierarchical_namespace = Google::Apis::StorageV1::Bucket::HierarchicalNamespace.new enabled: true - storage_client.create_bucket random_bucket_name do |b| b.uniform_bucket_level_access = true b.hierarchical_namespace = hierarchical_namespace end - } - let(:create_file_hns) { - file_content = "A" * (3 * 1024 * 1024) # 3 MB of 'A' characters - file = StringIO.new file_content - hns_bucket.create_file file,file_1_name - } + end + let :create_file_hns do + file_content = "A" * (3 * 1024 * 1024) # 3 MB of 'A' characters + file = StringIO.new file_content + hns_bucket.create_file file, file_1_name + end it "obejct is moved and old object is deleted" do create_file_hns out, _err = capture_io do @@ -612,16 +611,15 @@ it "raises error for non hns bucket" do file_content = "A" * (3 * 1024 * 1024) # 3 MB of 'A' characters file = StringIO.new file_content - bucket.create_file file,file_1_name - exception = assert_raises(Google::Cloud::AlreadyExistsError) do + bucket.create_file file, file_1_name + assert_raises Google::Cloud::AlreadyExistsError do move_object bucket_name: bucket.name, source_file_name: file_1_name, destination_file_name: file_2_name end - assert_equal "conflict: The bucket does not support hierarchical namespace.", exception.message end it "raises error if source and destination are having same filename" do create_file_hns - exception = assert_raises(Google::Cloud::InvalidArgumentError) do + exception = assert_raises Google::Cloud::InvalidArgumentError do move_object bucket_name: hns_bucket.name, source_file_name: file_1_name, destination_file_name: file_1_name end assert_equal "invalid: Source and destination object names must be different.", exception.message From 1841e87c54536f8b3716da64f9c835368de54256 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 19 Mar 2025 13:18:58 +0000 Subject: [PATCH 04/15] fixing lint issue --- google-cloud-storage/samples/storage_move_object.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/google-cloud-storage/samples/storage_move_object.rb b/google-cloud-storage/samples/storage_move_object.rb index af4777f51a28..727f3dc7d891 100644 --- a/google-cloud-storage/samples/storage_move_object.rb +++ b/google-cloud-storage/samples/storage_move_object.rb @@ -31,8 +31,10 @@ def move_object bucket_name:, source_file_name:, destination_file_name: bucket.move_file source_file_name, destination_file_name fetch_file = bucket.file destination_file_name puts "New File #{fetch_file.name} created\n" - end # [END storage_move_object] -move_object bucket_name: ARGV.shift, source_file_name: ARGV.shift, destination_file_name: ARGV.shift if $PROGRAM_NAME == __FILE__ +if $PROGRAM_NAME == __FILE__ + move_object bucket_name: ARGV.shift, source_file_name: ARGV.shift, + destination_file_name: ARGV.shift +end From 0c28b1ef2b2d83ad1e54fc88fd386d1631618844 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 19 Mar 2025 14:32:19 +0000 Subject: [PATCH 05/15] removing test case for nin hns bucket --- google-cloud-storage/samples/acceptance/buckets_test.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/google-cloud-storage/samples/acceptance/buckets_test.rb b/google-cloud-storage/samples/acceptance/buckets_test.rb index 7bc6f59704d9..8088fbdbde64 100644 --- a/google-cloud-storage/samples/acceptance/buckets_test.rb +++ b/google-cloud-storage/samples/acceptance/buckets_test.rb @@ -608,15 +608,6 @@ assert_nil(hns_bucket.file(file_1_name)) end - it "raises error for non hns bucket" do - file_content = "A" * (3 * 1024 * 1024) # 3 MB of 'A' characters - file = StringIO.new file_content - bucket.create_file file, file_1_name - assert_raises Google::Cloud::AlreadyExistsError do - move_object bucket_name: bucket.name, source_file_name: file_1_name, destination_file_name: file_2_name - end - end - it "raises error if source and destination are having same filename" do create_file_hns exception = assert_raises Google::Cloud::InvalidArgumentError do From b3f8633eb1082795fa4e80fd318d18308a349213 Mon Sep 17 00:00:00 2001 From: Thiyagu K Date: Thu, 20 Mar 2025 12:56:58 +0530 Subject: [PATCH 06/15] Update google-cloud-storage/samples/acceptance/buckets_test.rb --- google-cloud-storage/samples/acceptance/buckets_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage/samples/acceptance/buckets_test.rb b/google-cloud-storage/samples/acceptance/buckets_test.rb index 8088fbdbde64..aa0730b60ff6 100644 --- a/google-cloud-storage/samples/acceptance/buckets_test.rb +++ b/google-cloud-storage/samples/acceptance/buckets_test.rb @@ -598,7 +598,7 @@ file = StringIO.new file_content hns_bucket.create_file file, file_1_name end - it "obejct is moved and old object is deleted" do + it "object is moved and old object is deleted" do create_file_hns out, _err = capture_io do move_object bucket_name: hns_bucket.name, source_file_name: file_1_name, destination_file_name: file_2_name From 024c368e5eff8f94a78585d3575db22f219e0d4a Mon Sep 17 00:00:00 2001 From: Thiyagu K Date: Mon, 24 Mar 2025 11:38:29 +0530 Subject: [PATCH 07/15] Update google-cloud-storage/lib/google/cloud/storage/bucket.rb Co-authored-by: Neha Bajaj --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 590584de3692..f3439a2b730f 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -3146,7 +3146,7 @@ def reload! ## # Moves object from source to destination path within bucket # This Operation is being performed at server side - # @param [String] source_object The file name existing on bucket + # @param [String] source_object The file name in existing bucket # @param [String] destination_object The new filename to be created on bucket # @example # require "google/cloud/storage" From fe3cb11f3079057ad69f106a7563cd3d7cea8b20 Mon Sep 17 00:00:00 2001 From: Thiyagu K Date: Mon, 24 Mar 2025 11:45:57 +0530 Subject: [PATCH 08/15] fixed naming convention --- google-cloud-storage/samples/acceptance/buckets_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-storage/samples/acceptance/buckets_test.rb b/google-cloud-storage/samples/acceptance/buckets_test.rb index aa0730b60ff6..04b6a0931ef8 100644 --- a/google-cloud-storage/samples/acceptance/buckets_test.rb +++ b/google-cloud-storage/samples/acceptance/buckets_test.rb @@ -593,13 +593,13 @@ b.hierarchical_namespace = hierarchical_namespace end end - let :create_file_hns do + let :create_source_file do file_content = "A" * (3 * 1024 * 1024) # 3 MB of 'A' characters file = StringIO.new file_content hns_bucket.create_file file, file_1_name end it "object is moved and old object is deleted" do - create_file_hns + create_source_file out, _err = capture_io do move_object bucket_name: hns_bucket.name, source_file_name: file_1_name, destination_file_name: file_2_name end @@ -609,7 +609,7 @@ end it "raises error if source and destination are having same filename" do - create_file_hns + create_source_file exception = assert_raises Google::Cloud::InvalidArgumentError do move_object bucket_name: hns_bucket.name, source_file_name: file_1_name, destination_file_name: file_1_name end From 3659df8b88d0eefdcfee2d5ae4c49097b97470cd Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 26 Mar 2025 04:36:25 +0000 Subject: [PATCH 09/15] fixing naming convention --- .../lib/google/cloud/storage/bucket.rb | 12 ++++++------ .../lib/google/cloud/storage/service.rb | 8 ++++---- .../samples/acceptance/buckets_test.rb | 16 ++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index f3439a2b730f..4e16f4e6c981 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -3146,15 +3146,15 @@ def reload! ## # Moves object from source to destination path within bucket # This Operation is being performed at server side - # @param [String] source_object The file name in existing bucket - # @param [String] destination_object The new filename to be created on bucket + # @param [String] source_file The file name in existing bucket + # @param [String] destination_file The new filename to be created on bucket # @example # require "google/cloud/storage" # storage = Google::Cloud::Storage.new # bucket = storage.bucket bucket_name, skip_lookup: true # bucket.move_file source_file_name, destination_file_name - def move_file source_object, - destination_object, + def move_file source_file, + destination_file, if_generation_match: nil, if_generation_not_match: nil, if_metageneration_match: nil, @@ -3170,8 +3170,8 @@ def move_file source_object, options: {} ensure_service! service.move_file name, - source_object, - destination_object, + source_file, + destination_file, if_generation_match: if_generation_match, if_generation_not_match: if_generation_not_match, if_metageneration_match: if_metageneration_match, diff --git a/google-cloud-storage/lib/google/cloud/storage/service.rb b/google-cloud-storage/lib/google/cloud/storage/service.rb index fe0275be1de4..acbee97af0e0 100644 --- a/google-cloud-storage/lib/google/cloud/storage/service.rb +++ b/google-cloud-storage/lib/google/cloud/storage/service.rb @@ -633,8 +633,8 @@ def patch_file bucket_name, ## # Moves object from source to destination path within bucket def move_file name, - source_object, - destination_object, + source_file, + destination_file, if_generation_match: nil, if_generation_not_match: nil, if_metageneration_match: nil, @@ -650,8 +650,8 @@ def move_file name, options: {} execute do service.move_object name, - source_object, - destination_object, + source_file, + destination_file, if_generation_match: if_generation_match, if_generation_not_match: if_generation_not_match, if_metageneration_match: if_metageneration_match, diff --git a/google-cloud-storage/samples/acceptance/buckets_test.rb b/google-cloud-storage/samples/acceptance/buckets_test.rb index 04b6a0931ef8..bfd54f243b8b 100644 --- a/google-cloud-storage/samples/acceptance/buckets_test.rb +++ b/google-cloud-storage/samples/acceptance/buckets_test.rb @@ -584,8 +584,8 @@ end describe "storage move object" do - let(:file_1_name) { "file_1_name_#{SecureRandom.hex}.txt" } - let(:file_2_name) { "file_2_name_#{SecureRandom.hex}.txt" } + let(:source_file) { "file_1_name_#{SecureRandom.hex}.txt" } + let(:destination_file) { "file_2_name_#{SecureRandom.hex}.txt" } let :hns_bucket do hierarchical_namespace = Google::Apis::StorageV1::Bucket::HierarchicalNamespace.new enabled: true storage_client.create_bucket random_bucket_name do |b| @@ -596,22 +596,22 @@ let :create_source_file do file_content = "A" * (3 * 1024 * 1024) # 3 MB of 'A' characters file = StringIO.new file_content - hns_bucket.create_file file, file_1_name + hns_bucket.create_file file, source_file end it "object is moved and old object is deleted" do create_source_file out, _err = capture_io do - move_object bucket_name: hns_bucket.name, source_file_name: file_1_name, destination_file_name: file_2_name + move_object bucket_name: hns_bucket.name, source_file_name: source_file, destination_file_name: destination_file end - assert_includes out, "New File #{file_2_name} created\n" - refute_nil(hns_bucket.file(file_2_name)) - assert_nil(hns_bucket.file(file_1_name)) + assert_includes out, "New File #{destination_file} created\n" + refute_nil(hns_bucket.file(destination_file)) + assert_nil(hns_bucket.file(source_file)) end it "raises error if source and destination are having same filename" do create_source_file exception = assert_raises Google::Cloud::InvalidArgumentError do - move_object bucket_name: hns_bucket.name, source_file_name: file_1_name, destination_file_name: file_1_name + move_object bucket_name: hns_bucket.name, source_file_name: source_file, destination_file_name: source_file end assert_equal "invalid: Source and destination object names must be different.", exception.message end From f544fdae785067b022dc5073a3a4582735760d5f Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 8 Apr 2025 08:53:28 +0000 Subject: [PATCH 10/15] changing comments --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 2 +- google-cloud-storage/samples/acceptance/buckets_test.rb | 4 ++-- google-cloud-storage/test/google/cloud/storage/bucket_test.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 4e16f4e6c981..473546e21c32 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -3144,7 +3144,7 @@ def reload! alias refresh! reload! ## - # Moves object from source to destination path within bucket + # Moves File from source to destination path within bucket # This Operation is being performed at server side # @param [String] source_file The file name in existing bucket # @param [String] destination_file The new filename to be created on bucket diff --git a/google-cloud-storage/samples/acceptance/buckets_test.rb b/google-cloud-storage/samples/acceptance/buckets_test.rb index bfd54f243b8b..d826d088c006 100644 --- a/google-cloud-storage/samples/acceptance/buckets_test.rb +++ b/google-cloud-storage/samples/acceptance/buckets_test.rb @@ -583,7 +583,7 @@ end end - describe "storage move object" do + describe "storage move file" do let(:source_file) { "file_1_name_#{SecureRandom.hex}.txt" } let(:destination_file) { "file_2_name_#{SecureRandom.hex}.txt" } let :hns_bucket do @@ -598,7 +598,7 @@ file = StringIO.new file_content hns_bucket.create_file file, source_file end - it "object is moved and old object is deleted" do + it "file is moved and old object is deleted" do create_source_file out, _err = capture_io do move_object bucket_name: hns_bucket.name, source_file_name: source_file, destination_file_name: destination_file diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index a3daaa8c130d..658df0920bb4 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1381,7 +1381,7 @@ _(bucket.api_url).must_equal "#{new_url_root}/b/#{bucket_name}" mock.verify end - describe "storage move object" do + describe "storage move file" do it "moves a file object for bucket" do file_name = "file.ext" file_2_name = "file1.ext" From 4f7efa372d2ce7226882099d83c781efc12dda04 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 8 Apr 2025 09:02:37 +0000 Subject: [PATCH 11/15] fixing lint issue --- .../storage_remove_bucket_conditional_iam_binding.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/google-cloud-storage/samples/storage_remove_bucket_conditional_iam_binding.rb b/google-cloud-storage/samples/storage_remove_bucket_conditional_iam_binding.rb index 298450305845..0ee0f5a97ec5 100644 --- a/google-cloud-storage/samples/storage_remove_bucket_conditional_iam_binding.rb +++ b/google-cloud-storage/samples/storage_remove_bucket_conditional_iam_binding.rb @@ -37,10 +37,10 @@ def remove_bucket_conditional_iam_binding bucket_name: description: description, expression: expression } - if (b.role == role) && (b.condition && - b.condition.title == title && - b.condition.description == description && - b.condition.expression == expression) + if b.role == role && b.condition && + b.condition.title == title && + b.condition.description == description && + b.condition.expression == expression binding_to_remove = b end end From a58a39d21d04b631c5cf274ee3de2cb580b9b387 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 8 Apr 2025 09:13:28 +0000 Subject: [PATCH 12/15] fix name --- google-cloud-storage/test/google/cloud/storage/bucket_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index 658df0920bb4..203e423467e5 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1382,7 +1382,7 @@ mock.verify end describe "storage move file" do - it "moves a file object for bucket" do + it "moves a file for bucket" do file_name = "file.ext" file_2_name = "file1.ext" mock = Minitest::Mock.new From da9a43fbf58349130f130f704863f31084a88eca Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 9 Apr 2025 11:29:54 +0530 Subject: [PATCH 13/15] Update google-cloud-storage/lib/google/cloud/storage/service.rb Co-authored-by: Neha Bajaj --- google-cloud-storage/lib/google/cloud/storage/service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/service.rb b/google-cloud-storage/lib/google/cloud/storage/service.rb index acbee97af0e0..d9adf2acff65 100644 --- a/google-cloud-storage/lib/google/cloud/storage/service.rb +++ b/google-cloud-storage/lib/google/cloud/storage/service.rb @@ -631,7 +631,7 @@ def patch_file bucket_name, end ## - # Moves object from source to destination path within bucket + # Moves file from source to destination path within bucket def move_file name, source_file, destination_file, From eff229458529f639422ea6cef7219646e9dd8299 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 9 Apr 2025 11:30:31 +0530 Subject: [PATCH 14/15] Update google-cloud-storage/samples/acceptance/buckets_test.rb Co-authored-by: Neha Bajaj --- google-cloud-storage/samples/acceptance/buckets_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage/samples/acceptance/buckets_test.rb b/google-cloud-storage/samples/acceptance/buckets_test.rb index d826d088c006..7afc71d14415 100644 --- a/google-cloud-storage/samples/acceptance/buckets_test.rb +++ b/google-cloud-storage/samples/acceptance/buckets_test.rb @@ -598,7 +598,7 @@ file = StringIO.new file_content hns_bucket.create_file file, source_file end - it "file is moved and old object is deleted" do + it "file is moved and old file is deleted" do create_source_file out, _err = capture_io do move_object bucket_name: hns_bucket.name, source_file_name: source_file, destination_file_name: destination_file From c6ff862357b40f951c9bf02cd3ef6e42154ee315 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 9 Apr 2025 14:10:19 +0000 Subject: [PATCH 15/15] updating comment --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 473546e21c32..ca8461354bb7 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -3144,10 +3144,11 @@ def reload! alias refresh! reload! ## - # Moves File from source to destination path within bucket + # Moves File from source to destination path within the same HNS-enabled bucket # This Operation is being performed at server side # @param [String] source_file The file name in existing bucket # @param [String] destination_file The new filename to be created on bucket + # If the destination path includes non-existent parent folders, they will be created. # @example # require "google/cloud/storage" # storage = Google::Cloud::Storage.new