OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Recursively prints file modified times for Android. This version handles | |
6 // files as well as 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/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 // TODO(craigdh): Have an ignore list including .git directories. | |
33 const std::string svn_dir_component = FILE_PATH_LITERAL("/.svn/"); | |
bulach
2013/07/15 18:35:20
how about .git?
craigdh
2013/07/15 19:06:50
It's not an issue right now because .git is only i
frankf
2013/07/15 19:16:57
Actually, this won't work if you're just pushing a
| |
34 for (const char** file = files; file != files + num_files; ++file) { | |
35 base::FilePath file_path(*file); | |
36 if (file_util::DirectoryExists(file_path)) { | |
37 base::FileEnumerator file_enumerator( | |
38 file_path, true /* recurse */, base::FileEnumerator::FILES); | |
39 base::FilePath child, empty; | |
40 while ((child = file_enumerator.Next()) != empty) { | |
41 // If the path contains /.svn/, ignore it. | |
42 if (child.value().find(svn_dir_component) == std::string::npos) { | |
43 if (!PrintFileAccessTime(child)) | |
44 return false; | |
45 } | |
46 } | |
47 } else { | |
48 if (!PrintFileAccessTime(file_path)) | |
49 return false; | |
50 } | |
51 } | |
52 return true; | |
53 } | |
54 | |
55 } // namespace | |
56 | |
57 int main(int argc, const char* argv[]) { | |
58 if (argc < 2) { | |
59 LOG(ERROR) << "Usage: timemodified <path/to/file_or_dir> ..."; | |
60 return 1; | |
61 } | |
62 return PrintAccessTimesRecursively(argc - 1, argv + 1); | |
63 } | |
OLD | NEW |