Skip to content
Closed
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
3 changes: 2 additions & 1 deletion cpp/src/arrow/filesystem/gcsfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ Status GcsFileSystem::DeleteDir(const std::string& path) {
}

Status GcsFileSystem::DeleteDirContents(const std::string& path) {
return Status::NotImplemented("The GCS FileSystem is not fully implemented");
ARROW_ASSIGN_OR_RAISE(auto p, GcsPath::FromString(path));
return impl_->DeleteDirContents(p, io_context());
}

Status GcsFileSystem::DeleteRootDirContents() {
Expand Down
35 changes: 35 additions & 0 deletions cpp/src/arrow/filesystem/gcsfs_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,41 @@ TEST_F(GcsIntegrationTest, DeleteDirSuccess) {
}
}

TEST_F(GcsIntegrationTest, DeleteDirContentsSuccess) {
auto fs = internal::MakeGcsFileSystemForTest(TestGcsOptions());
const char* const kTestFolders[] = {
"a/", "a/0/", "a/0/0/", "a/1/", "a/2/",
};
for (auto const* f : kTestFolders) {
const auto folder = PreexistingBucketPath() + f;
ASSERT_OK(fs->CreateDir(folder, true));
for (int i = 0; i != 64; ++i) {
const auto filename = folder + "test-file-" + std::to_string(i);
ASSERT_OK_AND_ASSIGN(auto w, fs->OpenOutputStream(filename, {}));
ASSERT_OK(w->Write(filename.data(), filename.size()));
ASSERT_OK(w->Close());
}
}

const auto folder = PreexistingBucketPath() + kTestFolders[0];
ASSERT_OK(fs->DeleteDirContents(folder));
arrow::fs::AssertFileInfo(fs.get(), folder, FileType::Directory);
arrow::fs::AssertFileInfo(fs.get(), PreexistingBucketPath(), FileType::Directory);
arrow::fs::AssertFileInfo(fs.get(), PreexistingObjectPath(), FileType::File);

for (auto const* f : kTestFolders) {
const auto subfolder = PreexistingBucketPath() + f;
if (subfolder == folder) {
continue;
}
arrow::fs::AssertFileInfo(fs.get(), subfolder, FileType::NotFound);
for (int i = 0; i != 64; ++i) {
const auto filename = subfolder + "test-file-" + std::to_string(i);
arrow::fs::AssertFileInfo(fs.get(), filename, FileType::NotFound);
}
}
}

TEST_F(GcsIntegrationTest, DeleteRootDirContents) {
auto fs = internal::MakeGcsFileSystemForTest(TestGcsOptions());
EXPECT_RAISES_WITH_MESSAGE_THAT(NotImplemented, HasSubstr("too dangerous"),
Expand Down