| 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 <errno.h> | 5 #include <errno.h> |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 namespace { | 195 namespace { |
| 196 | 196 |
| 197 class Thread; | 197 class Thread; |
| 198 | 198 |
| 199 static const base::FilePath::CharType kLevelDBTestDirectoryPrefix[] | 199 static const base::FilePath::CharType kLevelDBTestDirectoryPrefix[] |
| 200 = FILE_PATH_LITERAL("leveldb-test-"); | 200 = FILE_PATH_LITERAL("leveldb-test-"); |
| 201 | 201 |
| 202 const char* PlatformFileErrorString(const ::base::PlatformFileError& error) { | 202 const char* PlatformFileErrorString(const ::base::PlatformFileError& error) { |
| 203 switch (error) { | 203 switch (error) { |
| 204 case ::base::PLATFORM_FILE_ERROR_FAILED: | 204 case ::base::PLATFORM_FILE_ERROR_FAILED: |
| 205 return "Opening file failed."; | 205 return "No further details."; |
| 206 case ::base::PLATFORM_FILE_ERROR_IN_USE: | 206 case ::base::PLATFORM_FILE_ERROR_IN_USE: |
| 207 return "File currently in use."; | 207 return "File currently in use."; |
| 208 case ::base::PLATFORM_FILE_ERROR_EXISTS: | 208 case ::base::PLATFORM_FILE_ERROR_EXISTS: |
| 209 return "File already exists."; | 209 return "File already exists."; |
| 210 case ::base::PLATFORM_FILE_ERROR_NOT_FOUND: | 210 case ::base::PLATFORM_FILE_ERROR_NOT_FOUND: |
| 211 return "File not found."; | 211 return "File not found."; |
| 212 case ::base::PLATFORM_FILE_ERROR_ACCESS_DENIED: | 212 case ::base::PLATFORM_FILE_ERROR_ACCESS_DENIED: |
| 213 return "Access denied."; | 213 return "Access denied."; |
| 214 case ::base::PLATFORM_FILE_ERROR_TOO_MANY_OPENED: | 214 case ::base::PLATFORM_FILE_ERROR_TOO_MANY_OPENED: |
| 215 return "Too many files open."; | 215 return "Too many files open."; |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 }; | 542 }; |
| 543 | 543 |
| 544 virtual Status RenameFile(const std::string& src, const std::string& dst) { | 544 virtual Status RenameFile(const std::string& src, const std::string& dst) { |
| 545 Status result; | 545 Status result; |
| 546 base::FilePath src_file_path = CreateFilePath(src); | 546 base::FilePath src_file_path = CreateFilePath(src); |
| 547 if (!::file_util::PathExists(src_file_path)) | 547 if (!::file_util::PathExists(src_file_path)) |
| 548 return result; | 548 return result; |
| 549 base::FilePath destination = CreateFilePath(dst); | 549 base::FilePath destination = CreateFilePath(dst); |
| 550 | 550 |
| 551 Retrier retrier(GetRetryTimeHistogram(kRenameFile), kMaxRenameTimeMillis); | 551 Retrier retrier(GetRetryTimeHistogram(kRenameFile), kMaxRenameTimeMillis); |
| 552 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 552 do { | 553 do { |
| 553 if (::file_util::ReplaceFile(src_file_path, destination)) { | 554 if (::file_util::ReplaceFileAndGetError( |
| 555 src_file_path, destination, &error)) { |
| 554 sync_parent(dst); | 556 sync_parent(dst); |
| 555 if (src != dst) | 557 if (src != dst) |
| 556 sync_parent(src); | 558 sync_parent(src); |
| 557 return result; | 559 return result; |
| 558 } | 560 } |
| 559 } while (retrier.ShouldKeepTrying()); | 561 } while (retrier.ShouldKeepTrying()); |
| 560 | 562 |
| 561 RecordErrorAt(kRenameFile); | 563 DCHECK(error != base::PLATFORM_FILE_OK); |
| 562 return Status::IOError(src, "Could not rename file."); | 564 RecordOSError(kRenameFile, error); |
| 565 char buf[100]; |
| 566 snprintf(buf, sizeof(buf), "Could not rename file: %s", |
| 567 PlatformFileErrorString(error)); |
| 568 return Status::IOError(src, buf); |
| 563 } | 569 } |
| 564 | 570 |
| 565 virtual Status LockFile(const std::string& fname, FileLock** lock) { | 571 virtual Status LockFile(const std::string& fname, FileLock** lock) { |
| 566 *lock = NULL; | 572 *lock = NULL; |
| 567 Status result; | 573 Status result; |
| 568 int flags = ::base::PLATFORM_FILE_OPEN_ALWAYS | | 574 int flags = ::base::PLATFORM_FILE_OPEN_ALWAYS | |
| 569 ::base::PLATFORM_FILE_READ | | 575 ::base::PLATFORM_FILE_READ | |
| 570 ::base::PLATFORM_FILE_WRITE | | 576 ::base::PLATFORM_FILE_WRITE | |
| 571 ::base::PLATFORM_FILE_EXCLUSIVE_READ | | 577 ::base::PLATFORM_FILE_EXCLUSIVE_READ | |
| 572 ::base::PLATFORM_FILE_EXCLUSIVE_WRITE; | 578 ::base::PLATFORM_FILE_EXCLUSIVE_WRITE; |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 | 831 |
| 826 Env* IDBEnv() { | 832 Env* IDBEnv() { |
| 827 return idb_env.Pointer(); | 833 return idb_env.Pointer(); |
| 828 } | 834 } |
| 829 | 835 |
| 830 Env* Env::Default() { | 836 Env* Env::Default() { |
| 831 return default_env.Pointer(); | 837 return default_env.Pointer(); |
| 832 } | 838 } |
| 833 | 839 |
| 834 } | 840 } |
| OLD | NEW |