From ed50308d2042bf845a9e8ddba69efb8244b879a0 Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Thu, 23 Feb 2017 10:46:54 -0800 Subject: [PATCH] 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 --- utilities/backupable/backupable_db.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/utilities/backupable/backupable_db.cc b/utilities/backupable/backupable_db.cc index 4a48c6b24..ed5601d55 100644 --- a/utilities/backupable/backupable_db.cc +++ b/utilities/backupable/backupable_db.cc @@ -1416,16 +1416,19 @@ Status BackupEngineImpl::InsertPathnameToSizeBytes( std::unordered_map* result) { assert(result != nullptr); std::vector 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() {