From 83d86062709d937e244418335f96017d264f3625 Mon Sep 17 00:00:00 2001 From: Zijie He Date: Wed, 8 Feb 2017 10:46:55 -0800 Subject: [PATCH] Crash on directory --- frontend/docsettings.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/docsettings.lua b/frontend/docsettings.lua index 5ff2d05e7..0a4396053 100644 --- a/frontend/docsettings.lua +++ b/frontend/docsettings.lua @@ -29,13 +29,17 @@ end function DocSettings:getSidecarFile(doc_path) if doc_path == nil or doc_path == '' then return '' end - return self:getSidecarDir(doc_path) .. "/metadata." .. doc_path:match(".*%.(.+)") .. ".lua" + -- If the file does not have a suffix or we are working on a directory, we + -- should ignore the suffix part in metadata file path. + local suffix = doc_path:match(".*%.(.+)") + if suffix == nil then + suffix = '' + end + return self:getSidecarDir(doc_path) .. "/metadata." .. suffix .. ".lua" end function DocSettings:hasSidecarFile(doc_path) - local file = self:getSidecarFile(doc_path) - if file == nil or file == '' then return false end - return lfs.attributes(file, "mode") == "file" + return lfs.attributes(self:getSidecarFile(doc_path), "mode") == "file" end function DocSettings:getHistoryPath(fullpath)