fix: query home dir from user id, if fail, fallback to default value
gitea-sync/antos-backend/pipeline/head This commit looks good Details

This commit is contained in:
DanyLE 2024-03-10 22:55:39 +01:00
parent 32bd62ae86
commit 37f68f0e04
2 changed files with 16 additions and 3 deletions

View File

@ -2,14 +2,21 @@ local vfs = {}
vfs.ospath = function(path)
local user = SESSION.user
local uid = ulib.uid(SESSION.user)
local prefix = string.match(path, "%a+:/")
local home = ulib.home_dir(uid.id)
if not home then
home = string.format("%s/%s",VFS_HOME, user)
else
LOG_DEBUG("User home is %s", home)
end
local os_path = nil
if (prefix ~= nil) then
local suffix = string.gsub(path, prefix, "")
if prefix == "home:/" then
os_path = string.format(VFS_HOME, user) .. '/' .. suffix
os_path = home.. '/' .. suffix
elseif prefix == "desktop:/" then
os_path = string.format(VFS_HOME, user) .. "/.antos/desktop/" .. suffix
os_path = home .. "/.antos/desktop/" .. suffix
elseif prefix == "shared:/" then
os_path = require("shared").ospath(ulib.trim(suffix, "/"))
elseif prefix == "os:/" then

View File

@ -15,7 +15,13 @@ package.path = package.path..";"..WWW_ROOT .. '/libs/?.lua'
require("common")
DIR_SEP = "/"
VFS_HOME = "/home/%s"
VFS_HOME = os.getenv("HOME_ROOT")
if not VFS_HOME then
VFS_HOME="/home"
end
LOG_DEBUG("VFS_HOME=%s", VFS_HOME)
-- class path: path.to.class
CONTROLLER_ROOT = "os.controllers"
MODEL_ROOT = "os.models"