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
11 changes: 10 additions & 1 deletion cpp/src/arrow/filesystem/gcsfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ class GcsFileSystem::Impl {
return GetFileInfoImpl(path, std::move(meta).status(), FileType::Directory);
}

Status DeleteFile(const GcsPath& p) {
if (!p.object.empty() && p.object.back() == '/') {
return Status::IOError("The given path (" + p.full_path +
") is a directory, use DeleteDir");
}
return internal::ToArrowStatus(client_.DeleteObject(p.bucket, p.object));
}

Status CopyFile(const GcsPath& src, const GcsPath& dest) {
auto metadata =
client_.RewriteObjectBlocking(src.bucket, src.object, dest.bucket, dest.object);
Expand Down Expand Up @@ -272,7 +280,8 @@ Status GcsFileSystem::DeleteRootDirContents() {
}

Status GcsFileSystem::DeleteFile(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_->DeleteFile(p);
}

Status GcsFileSystem::Move(const std::string& src, const std::string& dest) {
Expand Down
17 changes: 17 additions & 0 deletions cpp/src/arrow/filesystem/gcsfs_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,23 @@ TEST_F(GcsIntegrationTest, GetFileInfoObject) {
arrow::fs::AssertFileInfo(fs.get(), PreexistingObjectPath(), FileType::File);
}

TEST_F(GcsIntegrationTest, DeleteFileSuccess) {
auto fs = internal::MakeGcsFileSystemForTest(TestGcsOptions());
ASSERT_OK(fs->DeleteFile(PreexistingObjectPath()));
arrow::fs::AssertFileInfo(fs.get(), PreexistingObjectPath(), FileType::NotFound);
}

TEST_F(GcsIntegrationTest, DeleteFileFailure) {
auto fs = internal::MakeGcsFileSystemForTest(TestGcsOptions());
ASSERT_RAISES(IOError, fs->DeleteFile(NotFoundObjectPath()));
}

TEST_F(GcsIntegrationTest, DeleteFileDirectoryFails) {
auto fs = internal::MakeGcsFileSystemForTest(TestGcsOptions());
const auto path = std::string(kPreexistingBucket) + "/DeleteFileDirectoryFails/";
ASSERT_RAISES(IOError, fs->DeleteFile(path));
}

TEST_F(GcsIntegrationTest, CopyFileSuccess) {
auto fs = internal::MakeGcsFileSystemForTest(TestGcsOptions());
const auto destination_path = kPreexistingBucket + std::string("/copy-destination");
Expand Down