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 19 matching lines...) Expand all Loading... | |
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 Loading... | |
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 Loading... | |
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 namespace { |
672 std::vector<std::string>* result) { | 675 #if defined(OS_WIN) |
673 result->clear(); | 676 static base::PlatformFileError GetDirectoryEntries( |
674 // TODO(jorlow): Unfortunately, the FileEnumerator swallows errors, so | 677 const base::FilePath& dir_filepath, |
675 // we'll always return OK. Maybe manually check for error | 678 std::vector<base::FilePath>* result) { |
676 // conditions like the file not existing? | 679 // TODO(dgrogan): Replace with FindFirstFile / FindNextFile. Note that until |
677 base::FileEnumerator iter( | 680 // that happens this is filtering out directories whereas the Posix version |
678 CreateFilePath(dir), false, base::FileEnumerator::FILES); | 681 // below is not. There shouldn't be any directories so this shouldn't be an |
682 // issue. | |
683 base::FileEnumerator iter(dir_filepath, false, base::FileEnumerator::FILES); | |
679 base::FilePath current = iter.Next(); | 684 base::FilePath current = iter.Next(); |
680 while (!current.empty()) { | 685 while (!current.empty()) { |
681 result->push_back(FilePathToString(current.BaseName())); | 686 result->push_back(current.BaseName()); |
682 current = iter.Next(); | 687 current = iter.Next(); |
683 } | 688 } |
689 return base::PLATFORM_FILE_OK; | |
690 } | |
691 #else | |
692 static base::PlatformFileError GetDirectoryEntries( | |
693 const base::FilePath& dir_filepath, | |
694 std::vector<base::FilePath>* result) { | |
695 const std::string dir_string = FilePathToString(dir_filepath); | |
696 result->clear(); | |
697 DIR* dir = opendir(dir_string.c_str()); | |
698 if (!dir) | |
699 return base::ErrnoToPlatformFileError(errno); | |
700 struct dirent dent_buf; | |
701 struct dirent* dent; | |
702 int readdir_result; | |
703 while ((readdir_result = readdir_r(dir, &dent_buf, &dent)) == 0 && dent) | |
704 result->push_back(CreateFilePath(dent->d_name)); | |
705 int saved_errno = errno; | |
706 closedir(dir); | |
707 if (readdir_result != 0) | |
708 return base::ErrnoToPlatformFileError(saved_errno); | |
709 return base::PLATFORM_FILE_OK; | |
710 } | |
711 #endif | |
712 } | |
713 | |
714 Status ChromiumEnv::GetChildren(const std::string& dir_string, | |
715 std::vector<std::string>* result) { | |
716 std::vector<base::FilePath> entries; | |
717 base::PlatformFileError error = | |
718 GetDirectoryEntries(CreateFilePath(dir_string), &entries); | |
719 if (error != base::PLATFORM_FILE_OK) { | |
720 RecordOSError(kGetChildren, error); | |
Nico
2013/10/18 02:28:30
Does this mean that PlatformFileError needs to hav
dgrogan
2013/10/18 20:52:59
That ship may have already sailed. It's not just u
| |
721 return MakeIOError( | |
722 dir_string, "Could not open/read directory", kGetChildren, error); | |
723 } | |
724 for (std::vector<base::FilePath>::iterator it = entries.begin(); | |
725 it != entries.end(); | |
726 ++it) { | |
727 result->push_back(FilePathToString(*it)); | |
728 } | |
729 | |
684 if (make_backup_) | 730 if (make_backup_) |
685 RestoreIfNecessary(dir, result); | 731 RestoreIfNecessary(dir_string, result); |
686 return Status::OK(); | 732 return Status::OK(); |
687 } | 733 } |
688 | 734 |
689 Status ChromiumEnv::DeleteFile(const std::string& fname) { | 735 Status ChromiumEnv::DeleteFile(const std::string& fname) { |
690 Status result; | 736 Status result; |
691 base::FilePath fname_filepath = CreateFilePath(fname); | 737 base::FilePath fname_filepath = CreateFilePath(fname); |
692 // TODO(jorlow): Should we assert this is a file? | 738 // TODO(jorlow): Should we assert this is a file? |
693 if (!::base::DeleteFile(fname_filepath, false)) { | 739 if (!::base::DeleteFile(fname_filepath, false)) { |
694 result = MakeIOError(fname, "Could not delete file.", kDeleteFile); | 740 result = MakeIOError(fname, "Could not delete file.", kDeleteFile); |
695 RecordErrorAt(kDeleteFile); | 741 RecordErrorAt(kDeleteFile); |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1071 Env* IDBEnv() { | 1117 Env* IDBEnv() { |
1072 return leveldb_env::idb_env.Pointer(); | 1118 return leveldb_env::idb_env.Pointer(); |
1073 } | 1119 } |
1074 | 1120 |
1075 Env* Env::Default() { | 1121 Env* Env::Default() { |
1076 return leveldb_env::default_env.Pointer(); | 1122 return leveldb_env::default_env.Pointer(); |
1077 } | 1123 } |
1078 | 1124 |
1079 } // namespace leveldb | 1125 } // namespace leveldb |
1080 | 1126 |
OLD | NEW |