OLD | NEW |
1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved. | 1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. See the AUTHORS file for names of contributors. | 3 // found in the LICENSE file. See the AUTHORS file for names of contributors. |
4 | 4 |
5 #include <deque> | 5 #include <deque> |
6 #include <errno.h> | 6 #include <errno.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 // Wide-char safe fopen wrapper. | 68 // Wide-char safe fopen wrapper. |
69 FILE* fopen_internal(const char* fname, const char* mode) { | 69 FILE* fopen_internal(const char* fname, const char* mode) { |
70 #if defined(OS_WIN) | 70 #if defined(OS_WIN) |
71 return _wfopen(UTF8ToUTF16(fname).c_str(), ASCIIToUTF16(mode).c_str()); | 71 return _wfopen(UTF8ToUTF16(fname).c_str(), ASCIIToUTF16(mode).c_str()); |
72 #else | 72 #else |
73 return fopen(fname, mode); | 73 return fopen(fname, mode); |
74 #endif | 74 #endif |
75 } | 75 } |
76 | 76 |
77 ::FilePath CreateFilePath(const std::string& file_path) { | 77 base::FilePath CreateFilePath(const std::string& file_path) { |
78 #if defined(OS_WIN) | 78 #if defined(OS_WIN) |
79 return FilePath(UTF8ToUTF16(file_path)); | 79 return base::FilePath(UTF8ToUTF16(file_path)); |
80 #else | 80 #else |
81 return FilePath(file_path); | 81 return base::FilePath(file_path); |
82 #endif | 82 #endif |
83 } | 83 } |
84 | 84 |
85 std::string FilePathToString(const ::FilePath& file_path) { | 85 std::string FilePathToString(const base::FilePath& file_path) { |
86 #if defined(OS_WIN) | 86 #if defined(OS_WIN) |
87 return UTF16ToUTF8(file_path.value()); | 87 return UTF16ToUTF8(file_path.value()); |
88 #else | 88 #else |
89 return file_path.value(); | 89 return file_path.value(); |
90 #endif | 90 #endif |
91 } | 91 } |
92 | 92 |
93 bool sync_parent(const std::string& fname) { | 93 bool sync_parent(const std::string& fname) { |
94 #if !defined(OS_WIN) | 94 #if !defined(OS_WIN) |
95 FilePath parent_dir = CreateFilePath(fname).DirName(); | 95 base::FilePath parent_dir = CreateFilePath(fname).DirName(); |
96 int parent_fd = HANDLE_EINTR(open(FilePathToString(parent_dir).c_str(), O_RDON
LY)); | 96 int parent_fd = HANDLE_EINTR(open(FilePathToString(parent_dir).c_str(), O_RDON
LY)); |
97 if (parent_fd < 0) | 97 if (parent_fd < 0) |
98 return false; | 98 return false; |
99 HANDLE_EINTR(fsync(parent_fd)); | 99 HANDLE_EINTR(fsync(parent_fd)); |
100 HANDLE_EINTR(close(parent_fd)); | 100 HANDLE_EINTR(close(parent_fd)); |
101 #endif | 101 #endif |
102 return true; | 102 return true; |
103 } | 103 } |
104 | 104 |
105 enum UmaEntry { | 105 enum UmaEntry { |
(...skipping 27 matching lines...) Expand all Loading... |
133 }; | 133 }; |
134 | 134 |
135 } // namespace | 135 } // namespace |
136 | 136 |
137 namespace leveldb { | 137 namespace leveldb { |
138 | 138 |
139 namespace { | 139 namespace { |
140 | 140 |
141 class Thread; | 141 class Thread; |
142 | 142 |
143 static const ::FilePath::CharType kLevelDBTestDirectoryPrefix[] | 143 static const base::FilePath::CharType kLevelDBTestDirectoryPrefix[] |
144 = FILE_PATH_LITERAL("leveldb-test-"); | 144 = FILE_PATH_LITERAL("leveldb-test-"); |
145 | 145 |
146 const char* PlatformFileErrorString(const ::base::PlatformFileError& error) { | 146 const char* PlatformFileErrorString(const ::base::PlatformFileError& error) { |
147 switch (error) { | 147 switch (error) { |
148 case ::base::PLATFORM_FILE_ERROR_FAILED: | 148 case ::base::PLATFORM_FILE_ERROR_FAILED: |
149 return "Opening file failed."; | 149 return "Opening file failed."; |
150 case ::base::PLATFORM_FILE_ERROR_IN_USE: | 150 case ::base::PLATFORM_FILE_ERROR_IN_USE: |
151 return "File currently in use."; | 151 return "File currently in use."; |
152 case ::base::PLATFORM_FILE_ERROR_EXISTS: | 152 case ::base::PLATFORM_FILE_ERROR_EXISTS: |
153 return "File already exists."; | 153 return "File already exists."; |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 | 374 |
375 virtual bool FileExists(const std::string& fname) { | 375 virtual bool FileExists(const std::string& fname) { |
376 return ::file_util::PathExists(CreateFilePath(fname)); | 376 return ::file_util::PathExists(CreateFilePath(fname)); |
377 } | 377 } |
378 | 378 |
379 virtual Status GetChildren(const std::string& dir, | 379 virtual Status GetChildren(const std::string& dir, |
380 std::vector<std::string>* result) { | 380 std::vector<std::string>* result) { |
381 result->clear(); | 381 result->clear(); |
382 ::file_util::FileEnumerator iter( | 382 ::file_util::FileEnumerator iter( |
383 CreateFilePath(dir), false, ::file_util::FileEnumerator::FILES); | 383 CreateFilePath(dir), false, ::file_util::FileEnumerator::FILES); |
384 ::FilePath current = iter.Next(); | 384 base::FilePath current = iter.Next(); |
385 while (!current.empty()) { | 385 while (!current.empty()) { |
386 result->push_back(FilePathToString(current.BaseName())); | 386 result->push_back(FilePathToString(current.BaseName())); |
387 current = iter.Next(); | 387 current = iter.Next(); |
388 } | 388 } |
389 // TODO(jorlow): Unfortunately, the FileEnumerator swallows errors, so | 389 // TODO(jorlow): Unfortunately, the FileEnumerator swallows errors, so |
390 // we'll always return OK. Maybe manually check for error | 390 // we'll always return OK. Maybe manually check for error |
391 // conditions like the file not existing? | 391 // conditions like the file not existing? |
392 return Status::OK(); | 392 return Status::OK(); |
393 } | 393 } |
394 | 394 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 s = Status::IOError(fname, "Could not determine file size."); | 429 s = Status::IOError(fname, "Could not determine file size."); |
430 RecordErrorAt(kGetFileSize); | 430 RecordErrorAt(kGetFileSize); |
431 } else { | 431 } else { |
432 *size = static_cast<uint64_t>(signed_size); | 432 *size = static_cast<uint64_t>(signed_size); |
433 } | 433 } |
434 return s; | 434 return s; |
435 } | 435 } |
436 | 436 |
437 virtual Status RenameFile(const std::string& src, const std::string& dst) { | 437 virtual Status RenameFile(const std::string& src, const std::string& dst) { |
438 Status result; | 438 Status result; |
439 FilePath src_file_path = CreateFilePath(src); | 439 base::FilePath src_file_path = CreateFilePath(src); |
440 if (!::file_util::PathExists(src_file_path)) | 440 if (!::file_util::PathExists(src_file_path)) |
441 return result; | 441 return result; |
442 if (!::file_util::ReplaceFile(src_file_path, CreateFilePath(dst))) { | 442 if (!::file_util::ReplaceFile(src_file_path, CreateFilePath(dst))) { |
443 result = Status::IOError(src, "Could not rename file."); | 443 result = Status::IOError(src, "Could not rename file."); |
444 RecordErrorAt(kRenamefile); | 444 RecordErrorAt(kRenamefile); |
445 } else { | 445 } else { |
446 sync_parent(dst); | 446 sync_parent(dst); |
447 if (src != dst) | 447 if (src != dst) |
448 sync_parent(src); | 448 sync_parent(src); |
449 } | 449 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 protected: | 553 protected: |
554 void InitHistograms(const std::string& uma_title); | 554 void InitHistograms(const std::string& uma_title); |
555 | 555 |
556 private: | 556 private: |
557 // BGThread() is the body of the background thread | 557 // BGThread() is the body of the background thread |
558 void BGThread(); | 558 void BGThread(); |
559 static void BGThreadWrapper(void* arg) { | 559 static void BGThreadWrapper(void* arg) { |
560 reinterpret_cast<ChromiumEnv*>(arg)->BGThread(); | 560 reinterpret_cast<ChromiumEnv*>(arg)->BGThread(); |
561 } | 561 } |
562 | 562 |
563 FilePath test_directory_; | 563 base::FilePath test_directory_; |
564 | 564 |
565 size_t page_size_; | 565 size_t page_size_; |
566 ::base::Lock mu_; | 566 ::base::Lock mu_; |
567 ::base::ConditionVariable bgsignal_; | 567 ::base::ConditionVariable bgsignal_; |
568 bool started_bgthread_; | 568 bool started_bgthread_; |
569 | 569 |
570 // Entry per Schedule() call | 570 // Entry per Schedule() call |
571 struct BGItem { void* arg; void (*function)(void*); }; | 571 struct BGItem { void* arg; void (*function)(void*); }; |
572 typedef std::deque<BGItem> BGQueue; | 572 typedef std::deque<BGItem> BGQueue; |
573 BGQueue queue_; | 573 BGQueue queue_; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 | 678 |
679 Env* IDBEnv() { | 679 Env* IDBEnv() { |
680 return idb_env.Pointer(); | 680 return idb_env.Pointer(); |
681 } | 681 } |
682 | 682 |
683 Env* Env::Default() { | 683 Env* Env::Default() { |
684 return default_env.Pointer(); | 684 return default_env.Pointer(); |
685 } | 685 } |
686 | 686 |
687 } | 687 } |
OLD | NEW |