whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [whimsy] branch master updated: Choose latest file regardless of Dir behaviour
Date Mon, 05 Oct 2020 09:52:43 GMT
This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 57c097b  Choose latest file regardless of  Dir behaviour
57c097b is described below

commit 57c097b28674ec7bf18cf8545e6c87cef414b944
Author: Sebb <sebb@apache.org>
AuthorDate: Mon Oct 5 10:52:34 2020 +0100

    Choose latest file regardless of  Dir behaviour
---
 lib/whimsy/logparser.rb | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/whimsy/logparser.rb b/lib/whimsy/logparser.rb
index 852ae40..1203c0e 100755
--- a/lib/whimsy/logparser.rb
+++ b/lib/whimsy/logparser.rb
@@ -207,14 +207,21 @@ module LogParser
     return logs
   end
 
+  # get the most recently modified matching file
+  # Note that Dir may return files in any order
+  def latest(path)
+    Dir.glob(path).max_by {|f| File.mtime(f) }
+  end
+
   # Get a list of all current|available error logs interesting entries
   # @param current - only scan current day? or scan all week's logs
   # @param d directory to scan for *error.log*
   # @return hash of arrays of interesting entries
   def get_errors(current, dir: ERROR_LOG_DIR)
     if current
-      logs = LogParser.parse_whimsy_error(File.join(dir, 'whimsy_error.log'))
-      error_log = Dir[File.join(dir, 'error?log')].first
+      whimsy_log = latest(File.join(dir, 'whimsy_error.log*'))
+      logs = LogParser.parse_whimsy_error(whimsy_log)
+      error_log = latest(File.join(dir, 'error?log*'))
       LogParser.parse_error_log(error_log, logs) if error_log
     else
       logs = LogParser.parse_whimsy_errors(dir)


Mime
View raw message