check backup directory exists before listing children

Summary:
InsertPathnameToSizeBytes() is called on shared/ and shared_checksum/ directories, which only exist for certain configurations. If we try to list a non-existent directory's contents, some Envs will dump an error message. Let's avoid this by checking whether the directory exists before listing its contents.
Closes https://github.com/facebook/rocksdb/pull/1895

Differential Revision: D4596301

Pulled By: ajkr

fbshipit-source-id: c809679
main
Andrew Kryczka 8 years ago committed by Facebook Github Bot
parent 4d7c06cedf
commit ed50308d20
  1. 11
      utilities/backupable/backupable_db.cc

@ -1416,16 +1416,19 @@ Status BackupEngineImpl::InsertPathnameToSizeBytes(
std::unordered_map<std::string, uint64_t>* result) {
assert(result != nullptr);
std::vector<Env::FileAttributes> files_attrs;
Status status = env->GetChildrenFileAttributes(dir, &files_attrs);
if (!status.ok()) {
return status;
Status status = env->FileExists(dir);
if (status.ok()) {
status = env->GetChildrenFileAttributes(dir, &files_attrs);
} else if (status.IsNotFound()) {
// Insert no entries can be considered success
status = Status::OK();
}
const bool slash_needed = dir.empty() || dir.back() != '/';
for (const auto& file_attrs : files_attrs) {
result->emplace(dir + (slash_needed ? "/" : "") + file_attrs.name,
file_attrs.size_bytes);
}
return Status::OK();
return status;
}
Status BackupEngineImpl::GarbageCollect() {

Loading…
Cancel
Save