Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cloud_controller/blobstore/local/local_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 16 additions & 13 deletions spec/unit/lib/cloud_controller/blobstore/local/local_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading