[Groonga-commit] ranguba/ranguba at 0f2802d [master] indexer: fix a bug that URL and content may be differed

Back to archive index
Kouhei Sutou null+****@clear*****
Thu Oct 25 11:52:28 JST 2018


Kouhei Sutou	2018-10-25 11:52:28 +0900 (Thu, 25 Oct 2018)

  Revision: 0f2802d1f9b9f5c081906334bab871dc7622d45e
  https://github.com/ranguba/ranguba/commit/0f2802d1f9b9f5c081906334bab871dc7622d45e

  Message:
    indexer: fix a bug that URL and content may be differed
    
    It's occurred when redirect is occurred.

  Modified files:
    lib/ranguba/indexer.rb

  Modified: lib/ranguba/indexer.rb (+16 -14)
===================================================================
--- lib/ranguba/indexer.rb    2014-09-23 01:50:24 +0900 (0d81141)
+++ lib/ranguba/indexer.rb    2018-10-25 11:52:28 +0900 (5feb0dd)
@@ -207,27 +207,29 @@ EOS
   def process_from_log(base, input)
     result = true
     url = response = file = path = nil
-    input.each("") do |log|
-      next unless log.valid_encoding?
-      case log
-      when /^--([-\d]+.*?)\s*--\s+(.+)/
+    input.each_line do |line|
+      next unless line.valid_encoding?
+      case line.chomp
+      when /\A--([-\d]+.*?)\s*--\s+(.+)/
         update = $1
         url = $2.sub(/\A\(try:\s*\d+\)\s*/, '')
-        log(:info, " URL: #{url}")
-        if response = log[/^(?:  .*\n)+/]
-          response = Hash[response.lines.grep(/^\s*([-A-Za-z0-9]+):\s*(.*)$/) {[$1.downcase, $2]}]
-        end
-        file = log[/^Saving to: [`'](.+)[`']$/, 1]
-        next unless file      # failed to start download
-        path = File.join(base, file.gsub(/\\'/, "'"))
-        response ||= {}
+        file = nil
+        path = nil
         update = Time.parse(update)
-        response["x-update-time"] = update
         if !@oldest or @oldest > update
           @oldest = update
         end
+        response = {
+          "x-update-time" => update,
+        }
+        log(:info, " URL: #{url}")
+      when /\A  ([-A-Za-z0-9]+):\s*(.*)\z/
+        response[$1] = $2
+      when /\ASaving to: [`'](.+)[`']\z/
+        file = $1
+        path = File.join(base, file.gsub(/\\'/, "'"))
       when /saved/
-        unless url and path and File.file?(path)
+        if url.nil? or path.nil? or !File.file?(path)
           log(:warn, "[file][not_found] path #{path}")
           next
         end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20181025/96d05afa/attachment-0001.html>


More information about the Groonga-commit mailing list
Back to archive index