Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Unified Diff: third_party/leveldatabase/env_chromium.cc

Issue 11445030: Add sync of parent directory when creating or renaming a file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Correct flag to open() for directory. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/leveldatabase/env_chromium.cc
diff --git a/third_party/leveldatabase/env_chromium.cc b/third_party/leveldatabase/env_chromium.cc
index 3cdb094f5ac2b1f7e39dc50d78cdff6c71ddcd13..e8ffcfdd369cce0a2a9df78fff503009b645f273 100644
--- a/third_party/leveldatabase/env_chromium.cc
+++ b/third_party/leveldatabase/env_chromium.cc
@@ -31,6 +31,10 @@
#include "base/win/win_util.h"
#endif
+#if !defined(OS_WIN)
+#include <fcntl.h>
+#endif
+
namespace {
#if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_ANDROID) || \
@@ -70,6 +74,34 @@ FILE* fopen_internal(const char* fname, const char* mode) {
#endif
}
+::FilePath CreateFilePath(const std::string& file_path) {
+#if defined(OS_WIN)
+ return FilePath(UTF8ToUTF16(file_path));
+#else
+ return FilePath(file_path);
+#endif
+}
+
+std::string FilePathToString(const ::FilePath& file_path) {
+#if defined(OS_WIN)
+ return UTF16ToUTF8(file_path.value());
+#else
+ return file_path.value();
+#endif
+}
+
+bool sync_parent(const std::string& fname) {
+#if !defined(OS_WIN)
dgrogan 2013/05/28 22:02:19 What was the impetus for skipping this on windows?
ericu 2013/05/28 22:05:25 I asked Siggi, and he said that on Windows there w
+ FilePath parent_dir = CreateFilePath(fname).DirName();
+ int parent_fd = open(FilePathToString(parent_dir).c_str(), O_RDONLY);
+ if (parent_fd < 0)
+ return false;
+ fsync(parent_fd);
+ close(parent_fd);
+#endif
+ return true;
+}
+
enum UmaEntry {
kSequentialFileRead,
kSequentialFileSkip,
@@ -108,22 +140,6 @@ class Thread;
static const ::FilePath::CharType kLevelDBTestDirectoryPrefix[]
= FILE_PATH_LITERAL("leveldb-test-");
-::FilePath CreateFilePath(const std::string& file_path) {
-#if defined(OS_WIN)
- return FilePath(UTF8ToUTF16(file_path));
-#else
- return FilePath(file_path);
-#endif
-}
-
-std::string FilePathToString(const ::FilePath& file_path) {
-#if defined(OS_WIN)
- return UTF16ToUTF8(file_path.value());
-#else
- return file_path.value();
-#endif
-}
-
// TODO(jorlow): This should be moved into Chromium's base.
const char* PlatformFileErrorString(const ::base::PlatformFileError& error) {
switch (error) {
@@ -328,6 +344,10 @@ class ChromiumEnv : public Env {
LogToUMA(kNewWritableFile);
return Status::IOError(fname, strerror(errno));
} else {
+ if (!sync_parent(fname)) {
+ fclose(f);
+ return Status::IOError(fname, strerror(errno));
+ }
*result = new ChromiumWritableFile(fname, f);
return Status::OK();
}
@@ -400,6 +420,10 @@ class ChromiumEnv : public Env {
if (!::file_util::ReplaceFile(CreateFilePath(src), CreateFilePath(dst))) {
result = Status::IOError(src, "Could not rename file.");
LogToUMA(kRenamefile);
+ } else {
+ sync_parent(dst);
+ if (src != dst)
+ sync_parent(src);
}
return result;
}
@@ -477,6 +501,10 @@ class ChromiumEnv : public Env {
LogToUMA(kNewLogger);
return Status::IOError(fname, strerror(errno));
} else {
+ if (!sync_parent(fname)) {
+ fclose(f);
+ return Status::IOError(fname, strerror(errno));
+ }
*result = new ChromiumLogger(f);
return Status::OK();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698