diff options
author | sanjay <sanjay@google.com> | 2017-10-02 16:04:02 -0700 |
---|---|---|
committer | Victor Costan <pwnall@chromium.org> | 2017-10-03 11:32:02 -0700 |
commit | 2372ac574fdeb1235e70cdd86a2681d1ce05cf65 (patch) | |
tree | 7d08e1ddec4dbfb593c2a209fdb1533986ad09a8 | |
parent | 1c75e88055e06da2939f9f4bd294625b76792815 (diff) | |
download | leveldb-2372ac574fdeb1235e70cdd86a2681d1ce05cf65.tar.gz |
Fix file writing bug in CL 170738066.
If the file already existed, we should have truncated it. This was not
detected by leveldb tests since leveldb code avoids reusing same files,
but there was code elsewhere that was directly using leveldb files and
relying on this behavior.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=170769101
-rw-r--r-- | util/env_posix.cc | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/util/env_posix.cc b/util/env_posix.cc index 1a88802..8d84ac7 100644 --- a/util/env_posix.cc +++ b/util/env_posix.cc @@ -429,7 +429,7 @@ class PosixEnv : public Env { virtual Status NewWritableFile(const std::string& fname, WritableFile** result) { Status s; - int fd = open(fname.c_str(), O_RDWR | O_CREAT, 0644); + int fd = open(fname.c_str(), O_TRUNC | O_WRONLY | O_CREAT, 0644); if (fd < 0) { *result = NULL; s = PosixError(fname, errno); @@ -442,7 +442,7 @@ class PosixEnv : public Env { virtual Status NewAppendableFile(const std::string& fname, WritableFile** result) { Status s; - int fd = open(fname.c_str(), O_APPEND | O_RDWR | O_CREAT, 0644); + int fd = open(fname.c_str(), O_APPEND | O_WRONLY | O_CREAT, 0644); if (fd < 0) { *result = NULL; s = PosixError(fname, errno); |