mirror of
https://github.com/antos-rde/antos-backend.git
synced 2024-11-20 04:18:23 +01:00
store package cache in temporal file if unable to create cached file
All checks were successful
gitea-sync/antos-backend/pipeline/head This commit looks good
All checks were successful
gitea-sync/antos-backend/pipeline/head This commit looks good
This commit is contained in:
parent
8d1d91f054
commit
16cfeb6591
@ -4,10 +4,17 @@ local uid = ulib.uid(SESSION.user)
|
||||
|
||||
packages._cache = function(y)
|
||||
local p = vfs.ospath(y)
|
||||
local f = io.open(p.."/packages.json", "w")
|
||||
local file_path = p .. "/packages.json"
|
||||
local f = io.open(file_path, "w")
|
||||
local has_cache = false
|
||||
local i = 1
|
||||
local meta = {}
|
||||
|
||||
if not f then
|
||||
-- store it is temporal file
|
||||
file_path = string.format("%s/%s.packages.json",__api__.tmpdir, enc.sha1(p))
|
||||
f = io.open(file_path, "w")
|
||||
end
|
||||
if f then
|
||||
local files = vfs.readDir(y)
|
||||
for k, v in pairs(files) do
|
||||
@ -28,7 +35,7 @@ packages._cache = function(y)
|
||||
f:write(table.concat(meta, ","))
|
||||
f:close()
|
||||
if has_cache == false then
|
||||
ulib.delete(p.."/packages.json");
|
||||
ulib.delete(file_path);
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -38,12 +45,18 @@ packages.list = function(paths)
|
||||
std.json()
|
||||
std.t("{\"result\" : { ")
|
||||
local first = true
|
||||
--std.f(__ROOT__.."/system/packages.json")
|
||||
for k, v in pairs(paths) do
|
||||
local osp = vfs.ospath(v.."/packages.json")
|
||||
if ulib.exists(osp) == false then
|
||||
local p = vfs.ospath(v)
|
||||
local f1 = p.."/packages.json"
|
||||
local f2 = string.format("%s/%s.packages.json",__api__.tmpdir, enc.sha1(p))
|
||||
|
||||
if not ulib.exists(f1) and not ulib.exists(f2) then
|
||||
packages._cache(v)
|
||||
end
|
||||
local osp = f1
|
||||
if not ulib.exists(osp) then
|
||||
osp = f2
|
||||
end
|
||||
if ulib.exists(osp) then
|
||||
if first == false then
|
||||
std.t(",")
|
||||
|
13
libs/vfs.lua
13
libs/vfs.lua
@ -3,19 +3,24 @@ local vfs = {}
|
||||
vfs.ospath = function(path)
|
||||
local user = SESSION.user
|
||||
local prefix = string.match(path, "%a+:/")
|
||||
local os_path = nil
|
||||
if (prefix ~= nil) then
|
||||
local suffix = string.gsub(path, prefix, "")
|
||||
if prefix == "home:/" then
|
||||
return string.format(VFS_HOME, user) .. '/' .. suffix
|
||||
os_path = string.format(VFS_HOME, user) .. '/' .. suffix
|
||||
elseif prefix == "desktop:/" then
|
||||
return string.format(VFS_HOME, user) .. "/.desktop/" .. suffix
|
||||
os_path = string.format(VFS_HOME, user) .. "/.desktop/" .. suffix
|
||||
elseif prefix == "shared:/" then
|
||||
return require("shared").ospath(ulib.trim(suffix, "/"))
|
||||
os_path = require("shared").ospath(ulib.trim(suffix, "/"))
|
||||
elseif prefix == "os:/" then
|
||||
return WWW_ROOT .. "/" .. suffix
|
||||
os_path = WWW_ROOT .. "/" .. suffix
|
||||
else
|
||||
return nil
|
||||
end
|
||||
while os_path:match("//") do
|
||||
os_path = os_path:gsub("//","/")
|
||||
end
|
||||
return os_path
|
||||
else
|
||||
return nil;
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user