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
19 changes: 18 additions & 1 deletion cpp/src/arrow/filesystem/gcsfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,21 @@ class GcsFileSystem::Impl {
return internal::ToArrowStatus(client_.DeleteObject(p.bucket, p.object));
}

Status Move(const GcsPath& src, const GcsPath& dest) {
if (src.full_path.empty() || src.object.empty() ||
src.object.back() == internal::kSep) {
return Status::IOError(
"Moving directories or buckets cannot be implemented in GCS. You provided (" +
src.full_path + ") as a source for Move()");
}
ARROW_ASSIGN_OR_RAISE(auto info, GetFileInfo(dest));
if (info.IsDirectory()) {
return Status::IOError("Attempting to Move() to an existing directory");
}
RETURN_NOT_OK(CopyFile(src, dest));
return DeleteFile(src);
}

Status CopyFile(const GcsPath& src, const GcsPath& dest) {
auto metadata =
client_.RewriteObjectBlocking(src.bucket, src.object, dest.bucket, dest.object);
Expand Down Expand Up @@ -460,7 +475,9 @@ Status GcsFileSystem::DeleteFile(const std::string& path) {
}

Status GcsFileSystem::Move(const std::string& src, const std::string& dest) {
return Status::NotImplemented("The GCS FileSystem is not fully implemented");
ARROW_ASSIGN_OR_RAISE(auto s, GcsPath::FromString(src));
ARROW_ASSIGN_OR_RAISE(auto d, GcsPath::FromString(dest));
return impl_->Move(s, d);
}

Status GcsFileSystem::CopyFile(const std::string& src, const std::string& dest) {
Expand Down
26 changes: 26 additions & 0 deletions cpp/src/arrow/filesystem/gcsfs_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,32 @@ TEST_F(GcsIntegrationTest, DeleteFileDirectoryFails) {
ASSERT_RAISES(IOError, fs->DeleteFile(path));
}

TEST_F(GcsIntegrationTest, MoveFileSuccess) {
auto fs = internal::MakeGcsFileSystemForTest(TestGcsOptions());
const auto destination_path = PreexistingBucketPath() + "move-destination";
ASSERT_OK(fs->Move(PreexistingObjectPath(), destination_path));
arrow::fs::AssertFileInfo(fs.get(), destination_path, FileType::File);
arrow::fs::AssertFileInfo(fs.get(), PreexistingObjectPath(), FileType::NotFound);
}

TEST_F(GcsIntegrationTest, MoveFileCannotRenameBuckets) {
auto fs = internal::MakeGcsFileSystemForTest(TestGcsOptions());
ASSERT_RAISES(IOError, fs->Move(PreexistingBucketPath(), "another-bucket/"));
}

TEST_F(GcsIntegrationTest, MoveFileCannotRenameDirectories) {
auto fs = internal::MakeGcsFileSystemForTest(TestGcsOptions());
ASSERT_RAISES(IOError, fs->Move(PreexistingBucketPath() + "folder/",
PreexistingBucketPath() + "new-name"));
}

TEST_F(GcsIntegrationTest, MoveFileCannotRenameToDirectory) {
auto fs = internal::MakeGcsFileSystemForTest(TestGcsOptions());
ASSERT_OK(fs->CreateDir(PreexistingBucketPath() + "destination/", false));
ASSERT_RAISES(IOError, fs->Move(PreexistingObjectPath(),
PreexistingBucketPath() + "destination/"));
}

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