OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium 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. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <fnmatch.h> | 10 #include <fnmatch.h> |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 return false; | 638 return false; |
639 | 639 |
640 #if !defined(OS_LINUX) && !defined(OS_MACOSX) | 640 #if !defined(OS_LINUX) && !defined(OS_MACOSX) |
641 #error Depending on the definition of struct dirent, additional space for \ | 641 #error Depending on the definition of struct dirent, additional space for \ |
642 pathname may be needed | 642 pathname may be needed |
643 #endif | 643 #endif |
644 struct dirent dent_buf; | 644 struct dirent dent_buf; |
645 struct dirent* dent; | 645 struct dirent* dent; |
646 while (readdir_r(dir, &dent_buf, &dent) == 0 && dent) { | 646 while (readdir_r(dir, &dent_buf, &dent) == 0 && dent) { |
647 DirectoryEntryInfo info; | 647 DirectoryEntryInfo info; |
648 FilePath full_name; | 648 info.filename = FilePath(dent->d_name); |
649 int stat_value; | |
650 | 649 |
651 info.filename = FilePath(dent->d_name); | 650 FilePath full_name = source.Append(dent->d_name); |
652 full_name = source.Append(dent->d_name); | 651 int ret; |
653 if (show_links) | 652 if (show_links) |
654 stat_value = lstat(full_name.value().c_str(), &info.stat); | 653 ret = lstat(full_name.value().c_str(), &info.stat); |
655 else | 654 else |
656 stat_value = stat(full_name.value().c_str(), &info.stat); | 655 ret = stat(full_name.value().c_str(), &info.stat); |
657 if (stat_value < 0) { | 656 if (ret < 0) { |
658 LOG(ERROR) << "Couldn't stat file: " << | 657 // Print the stat() error message unless it was ENOENT and we're |
659 source.Append(dent->d_name).value().c_str() << " errno = " << errno; | 658 // following symlinks. |
| 659 if (!(ret == ENOENT && !show_links)) { |
| 660 LOG(ERROR) << "Couldn't stat " |
| 661 << source.Append(dent->d_name).value() << ": " |
| 662 << strerror(errno); |
| 663 } |
660 memset(&info.stat, 0, sizeof(info.stat)); | 664 memset(&info.stat, 0, sizeof(info.stat)); |
661 } | 665 } |
662 entries->push_back(info); | 666 entries->push_back(info); |
663 } | 667 } |
664 | 668 |
665 closedir(dir); | 669 closedir(dir); |
666 return true; | 670 return true; |
667 } | 671 } |
668 | 672 |
669 bool FileEnumerator::CompareFiles(const DirectoryEntryInfo& a, | 673 bool FileEnumerator::CompareFiles(const DirectoryEntryInfo& a, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 munmap(data_, length_); | 724 munmap(data_, length_); |
721 if (file_ != -1) | 725 if (file_ != -1) |
722 close(file_); | 726 close(file_); |
723 | 727 |
724 data_ = NULL; | 728 data_ = NULL; |
725 length_ = 0; | 729 length_ = 0; |
726 file_ = -1; | 730 file_ = -1; |
727 } | 731 } |
728 | 732 |
729 } // namespace file_util | 733 } // namespace file_util |
OLD | NEW |