Skip to content

Commit

Permalink
apacheGH-38618: [C++] S3FileSystem: fix regression in deleting explic…
Browse files Browse the repository at this point in the history
…itly created sub-directories
  • Loading branch information
jorisvandenbossche committed Nov 22, 2023
1 parent c1b12ca commit 02b3dce
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cpp/src/arrow/filesystem/s3fs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2408,7 +2408,11 @@ class S3FileSystem::Impl : public std::enable_shared_from_this<S3FileSystem::Imp
std::vector<std::string> file_paths;
for (const auto& file_info : file_infos) {
DCHECK_GT(file_info.path().size(), bucket.size());
file_paths.push_back(file_info.path().substr(bucket.size() + 1));
auto file_path = file_info.path().substr(bucket.size() + 1);
if (file_info.IsDirectory()) {
file_path = file_path + kSep;
}
file_paths.push_back(file_path);
}
scheduler->AddSimpleTask(
[=, file_paths = std::move(file_paths)] {
Expand Down
28 changes: 28 additions & 0 deletions python/pyarrow/tests/test_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,34 @@ def test_delete_dir(fs, pathfn):
fs.delete_dir(d)


def test_delete_dir_with_explicit_subdir(fs, pathfn):
skip_fsspec_s3fs(fs)

d = pathfn('directory/')
nd = pathfn('directory/nested/')

# deleting dir with explicit subdir
fs.create_dir(d)
fs.create_dir(nd)
fs.delete_dir(d)
dir_info = fs.get_file_info(d)
assert dir_info.type == FileType.NotFound

# deleting dir with blob in explicit subdir
d = pathfn('directory2')
nd = pathfn('directory2/nested')
f = pathfn('directory2/nested/target-file')

fs.create_dir(d)
fs.create_dir(nd)
with fs.open_output_stream(f) as s:
s.write(b'data')

fs.delete_dir(d)
dir_info = fs.get_file_info(d)
assert dir_info.type == FileType.NotFound


def test_delete_dir_contents(fs, pathfn):
skip_fsspec_s3fs(fs)

Expand Down

0 comments on commit 02b3dce

Please sign in to comment.