From 9f4a1da52e86a8ceb9e37794b41a220940ffd697 Mon Sep 17 00:00:00 2001 From: "@splash" Date: Wed, 5 Aug 2015 14:45:41 +0200 Subject: [PATCH] sort discovered files by date modified for people doing bulk import it's important to know which files are going to be processed. Ultimately a better patch is to pass how to sort (date modified, alphabetically, none - in this case the user should rely on the fact that Dir.glob behaves differently across platforms) and logstash e.g. the file plugin could have option "sort". for now I think it's important users KNOW that files are sorted by date modified or alternatively alphabetically: ```globbed_dirs = Dir.glob(path).sort``` --- lib/filewatch/watch.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/filewatch/watch.rb b/lib/filewatch/watch.rb index 9694eed..985d091 100644 --- a/lib/filewatch/watch.rb +++ b/lib/filewatch/watch.rb @@ -128,7 +128,7 @@ def subscribe(stat_interval = 1, discover_interval = 5, &block) private def _discover_file(path, initial=false) - globbed_dirs = Dir.glob(path) + globbed_dirs = Dir.glob(path).sort_by { |a| File.mtime(a) } @logger.debug? && @logger.debug("_discover_file_glob: #{path}: glob is: #{globbed_dirs}") if globbed_dirs.empty? && File.file?(path) globbed_dirs = [path]