| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <fstream> | 10 #include <fstream> |
| 11 #include <iostream> | 11 #include <iostream> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/files/file_enumerator.h" | 15 #include "base/files/file_enumerator.h" |
| 16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/md5.h" | 19 #include "base/md5.h" |
| 20 #include "base/memory/scoped_ptr.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // Returns whether |path|'s MD5 was successfully written to |digest_string|. | 24 // Returns whether |path|'s MD5 was successfully written to |digest_string|. |
| 24 bool MD5Sum(const char* path, std::string* digest_string) { | 25 bool MD5Sum(const char* path, std::string* digest_string) { |
| 25 base::ScopedFILE file(fopen(path, "rb")); | 26 base::ScopedFILE file(fopen(path, "rb")); |
| 26 if (!file) { | 27 if (!file) { |
| 27 LOG(ERROR) << "Could not open file " << path; | 28 LOG(ERROR) << "Could not open file " << path; |
| 28 return false; | 29 return false; |
| 29 } | 30 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 for (std::set<std::string>::const_iterator it = files.begin(); | 82 for (std::set<std::string>::const_iterator it = files.begin(); |
| 82 it != files.end(); ++it) { | 83 it != files.end(); ++it) { |
| 83 if (!MD5Sum(it->c_str(), &digest)) { | 84 if (!MD5Sum(it->c_str(), &digest)) { |
| 84 failed = true; | 85 failed = true; |
| 85 } else { | 86 } else { |
| 86 std::cout << digest << " " << *it << std::endl; | 87 std::cout << digest << " " << *it << std::endl; |
| 87 } | 88 } |
| 88 } | 89 } |
| 89 return failed; | 90 return failed; |
| 90 } | 91 } |
| OLD | NEW |