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 "third_party/leveldatabase/env_chromium.h" | 5 #include "third_party/leveldatabase/env_chromium.h" |
6 | 6 |
7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
8 #include <dirent.h> | 8 #include <dirent.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #endif | 10 #endif |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 | 401 |
402 Status MakeIOError(Slice filename, | 402 Status MakeIOError(Slice filename, |
403 const std::string& message, | 403 const std::string& message, |
404 MethodID method) { | 404 MethodID method) { |
405 char buf[512]; | 405 char buf[512]; |
406 snprintf(buf, sizeof(buf), "%s (ChromeMethodOnly: %d::%s)", message.c_str(), | 406 snprintf(buf, sizeof(buf), "%s (ChromeMethodOnly: %d::%s)", message.c_str(), |
407 method, MethodIDToString(method)); | 407 method, MethodIDToString(method)); |
408 return Status::IOError(filename, buf); | 408 return Status::IOError(filename, buf); |
409 } | 409 } |
410 | 410 |
411 ErrorParsingResult ParseMethodAndError(const char* string, | 411 ErrorParsingResult ParseMethodAndError(const leveldb::Status& status, |
412 MethodID* method_param, | 412 MethodID* method_param, |
413 int* error) { | 413 int* error) { |
414 std::string str = status.ToString(); | |
dgrogan
2014/12/15 21:55:30
Change the variable name so status_string, or some
cmumford
2014/12/15 22:26:11
I renamed it to "status_string". I couldn't make i
dgrogan
2014/12/15 22:31:48
I think you understood it but now I'm confused. Wo
| |
414 int method; | 415 int method; |
415 if (RE2::PartialMatch(string, "ChromeMethodOnly: (\\d+)", &method)) { | 416 if (RE2::PartialMatch(str.c_str(), "ChromeMethodOnly: (\\d+)", &method)) { |
416 *method_param = static_cast<MethodID>(method); | 417 *method_param = static_cast<MethodID>(method); |
417 return METHOD_ONLY; | 418 return METHOD_ONLY; |
418 } | 419 } |
419 if (RE2::PartialMatch( | 420 if (RE2::PartialMatch(str.c_str(), "ChromeMethodPFE: (\\d+)::.*::(\\d+)", |
420 string, "ChromeMethodPFE: (\\d+)::.*::(\\d+)", &method, error)) { | 421 &method, error)) { |
421 *error = -*error; | 422 *error = -*error; |
422 *method_param = static_cast<MethodID>(method); | 423 *method_param = static_cast<MethodID>(method); |
423 return METHOD_AND_PFE; | 424 return METHOD_AND_PFE; |
424 } | 425 } |
425 if (RE2::PartialMatch( | 426 if (RE2::PartialMatch(str.c_str(), "ChromeMethodErrno: (\\d+)::.*::(\\d+)", |
426 string, "ChromeMethodErrno: (\\d+)::.*::(\\d+)", &method, error)) { | 427 &method, error)) { |
427 *method_param = static_cast<MethodID>(method); | 428 *method_param = static_cast<MethodID>(method); |
428 return METHOD_AND_ERRNO; | 429 return METHOD_AND_ERRNO; |
429 } | 430 } |
430 return NONE; | 431 return NONE; |
431 } | 432 } |
432 | 433 |
433 // Keep in sync with LevelDBCorruptionTypes in histograms.xml. Also, don't | 434 // Keep in sync with LevelDBCorruptionTypes in histograms.xml. Also, don't |
434 // change the order because indices into this array have been recorded in uma | 435 // change the order because indices into this array have been recorded in uma |
435 // histograms. | 436 // histograms. |
436 const char* patterns[] = { | 437 const char* patterns[] = { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 if (code == 0) | 496 if (code == 0) |
496 return "Unknown corruption"; | 497 return "Unknown corruption"; |
497 return patterns[code - 1]; | 498 return patterns[code - 1]; |
498 } | 499 } |
499 | 500 |
500 bool IndicatesDiskFull(const leveldb::Status& status) { | 501 bool IndicatesDiskFull(const leveldb::Status& status) { |
501 if (status.ok()) | 502 if (status.ok()) |
502 return false; | 503 return false; |
503 leveldb_env::MethodID method; | 504 leveldb_env::MethodID method; |
504 int error = -1; | 505 int error = -1; |
505 leveldb_env::ErrorParsingResult result = leveldb_env::ParseMethodAndError( | 506 leveldb_env::ErrorParsingResult result = |
506 status.ToString().c_str(), &method, &error); | 507 leveldb_env::ParseMethodAndError(status, &method, &error); |
507 return (result == leveldb_env::METHOD_AND_PFE && | 508 return (result == leveldb_env::METHOD_AND_PFE && |
508 static_cast<base::File::Error>(error) == | 509 static_cast<base::File::Error>(error) == |
509 base::File::FILE_ERROR_NO_SPACE) || | 510 base::File::FILE_ERROR_NO_SPACE) || |
510 (result == leveldb_env::METHOD_AND_ERRNO && error == ENOSPC); | 511 (result == leveldb_env::METHOD_AND_ERRNO && error == ENOSPC); |
511 } | 512 } |
512 | 513 |
513 bool IsIOError(const leveldb::Status& status) { | 514 bool IsIOError(const leveldb::Status& status) { |
514 leveldb_env::MethodID method; | 515 leveldb_env::MethodID method; |
515 int error = -1; | 516 int error = -1; |
516 leveldb_env::ErrorParsingResult result = leveldb_env::ParseMethodAndError( | 517 leveldb_env::ErrorParsingResult result = |
517 status.ToString().c_str(), &method, &error); | 518 leveldb_env::ParseMethodAndError(status, &method, &error); |
518 return result != leveldb_env::NONE; | 519 return result != leveldb_env::NONE; |
519 } | 520 } |
520 | 521 |
521 bool ChromiumEnv::MakeBackup(const std::string& fname) { | 522 bool ChromiumEnv::MakeBackup(const std::string& fname) { |
522 FilePath original_table_name = FilePath::FromUTF8Unsafe(fname); | 523 FilePath original_table_name = FilePath::FromUTF8Unsafe(fname); |
523 FilePath backup_table_name = | 524 FilePath backup_table_name = |
524 original_table_name.ReplaceExtension(backup_table_extension); | 525 original_table_name.ReplaceExtension(backup_table_extension); |
525 return base::CopyFile(original_table_name, backup_table_name); | 526 return base::CopyFile(original_table_name, backup_table_name); |
526 } | 527 } |
527 | 528 |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1086 | 1087 |
1087 Env* IDBEnv() { | 1088 Env* IDBEnv() { |
1088 return leveldb_env::idb_env.Pointer(); | 1089 return leveldb_env::idb_env.Pointer(); |
1089 } | 1090 } |
1090 | 1091 |
1091 Env* Env::Default() { | 1092 Env* Env::Default() { |
1092 return leveldb_env::default_env.Pointer(); | 1093 return leveldb_env::default_env.Pointer(); |
1093 } | 1094 } |
1094 | 1095 |
1095 } // namespace leveldb | 1096 } // namespace leveldb |
OLD | NEW |