| 435 | } |
| 436 | |
| 437 | Status FileSystemCopyFile(FileSystem* src_fs, const string& src, |
| 438 | FileSystem* target_fs, const string& target) { |
| 439 | std::unique_ptr<RandomAccessFile> src_file; |
| 440 | TF_RETURN_IF_ERROR(src_fs->NewRandomAccessFile(src, &src_file)); |
| 441 | |
| 442 | std::unique_ptr<WritableFile> target_file; |
| 443 | TF_RETURN_IF_ERROR(target_fs->NewWritableFile(target, &target_file)); |
| 444 | |
| 445 | uint64 offset = 0; |
| 446 | std::unique_ptr<char[]> scratch(new char[kCopyFileBufferSize]); |
| 447 | Status s = Status::OK(); |
| 448 | while (s.ok()) { |
| 449 | StringPiece result; |
| 450 | s = src_file->Read(offset, kCopyFileBufferSize, &result, scratch.get()); |
| 451 | if (!(s.ok() || s.code() == error::OUT_OF_RANGE)) { |
| 452 | return s; |
| 453 | } |
| 454 | TF_RETURN_IF_ERROR(target_file->Append(result)); |
| 455 | offset += result.size(); |
| 456 | } |
| 457 | return target_file->Close(); |
| 458 | } |
| 459 | |
| 460 | // A ZeroCopyInputStream on a RandomAccessFile. |
| 461 | namespace { |