Skip to content

Commit d1bf989

Browse files
authored
Fix LocalClient#delete_all_in_path not using partitioned key (#5237)
1 parent bdaef63 commit d1bf989

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

lib/cloud_controller/blobstore/local/local_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def delete_all(_=nil)
9797
end
9898

9999
def delete_all_in_path(path)
100-
dir = File.join(@base_path, path)
100+
dir = File.join(@base_path, File.dirname(partitioned_key(path)))
101101
FileUtils.rm_rf(dir) if File.directory?(dir)
102102
end
103103

spec/unit/lib/cloud_controller/blobstore/local/local_client_spec.rb

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,22 @@ module Blobstore
251251
end
252252

253253
describe '#delete_all_in_path' do
254-
it 'deletes all files in a specific path' do
255-
path1 = File.join(base_path, directory_key, 'path1', 'file1')
256-
path2 = File.join(base_path, directory_key, 'path2', 'file2')
257-
258-
FileUtils.mkdir_p(File.dirname(path1))
259-
FileUtils.mkdir_p(File.dirname(path2))
260-
File.write(path1, 'content1')
261-
File.write(path2, 'content2')
262-
263-
client.delete_all_in_path('path1')
264-
265-
expect(File.exist?(path1)).to be(false)
266-
expect(File.exist?(path2)).to be(true)
254+
it 'deletes all files in the partitioned directory for the given key' do
255+
key1 = 'abcdef1234'
256+
key2 = 'abcdef5678'
257+
other_key = 'ffff001234'
258+
tmpfile = Tempfile.new.tap { |f| f.write('x') && f.flush }
259+
260+
client.cp_to_blobstore(tmpfile.path, key1)
261+
client.cp_to_blobstore(tmpfile.path, key2)
262+
client.cp_to_blobstore(tmpfile.path, other_key)
263+
264+
# key1 and key2 share the same partitioned directory (ab/cd/)
265+
client.delete_all_in_path(key1)
266+
267+
expect(client.exists?(key1)).to be(false)
268+
expect(client.exists?(key2)).to be(false)
269+
expect(client.exists?(other_key)).to be(true)
267270
end
268271
end
269272

0 commit comments

Comments
 (0)