summaryrefslogtreecommitdiff
path: root/helpers
diff options
context:
space:
mode:
authorVictor Costan <costan@google.com>2020-01-08 09:14:53 -0800
committerVictor Costan <pwnall@chromium.org>2020-01-09 09:18:14 -0800
commita0191e5563b7a6c24b39edcbdbff29e602e0acfc (patch)
treec3e49f71d5e21af688f6c554431ee33e53425c46 /helpers
parentd152b23f3b787f67a0ac3a40498e13831f3778d7 (diff)
downloadleveldb-a0191e5563b7a6c24b39edcbdbff29e602e0acfc.tar.gz
Add Env::Remove{File,Dir} which obsolete Env::Delete{File,Dir}.
The "DeleteFile" method name causes pain for Windows developers, because <windows.h> #defines a DeleteFile macro to DeleteFileW or DeleteFileA. Current code uses workarounds, like #undefining DeleteFile everywhere an Env is declared, implemented, or used. This CL removes the need for workarounds by renaming Env::DeleteFile to Env::RemoveFile. For consistency, Env::DeleteDir is also renamed to Env::RemoveDir. A few internal methods are also renamed for consistency. Software that supports Windows is expected to migrate any Env implementations and usage to Remove{File,Dir}, and never use the name Env::Delete{File,Dir} in its code. The renaming is done in a backwards-compatible way, at the risk of making it slightly more difficult to build a new correct Env implementation. The backwards compatibility is achieved using the following hacks: 1) Env::Remove{File,Dir} methods are added, with a default implementation that calls into Env::Delete{File,Dir}. This makes old Env implementations compatible with code that calls into the updated API. 2) The Env::Delete{File,Dir} methods are no longer pure virtuals. Instead, they gain a default implementation that calls into Env::Remove{File,Dir}. This makes updated Env implementations compatible with code that calls into the old API. The cost of this approach is that it's possible to write an Env without overriding either Rename{File,Dir} or Delete{File,Dir}, without getting a compiler warning. However, attempting to run the test suite will immediately fail with an infinite call stack ending in {Remove,Delete}{File,Dir}, making developers aware of the problem. PiperOrigin-RevId: 288710907
Diffstat (limited to 'helpers')
-rw-r--r--helpers/memenv/memenv.cc10
-rw-r--r--helpers/memenv/memenv_test.cc6
2 files changed, 8 insertions, 8 deletions
diff --git a/helpers/memenv/memenv.cc b/helpers/memenv/memenv.cc
index 31d2bc0..383c78b 100644
--- a/helpers/memenv/memenv.cc
+++ b/helpers/memenv/memenv.cc
@@ -309,7 +309,7 @@ class InMemoryEnv : public EnvWrapper {
return Status::OK();
}
- void DeleteFileInternal(const std::string& fname)
+ void RemoveFileInternal(const std::string& fname)
EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
if (file_map_.find(fname) == file_map_.end()) {
return;
@@ -319,19 +319,19 @@ class InMemoryEnv : public EnvWrapper {
file_map_.erase(fname);
}
- Status DeleteFile(const std::string& fname) override {
+ Status RemoveFile(const std::string& fname) override {
MutexLock lock(&mutex_);
if (file_map_.find(fname) == file_map_.end()) {
return Status::IOError(fname, "File not found");
}
- DeleteFileInternal(fname);
+ RemoveFileInternal(fname);
return Status::OK();
}
Status CreateDir(const std::string& dirname) override { return Status::OK(); }
- Status DeleteDir(const std::string& dirname) override { return Status::OK(); }
+ Status RemoveDir(const std::string& dirname) override { return Status::OK(); }
Status GetFileSize(const std::string& fname, uint64_t* file_size) override {
MutexLock lock(&mutex_);
@@ -350,7 +350,7 @@ class InMemoryEnv : public EnvWrapper {
return Status::IOError(src, "File not found");
}
- DeleteFileInternal(target);
+ RemoveFileInternal(target);
file_map_[target] = file_map_[src];
file_map_.erase(src);
return Status::OK();
diff --git a/helpers/memenv/memenv_test.cc b/helpers/memenv/memenv_test.cc
index 619fe51..93186ab 100644
--- a/helpers/memenv/memenv_test.cc
+++ b/helpers/memenv/memenv_test.cc
@@ -88,12 +88,12 @@ TEST_F(MemEnvTest, Basics) {
ASSERT_TRUE(!rand_file);
// Check that deleting works.
- ASSERT_TRUE(!env_->DeleteFile("/dir/non_existent").ok());
- ASSERT_LEVELDB_OK(env_->DeleteFile("/dir/g"));
+ ASSERT_TRUE(!env_->RemoveFile("/dir/non_existent").ok());
+ ASSERT_LEVELDB_OK(env_->RemoveFile("/dir/g"));
ASSERT_TRUE(!env_->FileExists("/dir/g"));
ASSERT_LEVELDB_OK(env_->GetChildren("/dir", &children));
ASSERT_EQ(0, children.size());
- ASSERT_LEVELDB_OK(env_->DeleteDir("/dir"));
+ ASSERT_LEVELDB_OK(env_->RemoveDir("/dir"));
}
TEST_F(MemEnvTest, ReadWrite) {