From 3a073234da663709fcb7a479ec88ce7476c48e3a Mon Sep 17 00:00:00 2001 From: sdong Date: Tue, 4 Feb 2020 11:37:07 -0800 Subject: [PATCH] Consolidate ReadFileToString() (#6366) Summary: It's a minor refactoring. We have two ReadFileToString() but they are very similar. Make the one with Env argument calls the one with FS argument instead. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6366 Test Plan: Run all existing tests Differential Revision: D19712332 fbshipit-source-id: 5ae6fabf6355938690d95cda52afd1f39e0a7823 --- env/env.cc | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/env/env.cc b/env/env.cc index 514f78fe3..ea8a653c6 100644 --- a/env/env.cc +++ b/env/env.cc @@ -378,28 +378,8 @@ Status WriteStringToFile(Env* env, const Slice& data, const std::string& fname, } Status ReadFileToString(Env* env, const std::string& fname, std::string* data) { - EnvOptions soptions; - data->clear(); - std::unique_ptr file; - Status s = env->NewSequentialFile(fname, &file, soptions); - if (!s.ok()) { - return s; - } - static const int kBufferSize = 8192; - char* space = new char[kBufferSize]; - while (true) { - Slice fragment; - s = file->Read(kBufferSize, &fragment, space); - if (!s.ok()) { - break; - } - data->append(fragment.data(), fragment.size()); - if (fragment.empty()) { - break; - } - } - delete[] space; - return s; + LegacyFileSystemWrapper lfsw(env); + return ReadFileToString(&lfsw, fname, data); } EnvWrapper::~EnvWrapper() {