OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
frankf
2013/06/20 22:52:38
13
craigdh
2013/07/02 17:26:12
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Md5sum implementation for Android. This version handles files as well as | |
frankf
2013/06/20 22:52:38
Update doc
craigdh
2013/07/02 17:26:12
Done.
| |
6 // directories. Its output is sorted by file path. | |
7 | |
8 #include <iostream> | |
9 #include <string> | |
10 | |
11 #include "base/file_util.h" | |
12 #include "base/files/file_enumerator.h" | |
13 #include "base/files/file_path.h" | |
14 #include "base/logging.h" | |
15 #include "base/platform_file.h" | |
16 #include "base/time.h" | |
17 | |
18 namespace { | |
19 | |
20 bool PrintFileAccessTime(const base::FilePath& path) { | |
21 base::PlatformFileInfo file_info; | |
22 if (!file_util::GetFileInfo(path, &file_info)) | |
23 return false; | |
24 std::cout << file_info.last_modified.ToTimeT() << " " | |
25 << base::MakeAbsoluteFilePath(path).value() << std::endl; | |
26 } | |
27 | |
28 // Prints the access times of all files contained in |files|. This handles | |
29 // directories by walking them recursively. Excludes .svn directories and files | |
30 // under them. | |
31 bool PrintAccessTimesRecursively(int num_files, const char** files) { | |
32 const std::string svn_dir_component = FILE_PATH_LITERAL("/.svn/"); | |
33 for (const char** file = files; file != files + num_files; ++file) { | |
34 base::FilePath file_path(*file); | |
35 if (file_util::DirectoryExists(file_path)) { | |
36 base::FileEnumerator file_enumerator( | |
37 file_path, true /* recurse */, base::FileEnumerator::FILES); | |
38 for (base::FilePath child, empty; | |
39 (child = file_enumerator.Next()) != empty; ) { | |
frankf
2013/06/20 22:52:38
I think a while loop here is more readable.
craigdh
2013/07/02 17:26:12
Done.
| |
40 // If the path contains /.svn/, ignore it. | |
41 if (child.value().find(svn_dir_component) == std::string::npos) { | |
42 if (!PrintFileAccessTime(child)) | |
frankf
2013/06/20 22:52:38
Can we log the failure cases for debugging.
craigdh
2013/07/02 17:26:12
Done.
| |
43 return false; | |
44 } | |
45 } | |
46 } else { | |
47 if (!PrintFileAccessTime(file_path)) | |
48 return false; | |
49 } | |
50 } | |
51 return true; | |
52 } | |
53 | |
54 } // namespace | |
55 | |
56 int main(int argc, const char* argv[]) { | |
57 if (argc < 2) { | |
58 LOG(ERROR) << "Usage: timemodified <path/to/file_or_dir> ..."; | |
59 return 1; | |
60 } | |
61 return PrintAccessTimesRecursively(argc - 1, argv + 1); | |
62 } | |
OLD | NEW |