Index: tools/android/timemodified/timemodified.cc |
diff --git a/tools/android/timemodified/timemodified.cc b/tools/android/timemodified/timemodified.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e0aa33de584a5ac488fd0e2c3ea11922280b4975 |
--- /dev/null |
+++ b/tools/android/timemodified/timemodified.cc |
@@ -0,0 +1,63 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// Recursively prints file modified times for Android. This version handles |
+// files as well as directories. Its output is sorted by file path. |
+ |
+#include <iostream> |
+#include <string> |
+ |
+#include "base/file_util.h" |
+#include "base/files/file_enumerator.h" |
+#include "base/files/file_path.h" |
+#include "base/logging.h" |
+#include "base/platform_file.h" |
+#include "base/time/time.h" |
+ |
+namespace { |
+ |
+bool PrintFileAccessTime(const base::FilePath& path) { |
+ base::PlatformFileInfo file_info; |
+ if (!file_util::GetFileInfo(path, &file_info)) |
+ return false; |
+ std::cout << file_info.last_modified.ToTimeT() << " " |
+ << base::MakeAbsoluteFilePath(path).value() << std::endl; |
+} |
+ |
+// Prints the access times of all files contained in |files|. This handles |
+// directories by walking them recursively. Excludes .svn directories and files |
+// under them. |
+bool PrintAccessTimesRecursively(int num_files, const char** files) { |
+ // TODO(craigdh): Have an ignore list including .git directories. |
+ 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
|
+ for (const char** file = files; file != files + num_files; ++file) { |
+ base::FilePath file_path(*file); |
+ if (file_util::DirectoryExists(file_path)) { |
+ base::FileEnumerator file_enumerator( |
+ file_path, true /* recurse */, base::FileEnumerator::FILES); |
+ base::FilePath child, empty; |
+ while ((child = file_enumerator.Next()) != empty) { |
+ // If the path contains /.svn/, ignore it. |
+ if (child.value().find(svn_dir_component) == std::string::npos) { |
+ if (!PrintFileAccessTime(child)) |
+ return false; |
+ } |
+ } |
+ } else { |
+ if (!PrintFileAccessTime(file_path)) |
+ return false; |
+ } |
+ } |
+ return true; |
+} |
+ |
+} // namespace |
+ |
+int main(int argc, const char* argv[]) { |
+ if (argc < 2) { |
+ LOG(ERROR) << "Usage: timemodified <path/to/file_or_dir> ..."; |
+ return 1; |
+ } |
+ return PrintAccessTimesRecursively(argc - 1, argv + 1); |
+} |