| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Md5sum implementation for Android. This version handles files as well as | 5 // Md5sum implementation for Android. This version handles files as well as |
| 6 // directories. Its output is sorted by file path. | 6 // directories. Its output is sorted by file path. |
| 7 | 7 |
| 8 #include <fstream> | 8 #include <fstream> |
| 9 #include <iostream> | 9 #include <iostream> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 std::set<std::string> file_set; | 49 std::set<std::string> file_set; |
| 50 for (const char** file = files; *file; ++file) { | 50 for (const char** file = files; *file; ++file) { |
| 51 base::FilePath file_path(*file); | 51 base::FilePath file_path(*file); |
| 52 if (base::DirectoryExists(file_path)) { | 52 if (base::DirectoryExists(file_path)) { |
| 53 base::FileEnumerator file_enumerator( | 53 base::FileEnumerator file_enumerator( |
| 54 file_path, true /* recurse */, base::FileEnumerator::FILES); | 54 file_path, true /* recurse */, base::FileEnumerator::FILES); |
| 55 for (base::FilePath child, empty; | 55 for (base::FilePath child, empty; |
| 56 (child = file_enumerator.Next()) != empty; ) { | 56 (child = file_enumerator.Next()) != empty; ) { |
| 57 // If the path contains /.svn/, ignore it. | 57 // If the path contains /.svn/, ignore it. |
| 58 if (child.value().find(svn_dir_component) == std::string::npos) { | 58 if (child.value().find(svn_dir_component) == std::string::npos) { |
| 59 child = base::MakeAbsoluteFilePath(child); | |
| 60 file_set.insert(child.value()); | 59 file_set.insert(child.value()); |
| 61 } | 60 } |
| 62 } | 61 } |
| 63 } else { | 62 } else { |
| 64 file_set.insert(*file); | 63 file_set.insert(*file); |
| 65 } | 64 } |
| 66 } | 65 } |
| 67 return file_set; | 66 return file_set; |
| 68 } | 67 } |
| 69 | 68 |
| 70 } // namespace | 69 } // namespace |
| 71 | 70 |
| 72 int main(int argc, const char* argv[]) { | 71 int main(int argc, const char* argv[]) { |
| 73 if (argc < 2) { | 72 if (argc < 2) { |
| 74 LOG(ERROR) << "Usage: md5sum <path/to/file_or_dir>..."; | 73 LOG(ERROR) << "Usage: md5sum <path/to/file_or_dir>..."; |
| 75 return 1; | 74 return 1; |
| 76 } | 75 } |
| 77 const std::set<std::string> files = MakeFileSet(argv + 1); | 76 const std::set<std::string> files = MakeFileSet(argv + 1); |
| 78 bool failed = false; | 77 bool failed = false; |
| 79 std::string digest; | 78 std::string digest; |
| 80 for (std::set<std::string>::const_iterator it = files.begin(); | 79 for (std::set<std::string>::const_iterator it = files.begin(); |
| 81 it != files.end(); ++it) { | 80 it != files.end(); ++it) { |
| 82 if (!MD5Sum(it->c_str(), &digest)) { | 81 if (!MD5Sum(it->c_str(), &digest)) { |
| 83 failed = true; | 82 failed = true; |
| 84 } else { | 83 } else { |
| 85 base::FilePath file_path(*it); | 84 std::cout << digest << " " << *it << std::endl; |
| 86 std::cout << digest << " " | |
| 87 << base::MakeAbsoluteFilePath(file_path).value() << std::endl; | |
| 88 } | 85 } |
| 89 } | 86 } |
| 90 return failed; | 87 return failed; |
| 91 } | 88 } |
| OLD | NEW |