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

Side by Side Diff: third_party/leveldatabase/env_chromium.cc

Issue 26513005: Report errors from ChromiumEnv::GetChildren in Posix. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compile on windows Created 7 years, 2 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/leveldatabase/env_chromium.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 19 matching lines...) Expand all
30 #include "port/port.h" 30 #include "port/port.h"
31 #include "third_party/re2/re2/re2.h" 31 #include "third_party/re2/re2/re2.h"
32 #include "util/logging.h" 32 #include "util/logging.h"
33 33
34 #if defined(OS_WIN) 34 #if defined(OS_WIN)
35 #include <io.h> 35 #include <io.h>
36 #include "base/win/win_util.h" 36 #include "base/win/win_util.h"
37 #endif 37 #endif
38 38
39 #if defined(OS_POSIX) 39 #if defined(OS_POSIX)
40 #include <dirent.h>
40 #include <fcntl.h> 41 #include <fcntl.h>
41 #include <sys/resource.h> 42 #include <sys/resource.h>
42 #include <sys/time.h> 43 #include <sys/time.h>
43 #endif 44 #endif
44 45
45 using namespace leveldb; 46 using namespace leveldb;
46 47
47 namespace leveldb_env { 48 namespace leveldb_env {
48 49
49 namespace { 50 namespace {
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 case kLockFile: 309 case kLockFile:
309 return "LockFile"; 310 return "LockFile";
310 case kUnlockFile: 311 case kUnlockFile:
311 return "UnlockFile"; 312 return "UnlockFile";
312 case kGetTestDirectory: 313 case kGetTestDirectory:
313 return "GetTestDirectory"; 314 return "GetTestDirectory";
314 case kNewLogger: 315 case kNewLogger:
315 return "NewLogger"; 316 return "NewLogger";
316 case kSyncParent: 317 case kSyncParent:
317 return "SyncParent"; 318 return "SyncParent";
319 case kGetChildren:
320 return "GetChildren";
318 case kNumEntries: 321 case kNumEntries:
319 NOTREACHED(); 322 NOTREACHED();
320 return "kNumEntries"; 323 return "kNumEntries";
321 } 324 }
322 NOTREACHED(); 325 NOTREACHED();
323 return "Unknown"; 326 return "Unknown";
324 } 327 }
325 328
326 Status MakeIOError(Slice filename, 329 Status MakeIOError(Slice filename,
327 const char* message, 330 const char* message,
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 base::FilePath dir_filepath = base::FilePath::FromUTF8Unsafe(dir); 664 base::FilePath dir_filepath = base::FilePath::FromUTF8Unsafe(dir);
662 for (std::set<base::FilePath>::iterator it = backups_only.begin(); 665 for (std::set<base::FilePath>::iterator it = backups_only.begin();
663 it != backups_only.end(); 666 it != backups_only.end();
664 ++it) { 667 ++it) {
665 base::FilePath restored_table_name = 668 base::FilePath restored_table_name =
666 RestoreFromBackup(dir_filepath.Append(*it)); 669 RestoreFromBackup(dir_filepath.Append(*it));
667 result->push_back(FilePathToString(restored_table_name.BaseName())); 670 result->push_back(FilePathToString(restored_table_name.BaseName()));
668 } 671 }
669 } 672 }
670 673
671 Status ChromiumEnv::GetChildren(const std::string& dir, 674 #if defined(OS_WIN)
jsbell 2013/10/17 18:32:39 Anonymous namespace around this.
dgrogan 2013/10/17 20:22:36 Done.
672 std::vector<std::string>* result) { 675 base::PlatformFileError GetDirectoryEntries(
jsbell 2013/10/17 18:32:39 And mark this static. (Examples in base seem to do
dgrogan 2013/10/17 20:22:36 Done. Though I suspect the instances that of this
673 result->clear(); 676 const base::FilePath& dir_filepath,
674 // TODO(jorlow): Unfortunately, the FileEnumerator swallows errors, so 677 std::vector<base::FilePath>* result) {
675 // we'll always return OK. Maybe manually check for error 678 // TODO(dgrogan): Replace with FindFirstFile / FindNextFile.
676 // conditions like the file not existing? 679 base::FileEnumerator iter(dir_filepath, false, base::FileEnumerator::FILES);
jsbell 2013/10/17 18:32:39 This is filtering out directories whereas the new
dgrogan 2013/10/17 20:22:36 Added comment.
677 base::FileEnumerator iter(
678 CreateFilePath(dir), false, base::FileEnumerator::FILES);
679 base::FilePath current = iter.Next(); 680 base::FilePath current = iter.Next();
680 while (!current.empty()) { 681 while (!current.empty()) {
681 result->push_back(FilePathToString(current.BaseName())); 682 result->push_back(current.BaseName());
682 current = iter.Next(); 683 current = iter.Next();
683 } 684 }
685 return base::PLATFORM_FILE_OK;
686 }
687 #else
688 base::PlatformFileError GetDirectoryEntries(
jsbell 2013/10/17 18:32:39 Mark static too.
dgrogan 2013/10/17 20:22:36 Done.
689 const base::FilePath& dir_filepath,
690 std::vector<base::FilePath>* result) {
691 base::PlatformFileError return_value = base::PLATFORM_FILE_OK;
jsbell 2013/10/17 18:32:39 return_value is unused
dgrogan 2013/10/17 20:22:36 Done.
692 const std::string dir_string = dir_filepath.AsUTF8Unsafe();
jsbell 2013/10/17 18:32:39 Why not FilePathToString here?
dgrogan 2013/10/17 20:22:36 No good reason, switched to FilePathToString. They
jsbell 2013/10/17 20:47:42 On non-Mac,non-CrOS, AsUTF8Unsafe() actually does
693 result->clear();
694 DIR* dir = opendir(dir_string.c_str());
695 if (!dir)
696 return base::ErrnoToPlatformFileError(errno);
697 struct dirent dent_buf;
698 struct dirent* dent;
699 int readdir_return;
jsbell 2013/10/17 18:32:39 Name this readdir_result instead?
dgrogan 2013/10/17 20:22:36 Done.
700 while ((readdir_return = readdir_r(dir, &dent_buf, &dent)) == 0 && dent) {
jsbell 2013/10/17 18:32:39 Nit: No need for {}
dgrogan 2013/10/17 20:22:36 Done.
701 result->push_back(CreateFilePath(dent->d_name));
702 }
703 int saved_errno = errno;
704 closedir(dir);
705 if (readdir_return != 0)
706 return base::ErrnoToPlatformFileError(saved_errno);
707 return base::PLATFORM_FILE_OK;
708 }
709 #endif
710
711 Status ChromiumEnv::GetChildren(const std::string& dir_string,
712 std::vector<std::string>* result) {
713 std::vector<base::FilePath> entries;
714 base::PlatformFileError error =
715 GetDirectoryEntries(CreateFilePath(dir_string), &entries);
716 if (error != base::PLATFORM_FILE_OK) {
717 RecordOSError(kGetChildren, error);
718 return MakeIOError(
719 dir_string, "Could not open/read directory", kGetChildren, error);
720 }
721 for (std::vector<base::FilePath>::iterator it = entries.begin();
722 it != entries.end();
723 ++it) {
724 result->push_back(FilePathToString(*it));
725 }
726
684 if (make_backup_) 727 if (make_backup_)
685 RestoreIfNecessary(dir, result); 728 RestoreIfNecessary(dir_string, result);
686 return Status::OK(); 729 return Status::OK();
687 } 730 }
688 731
689 Status ChromiumEnv::DeleteFile(const std::string& fname) { 732 Status ChromiumEnv::DeleteFile(const std::string& fname) {
690 Status result; 733 Status result;
691 base::FilePath fname_filepath = CreateFilePath(fname); 734 base::FilePath fname_filepath = CreateFilePath(fname);
692 // TODO(jorlow): Should we assert this is a file? 735 // TODO(jorlow): Should we assert this is a file?
693 if (!::base::DeleteFile(fname_filepath, false)) { 736 if (!::base::DeleteFile(fname_filepath, false)) {
694 result = MakeIOError(fname, "Could not delete file.", kDeleteFile); 737 result = MakeIOError(fname, "Could not delete file.", kDeleteFile);
695 RecordErrorAt(kDeleteFile); 738 RecordErrorAt(kDeleteFile);
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 Env* IDBEnv() { 1114 Env* IDBEnv() {
1072 return leveldb_env::idb_env.Pointer(); 1115 return leveldb_env::idb_env.Pointer();
1073 } 1116 }
1074 1117
1075 Env* Env::Default() { 1118 Env* Env::Default() {
1076 return leveldb_env::default_env.Pointer(); 1119 return leveldb_env::default_env.Pointer();
1077 } 1120 }
1078 1121
1079 } // namespace leveldb 1122 } // namespace leveldb
1080 1123
OLDNEW
« no previous file with comments | « third_party/leveldatabase/env_chromium.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698