From efd7838b02f30b3c99611fc16c3f05a95fe8aadf Mon Sep 17 00:00:00 2001 From: ThinkChaos Date: Mon, 5 Feb 2024 21:29:45 -0500 Subject: [PATCH] fix(conf): don't use `cache` dir as base for all data dirs This is a bit tricky but the issue is that in a `for` loop, the loop variable(s) are shared during the whole iteration. So capturing its value in the `lambda` as `k=k` doesn't capture the value of the current iteration, but the value of the last one. In this code that happened to be `cache`, so all `data_dirs` usage was ending up with a path under `directory_cache`. --- maloja/pkg_global/conf.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/maloja/pkg_global/conf.py b/maloja/pkg_global/conf.py index 876ce95..46f2eab 100644 --- a/maloja/pkg_global/conf.py +++ b/maloja/pkg_global/conf.py @@ -332,12 +332,14 @@ for identifier,path in data_directories.items(): print("Make sure Maloja has write and execute access to this directory.") raise +class DataDirs: + def __init__(self, dirs): + self.dirs = dirs -data_dir = { - k:lambda *x,k=k: pthj(data_directories[k],*x) for k in data_directories -} - + def __getitem__(self, key): + return lambda *x, k=key: pthj(self.dirs[k], *x) +data_dir = DataDirs(data_directories) ### DOREAH OBJECTS