From 4447b6f147dd028b80ab40e70e30e490b40f6fb3 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Thu, 16 Apr 2015 19:52:04 +0200 Subject: [PATCH] Try to match as long a suffix as possible when determining MIME type. This will allow .tar.gz files to be indexed directly instead of being decompressed to a temp file first. --- src/index/mimetype.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/index/mimetype.cpp b/src/index/mimetype.cpp index d6735011..a2311f0a 100644 --- a/src/index/mimetype.cpp +++ b/src/index/mimetype.cpp @@ -159,11 +159,13 @@ string mimetype(const string &fn, const struct stat *stp, } // Compute file name suffix and search the mimetype map - string::size_type dot = fn.find_last_of("."); - string suff; - if (dot != string::npos) { - suff = stringtolower(fn.substr(dot)); + string::size_type dot = fn.find_first_of("."); + while (dot != string::npos) { + string suff = stringtolower(fn.substr(dot)); mtype = cfg->getMimeTypeFromSuffix(suff); + if (!mtype.empty() || dot >= fn.size() - 1) + break; + dot = fn.find_first_of(".", dot + 1); } // If type was not determined from suffix, examine file data. Can