From f3fe6f883b22b49533c6506020f220dcf0f8bfa5 Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Mon, 29 Jan 2018 20:59:59 -0800 Subject: [PATCH] fix for checkpoint directory with trailing slash(es) Summary: previously if `checkpoint_dir` contained a trailing slash, we'd attempt to create the `.tmp` directory under `checkpoint_dir` due to simply concatenating `checkpoint_dir + ".tmp"`. This failed because `checkpoint_dir` hadn't been created yet and our directory creation is non-recursive. This PR fixes the issue by always creating the `.tmp` directory in the same parent as `checkpoint_dir` by stripping trailing slashes before concatenating. Closes https://github.com/facebook/rocksdb/pull/3275 Differential Revision: D6574952 Pulled By: ajkr fbshipit-source-id: a6daa6777a901eac2460cd0140c9515f7241aefc --- utilities/checkpoint/checkpoint_impl.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/utilities/checkpoint/checkpoint_impl.cc b/utilities/checkpoint/checkpoint_impl.cc index 0cdddbd62..b116afe34 100644 --- a/utilities/checkpoint/checkpoint_impl.cc +++ b/utilities/checkpoint/checkpoint_impl.cc @@ -59,7 +59,21 @@ Status CheckpointImpl::CreateCheckpoint(const std::string& checkpoint_dir, db_options.info_log, "Started the snapshot process -- creating snapshot in directory %s", checkpoint_dir.c_str()); - std::string full_private_path = checkpoint_dir + ".tmp"; + + size_t final_nonslash_idx = checkpoint_dir.find_last_not_of('/'); + if (final_nonslash_idx == std::string::npos) { + // npos means it's only slashes, which means it's the root directory, but it + // shouldn't be because we verified above the directory doesn't exist. + assert(false); + return Status::InvalidArgument("invalid checkpoint directory name"); + } + + std::string full_private_path = + checkpoint_dir.substr(0, final_nonslash_idx + 1) + ".tmp"; + ROCKS_LOG_INFO( + db_options.info_log, + "Snapshot process -- using temporary directory %s", + full_private_path.c_str()); // create snapshot directory s = db_->GetEnv()->CreateDir(full_private_path); uint64_t sequence_number = 0;