fix: correct way to process package cache & init neccessary directories when use first logged in
All checks were successful
gitea-sync/antos-backend/pipeline/head This commit looks good

This commit is contained in:
DanyLE 2023-06-20 17:11:58 +02:00
parent 4f697d0f70
commit 4d97476aab
4 changed files with 32 additions and 14 deletions

View File

@ -53,7 +53,7 @@ function SystemController:settings(...)
if user then
local ospath = require("vfs").ospath("home:///", user)
if REQUEST and REQUEST.json then
local file_path = ospath .. "/" .. ".settings.json"
local file_path = ospath .. "/.antos/settings/" .. "settings.json"
local f = io.open(file_path, "w")
if f then
f:write(REQUEST.json)

View File

@ -26,14 +26,13 @@ packages._cache = function(y)
local name = utils.basename(v.path)
local mt = JSON.decodeString(f1:read("*all"))
mt.path = v.path
meta[i] = '"' .. name .. '":' .. JSON.encode(mt)
i = i + 1
meta[name] = mt
f1:close()
has_cache = true;
end
end
end
f:write(table.concat(meta, ","))
f:write(JSON.encode(meta))
f:close()
if has_cache == false then
ulib.delete(file_path);
@ -44,8 +43,10 @@ end
-- we will change this later
packages.list = function(paths)
std.json()
std.t("{\"result\" : { ")
local first = true
local ret = {
result = {},
error = false
}
for k, v in pairs(paths) do
local p = vfs.ospath(v)
local f1 = p.."/packages.json"
@ -60,15 +61,16 @@ packages.list = function(paths)
end
if ulib.exists(osp) then
LOG_DEBUG("Use package cache files at: %s", osp)
if first == false then
std.t(",")
else
first = false
local data = JSON.decodeFile(osp)
LOG_ERROR("ERROR: %s", data)
if data then
for k1,v1 in pairs(data) do
ret.result[k1] = v1
end
end
std.f(osp)
end
end
std.t("}, \"error\":false}")
std.t(JSON.encode(ret))
end
-- generate the packages caches

View File

@ -4,9 +4,25 @@ uman.userinfo = function(user)
local info = {}
local uid = ulib.uid(user)
if uid then
-- create the following directory structure if does not exists
local dir = require('vfs').ospath("home:///.antos", user)
if not ulib.exists(dir) then
ulib.mkdir(dir)
ulib.chown(dir, uid.id, uid.gid)
end
local setting_dir = dir.."/settings"
if not ulib.exists(setting_dir) then
ulib.mkdir(setting_dir)
ulib.chown(setting_dir, uid.id, uid.gid)
end
local desktop_dir = dir.."/desktop"
if not ulib.exists(desktop_dir) then
ulib.mkdir(desktop_dir)
ulib.chown(desktop_dir, uid.id, uid.gid)
end
-- read the setting
-- use the decodeFile function of JSON instead
local file = require('vfs').ospath("home:///").."/.settings.json"
local file = require('vfs').ospath("home:///").."/.antos/settings/settings.json"
local st = JSON.decodeFile(file)
if(st) then
info = st

View File

@ -9,7 +9,7 @@ vfs.ospath = function(path)
if prefix == "home:/" then
os_path = string.format(VFS_HOME, user) .. '/' .. suffix
elseif prefix == "desktop:/" then
os_path = string.format(VFS_HOME, user) .. "/.desktop/" .. suffix
os_path = string.format(VFS_HOME, user) .. "/.antos/desktop/" .. suffix
elseif prefix == "shared:/" then
os_path = require("shared").ospath(ulib.trim(suffix, "/"))
elseif prefix == "os:/" then