From badf724e35f9aac3abf00f71fc1f975aa89c7a82 Mon Sep 17 00:00:00 2001 From: Wei Quan Date: Fri, 26 Jun 2026 13:31:06 +0200 Subject: [PATCH] Fix LocalClient#delete_all_in_path not using partitioned key delete_all_in_path was building the path with the raw key instead of partitioned_key, so it looked in the wrong directory and deleted nothing. All other LocalClient methods use partitioned_key consistently. --- .../blobstore/local/local_client.rb | 2 +- .../blobstore/local/local_client_spec.rb | 29 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/cloud_controller/blobstore/local/local_client.rb b/lib/cloud_controller/blobstore/local/local_client.rb index cb331c27300..fa858bd6c96 100644 --- a/lib/cloud_controller/blobstore/local/local_client.rb +++ b/lib/cloud_controller/blobstore/local/local_client.rb @@ -97,7 +97,7 @@ def delete_all(_=nil) end def delete_all_in_path(path) - dir = File.join(@base_path, path) + dir = File.join(@base_path, File.dirname(partitioned_key(path))) FileUtils.rm_rf(dir) if File.directory?(dir) end diff --git a/spec/unit/lib/cloud_controller/blobstore/local/local_client_spec.rb b/spec/unit/lib/cloud_controller/blobstore/local/local_client_spec.rb index 07fbb139493..6788bce225d 100644 --- a/spec/unit/lib/cloud_controller/blobstore/local/local_client_spec.rb +++ b/spec/unit/lib/cloud_controller/blobstore/local/local_client_spec.rb @@ -251,19 +251,22 @@ module Blobstore end describe '#delete_all_in_path' do - it 'deletes all files in a specific path' do - path1 = File.join(base_path, directory_key, 'path1', 'file1') - path2 = File.join(base_path, directory_key, 'path2', 'file2') - - FileUtils.mkdir_p(File.dirname(path1)) - FileUtils.mkdir_p(File.dirname(path2)) - File.write(path1, 'content1') - File.write(path2, 'content2') - - client.delete_all_in_path('path1') - - expect(File.exist?(path1)).to be(false) - expect(File.exist?(path2)).to be(true) + it 'deletes all files in the partitioned directory for the given key' do + key1 = 'abcdef1234' + key2 = 'abcdef5678' + other_key = 'ffff001234' + tmpfile = Tempfile.new.tap { |f| f.write('x') && f.flush } + + client.cp_to_blobstore(tmpfile.path, key1) + client.cp_to_blobstore(tmpfile.path, key2) + client.cp_to_blobstore(tmpfile.path, other_key) + + # key1 and key2 share the same partitioned directory (ab/cd/) + client.delete_all_in_path(key1) + + expect(client.exists?(key1)).to be(false) + expect(client.exists?(key2)).to be(false) + expect(client.exists?(other_key)).to be(true) end end