From e9c319ac7c512b3563101c87d73d959931e1554a Mon Sep 17 00:00:00 2001 From: sumneko Date: Thu, 27 Jan 2022 23:04:53 +0800 Subject: fix ref --- script/workspace/loading.lua | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'script/workspace') diff --git a/script/workspace/loading.lua b/script/workspace/loading.lua index 2ea981e7..3cdeaad6 100644 --- a/script/workspace/loading.lua +++ b/script/workspace/loading.lua @@ -81,22 +81,24 @@ function mt:loadFile(uri, libraryUri) if files.getFile(uri) then self.read = self.read + 1 self:update() - files.addRef(uri) + if not self._cache[uri] then + files.addRef(uri) + end self._cache[uri] = true log.info(('Skip loaded file: %s'):format(uri)) else local content = pub.awaitTask('loadFile', furi.decode(uri)) self.read = self.read + 1 self:update() - if not self._cache[uri] then - files.addRef(uri) - end - self._cache[uri] = true if not content then return end log.info(('Preload file at: %s , size = %.3f KB'):format(uri, #content / 1024.0)) files.setText(uri, content, false) + if not self._cache[uri] then + files.addRef(uri) + end + self._cache[uri] = true end if libraryUri then log.info('++++As library of:', libraryUri) @@ -110,22 +112,24 @@ function mt:loadFile(uri, libraryUri) if files.getFile(uri) then self.read = self.read + 1 self:update() - files.addRef(uri) + if not self._cache[uri] then + files.addRef(uri) + end self._cache[uri] = true log.info(('Skip loaded file: %s'):format(uri)) else local content = pub.awaitTask('loadFile', furi.decode(uri)) self.read = self.read + 1 self:update() - if not self._cache[uri] then - files.addRef(uri) - end - self._cache[uri] = true if not content then return end log.info(('Preload dll at: %s , size = %.3f KB'):format(uri, #content / 1024.0)) files.saveDll(uri, content) + if not self._cache[uri] then + files.addRef(uri) + end + self._cache[uri] = true end if libraryUri then log.info('++++As library of:', libraryUri) -- cgit v1.2.3