From 12dec4c4f293f5c703c2f68f50a2bdb67a75f60e Mon Sep 17 00:00:00 2001 From: PengChen Date: Mon, 21 Aug 2017 18:54:11 +0800 Subject: [PATCH] #1303 flash env bugfix (#1310) --- src/leveldb/util/env_flash.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/leveldb/util/env_flash.cc b/src/leveldb/util/env_flash.cc index 32a57020f..fd0702388 100644 --- a/src/leveldb/util/env_flash.cc +++ b/src/leveldb/util/env_flash.cc @@ -62,9 +62,13 @@ Status CopyToLocal(const std::string& local_fname, Env* env, return s; } - for (size_t i = 1; i < local_fname.size(); i++) { - if (local_fname.at(i) == '/') { - Env::Default()->CreateDir(local_fname.substr(0,i)); + size_t dir_pos = local_fname.rfind("/"); + if (dir_pos != std::string::npos) { + s = Env::Default()->CreateDir(local_fname.substr(0, dir_pos)); + if (!s.ok()) { + Log("[env_flash] create dir: %s failed: %s, exit", + local_fname.substr(0, dir_pos).c_str(), s.ToString().c_str()); + exit(-1); } } @@ -73,8 +77,8 @@ Status CopyToLocal(const std::string& local_fname, Env* env, s = Env::Default()->NewWritableFile(local_fname, &local_file); if (!s.ok()) { if (!vanish_allowed) { - Log("[env_flash] local env error, exit: %s\n", - local_fname.c_str()); + Log("[env_flash] create file: %s failed: %s, exit", + local_fname.c_str(), s.ToString().c_str()); exit(-1); } delete dfs_file;