From 9791565324f0376494600ee230da7cdcb42a3310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 21 Oct 2021 20:14:35 +0800 Subject: catch error --- script/filewatch.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/script/filewatch.lua b/script/filewatch.lua index e8c54d62..17a0548b 100644 --- a/script/filewatch.lua +++ b/script/filewatch.lua @@ -5,6 +5,16 @@ local await = require 'await' local MODIFY = 1 << 0 local RENAME = 1 << 1 +local function exists(filename) + local path = fs.path(filename) + local suc, res = pcall(fs.exists, path) + if suc and res then + return true + else + return false + end +end + ---@class filewatch local m = {} @@ -53,7 +63,7 @@ function m.update() local changes = {} for path, flag in pairs(collect) do if flag & RENAME ~= 0 then - if fs.exists(fs.path(path)) then + if exists(path) then changes[#changes+1] = { type = 'create', path = path, -- cgit v1.2.3