From 539dee31c9ba1371b9af1952927631769322225b Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Mon, 17 Jul 2023 12:04:56 +0200
Subject: [PATCH] Config: Fix config dir creation for GNU/Linux.

---
 src/config.py | 10 ++++++----
 src/tools.py  |  5 +++++
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/config.py b/src/config.py
index c865ded2..46e4ad2e 100644
--- a/src/config.py
+++ b/src/config.py
@@ -242,11 +242,13 @@ class Config(SQL):
         file = ""
 
         if os.name == 'posix':
-            file = os.path.expanduser('~') + config_dir + config_file
+            ndir = os.path.expanduser('~') + config_dir
         else:
-            ndir = os.path.expanduser('~') + config_dir.replace("/", "\\")
-            os.makedirs(ndir, exist_ok = True)
-            file = ndir + config_file
+            ndir = os.path.expanduser('~') + config_dir
+            ndir = ndir.replace("/", "\\")
+
+        os.makedirs(ndir, exist_ok = True)
+        file = ndir + config_file
 
         return file
 
diff --git a/src/tools.py b/src/tools.py
index 0e7a48d6..c71c91d1 100644
--- a/src/tools.py
+++ b/src/tools.py
@@ -184,6 +184,11 @@ class SQL(object):
     def _init_db_file(self, db):
         exists = Path(db).exists()
 
+        os.makedirs(
+            os.path.dirname(db),
+            exist_ok = True
+        )
+
         self._db = sqlite3.connect(db)
         self._cur = self._db.cursor()
 
-- 
GitLab