Skip to content

Commit c5d7eca

Browse files
xinhaoyuancopybara-github
authored andcommitted
Add RemoteFileCopy to be used later.
PiperOrigin-RevId: 754083880
1 parent a3a8f25 commit c5d7eca

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

common/remote_file.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ absl::StatusOr<std::vector<std::string>> RemoteListFiles(std::string_view path,
137137
// Renames a file from `from` to `to`.
138138
absl::Status RemoteFileRename(std::string_view from, std::string_view to);
139139

140+
// Copies a file from `from` to `to`.
141+
absl::Status RemoteFileCopy(std::string_view from, std::string_view to);
142+
140143
// Updates the last-modified time of `path` to the current time.
141144
absl::Status RemotePathTouchExistingFile(std::string_view path);
142145

common/remote_file_oss.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ absl::Status RemoteFileRename(std::string_view from, std::string_view to) {
185185
LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
186186
}
187187

188+
absl::Status RemoteFileCopy(std::string_view from, std::string_view to) {
189+
LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
190+
}
191+
188192
absl::Status RemotePathTouchExistingFile(std::string_view path) {
189193
LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
190194
}
@@ -246,6 +250,18 @@ absl::Status RemoteFileRename(std::string_view from, std::string_view to) {
246250
return absl::OkStatus();
247251
}
248252

253+
absl::Status RemoteFileCopy(std::string_view from, std::string_view to) {
254+
std::error_code error;
255+
std::filesystem::copy(
256+
from, to, std::filesystem::copy_options::overwrite_existing, error);
257+
if (error) {
258+
return absl::UnknownError(
259+
absl::StrCat("filesystem::copy() failed, from: ", std::string(from),
260+
", to: ", std::string(to), ", error: ", error.message()));
261+
}
262+
return absl::OkStatus();
263+
}
264+
249265
absl::Status RemotePathTouchExistingFile(std::string_view path) {
250266
if (!RemotePathExists(path)) {
251267
return absl::InvalidArgumentError(

0 commit comments

Comments
 (0)