Просмотр исходного кода

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
naive_version
sanjay 7 лет назад
committed by Victor Costan
Родитель
Сommit
2372ac574f
1 измененных файлов: 2 добавлений и 2 удалений
  1. +2
    -2
      util/env_posix.cc

+ 2
- 2
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);

Загрузка…
Отмена
Сохранить