Make log_cat accept folders

Change-Id: I37b2ab9fbbd7506cd8e76621b916d2bb136446e6
diff --git a/aos/events/logging/log_cat.cc b/aos/events/logging/log_cat.cc
index 0afdc03..79ea1e3 100644
--- a/aos/events/logging/log_cat.cc
+++ b/aos/events/logging/log_cat.cc
@@ -5,6 +5,7 @@
 #include <string>
 #include <string_view>
 #include <vector>
+#include "dirent.h"
 
 #include "aos/configuration.h"
 #include "aos/events/logging/logger.h"
@@ -58,6 +59,31 @@
   }
 }
 
+void SearchDirectory(std::vector<std::string> *files, std::string filename) {
+  DIR *directory = opendir(filename.c_str());
+
+  if (directory == nullptr) {
+    // its not a directory
+    // it could be a file
+    // or it could not exist
+    files->emplace_back(filename);
+    return;
+  }
+
+  struct dirent *directory_entry;
+  while ((directory_entry = readdir(directory)) != nullptr) {
+    std::string next_filename = directory_entry->d_name;
+    if (next_filename == "." || next_filename == "..") {
+      continue;
+    }
+
+    std::string path = filename + "/" + next_filename;
+    SearchDirectory(files, path);
+  }
+
+  closedir(directory);
+}
+
 int main(int argc, char **argv) {
   gflags::SetUsageMessage(
       "Usage:\n"
@@ -124,7 +150,7 @@
 
   std::vector<std::string> unsorted_logfiles;
   for (int i = 1; i < argc; ++i) {
-    unsorted_logfiles.emplace_back(std::string(argv[i]));
+    SearchDirectory(&unsorted_logfiles, argv[i]);
   }
 
   const std::vector<aos::logger::LogFile> logfiles =