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

Side by Side Diff: tools/android/md5sum/md5sum.cc

Issue 13165005: Move FileEnumerator to its own file, do some refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge, fixes Created 7 years, 7 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/zlib/google/zip_unittest.cc ('k') | tools/heapcheck/suppressions.txt » ('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) 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>
11 #include <string> 11 #include <string>
12 12
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/files/file_enumerator.h"
14 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
16 #include "base/md5.h" 17 #include "base/md5.h"
17 18
18 namespace { 19 namespace {
19 20
20 const int kBufferSize = 1024; 21 const int kBufferSize = 1024;
21 22
22 // Returns whether |path|'s MD5 was successfully written to |digest_string|. 23 // Returns whether |path|'s MD5 was successfully written to |digest_string|.
23 bool MD5Sum(const char* path, std::string* digest_string) { 24 bool MD5Sum(const char* path, std::string* digest_string) {
(...skipping 22 matching lines...) Expand all
46 } 47 }
47 48
48 // Returns the set of all files contained in |files|. This handles directories 49 // Returns the set of all files contained in |files|. This handles directories
49 // by walking them recursively. Excludes, .svn directories and file under them. 50 // by walking them recursively. Excludes, .svn directories and file under them.
50 std::set<std::string> MakeFileSet(const char** files) { 51 std::set<std::string> MakeFileSet(const char** files) {
51 const std::string svn_dir_component = FILE_PATH_LITERAL("/.svn/"); 52 const std::string svn_dir_component = FILE_PATH_LITERAL("/.svn/");
52 std::set<std::string> file_set; 53 std::set<std::string> file_set;
53 for (const char** file = files; *file; ++file) { 54 for (const char** file = files; *file; ++file) {
54 base::FilePath file_path(*file); 55 base::FilePath file_path(*file);
55 if (file_util::DirectoryExists(file_path)) { 56 if (file_util::DirectoryExists(file_path)) {
56 file_util::FileEnumerator file_enumerator( 57 base::FileEnumerator file_enumerator(
57 file_path, true /* recurse */, file_util::FileEnumerator::FILES); 58 file_path, true /* recurse */, base::FileEnumerator::FILES);
58 for (base::FilePath child, empty; 59 for (base::FilePath child, empty;
59 (child = file_enumerator.Next()) != empty; ) { 60 (child = file_enumerator.Next()) != empty; ) {
60 // If the path contains /.svn/, ignore it. 61 // If the path contains /.svn/, ignore it.
61 if (child.value().find(svn_dir_component) == std::string::npos) { 62 if (child.value().find(svn_dir_component) == std::string::npos) {
62 child = base::MakeAbsoluteFilePath(child); 63 child = base::MakeAbsoluteFilePath(child);
63 file_set.insert(child.value()); 64 file_set.insert(child.value());
64 } 65 }
65 } 66 }
66 } else { 67 } else {
67 file_set.insert(*file); 68 file_set.insert(*file);
(...skipping 15 matching lines...) Expand all
83 for (std::set<std::string>::const_iterator it = files.begin(); 84 for (std::set<std::string>::const_iterator it = files.begin();
84 it != files.end(); ++it) { 85 it != files.end(); ++it) {
85 if (!MD5Sum(it->c_str(), &digest)) 86 if (!MD5Sum(it->c_str(), &digest))
86 failed = true; 87 failed = true;
87 base::FilePath file_path(*it); 88 base::FilePath file_path(*it);
88 std::cout << digest << " " 89 std::cout << digest << " "
89 << base::MakeAbsoluteFilePath(file_path).value() << std::endl; 90 << base::MakeAbsoluteFilePath(file_path).value() << std::endl;
90 } 91 }
91 return failed; 92 return failed;
92 } 93 }
OLDNEW
« no previous file with comments | « third_party/zlib/google/zip_unittest.cc ('k') | tools/heapcheck/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698