mirror of
https://github.com/antos-rde/antos-backend.git
synced 2024-11-20 04:18:23 +01:00
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
All checks were successful
gitea-sync/antos-backend/pipeline/head This commit looks good
This commit is contained in:
parent
4f697d0f70
commit
4d97476aab
@ -53,7 +53,7 @@ function SystemController:settings(...)
|
|||||||
if user then
|
if user then
|
||||||
local ospath = require("vfs").ospath("home:///", user)
|
local ospath = require("vfs").ospath("home:///", user)
|
||||||
if REQUEST and REQUEST.json then
|
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")
|
local f = io.open(file_path, "w")
|
||||||
if f then
|
if f then
|
||||||
f:write(REQUEST.json)
|
f:write(REQUEST.json)
|
||||||
|
@ -26,14 +26,13 @@ packages._cache = function(y)
|
|||||||
local name = utils.basename(v.path)
|
local name = utils.basename(v.path)
|
||||||
local mt = JSON.decodeString(f1:read("*all"))
|
local mt = JSON.decodeString(f1:read("*all"))
|
||||||
mt.path = v.path
|
mt.path = v.path
|
||||||
meta[i] = '"' .. name .. '":' .. JSON.encode(mt)
|
meta[name] = mt
|
||||||
i = i + 1
|
|
||||||
f1:close()
|
f1:close()
|
||||||
has_cache = true;
|
has_cache = true;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
f:write(table.concat(meta, ","))
|
f:write(JSON.encode(meta))
|
||||||
f:close()
|
f:close()
|
||||||
if has_cache == false then
|
if has_cache == false then
|
||||||
ulib.delete(file_path);
|
ulib.delete(file_path);
|
||||||
@ -44,8 +43,10 @@ end
|
|||||||
-- we will change this later
|
-- we will change this later
|
||||||
packages.list = function(paths)
|
packages.list = function(paths)
|
||||||
std.json()
|
std.json()
|
||||||
std.t("{\"result\" : { ")
|
local ret = {
|
||||||
local first = true
|
result = {},
|
||||||
|
error = false
|
||||||
|
}
|
||||||
for k, v in pairs(paths) do
|
for k, v in pairs(paths) do
|
||||||
local p = vfs.ospath(v)
|
local p = vfs.ospath(v)
|
||||||
local f1 = p.."/packages.json"
|
local f1 = p.."/packages.json"
|
||||||
@ -60,15 +61,16 @@ packages.list = function(paths)
|
|||||||
end
|
end
|
||||||
if ulib.exists(osp) then
|
if ulib.exists(osp) then
|
||||||
LOG_DEBUG("Use package cache files at: %s", osp)
|
LOG_DEBUG("Use package cache files at: %s", osp)
|
||||||
if first == false then
|
local data = JSON.decodeFile(osp)
|
||||||
std.t(",")
|
LOG_ERROR("ERROR: %s", data)
|
||||||
else
|
if data then
|
||||||
first = false
|
for k1,v1 in pairs(data) do
|
||||||
end
|
ret.result[k1] = v1
|
||||||
std.f(osp)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
std.t("}, \"error\":false}")
|
end
|
||||||
|
end
|
||||||
|
std.t(JSON.encode(ret))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- generate the packages caches
|
-- generate the packages caches
|
||||||
|
@ -4,9 +4,25 @@ uman.userinfo = function(user)
|
|||||||
local info = {}
|
local info = {}
|
||||||
local uid = ulib.uid(user)
|
local uid = ulib.uid(user)
|
||||||
if uid then
|
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
|
-- read the setting
|
||||||
-- use the decodeFile function of JSON instead
|
-- 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)
|
local st = JSON.decodeFile(file)
|
||||||
if(st) then
|
if(st) then
|
||||||
info = st
|
info = st
|
||||||
|
@ -9,7 +9,7 @@ vfs.ospath = function(path)
|
|||||||
if prefix == "home:/" then
|
if prefix == "home:/" then
|
||||||
os_path = string.format(VFS_HOME, user) .. '/' .. suffix
|
os_path = string.format(VFS_HOME, user) .. '/' .. suffix
|
||||||
elseif prefix == "desktop:/" then
|
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
|
elseif prefix == "shared:/" then
|
||||||
os_path = require("shared").ospath(ulib.trim(suffix, "/"))
|
os_path = require("shared").ospath(ulib.trim(suffix, "/"))
|
||||||
elseif prefix == "os:/" then
|
elseif prefix == "os:/" then
|
||||||
|
Loading…
Reference in New Issue
Block a user