From 2f7923c513e9a4fc3679375e24a87f11ed8d8407 Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Wed, 3 May 2023 18:43:49 +0200 Subject: [PATCH] DataStorage: create parent config home if it doesn't exist yet (#10382) This situation might potentially occur in something like a Docker/Podman container or WSL. Fixes #10380. --- datastorage.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/datastorage.lua b/datastorage.lua index 7d9d10ae7..836cf51bc 100644 --- a/datastorage.lua +++ b/datastorage.lua @@ -20,15 +20,22 @@ function DataStorage:getDataDir() elseif os.getenv("APPIMAGE") or os.getenv("KO_MULTIUSER") then if os.getenv("XDG_CONFIG_HOME") then data_dir = string.format("%s/%s", os.getenv("XDG_CONFIG_HOME"), "koreader") + if lfs.attributes(os.getenv("XDG_CONFIG_HOME"), "mode") ~= "directory" then + lfs.mkdir(os.getenv("XDG_CONFIG_HOME")) + end else local user_rw = jit.os == "OSX" and "Library/Application Support" or ".config" + if lfs.attributes(user_rw, "mode") ~= "directory" then + lfs.mkdir(user_rw) + end data_dir = string.format("%s/%s/%s", os.getenv("HOME"), user_rw, "koreader") end else data_dir = "." end if lfs.attributes(data_dir, "mode") ~= "directory" then - lfs.mkdir(data_dir) + local ok, err = lfs.mkdir(data_dir) + if not ok then error(err) end end return data_dir