From 670acd237523dcb96e40df2b1232158dfa3ed2b2 Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Thu, 21 Jan 2021 01:44:13 -0800
Subject: [PATCH] Fix: initialize default data directories after auto-creating
 sub-dirs

When a file library's "Access to Sub-directories" option was enabled, any auto-created directories would have their data dir initialized as "blank" (empty), so their data files (e.g. <code>.dat, <code>.ixb) would be created in the ctrl directory.

I guess nobody used this feature? It is pretty cool, but not really documented. If you were using it before this commit, you'll need to move your sub-directories data files to data/dirs or re-add the files (recreate the database files). And you can remove the old cruft from the ctrl dir.
---
 src/sbbs3/load_cfg.c | 45 ++++++++++++++++++++++----------------------
 1 file changed, 22 insertions(+), 23 deletions(-)

diff --git a/src/sbbs3/load_cfg.c b/src/sbbs3/load_cfg.c
index 147d66bbd4..761157407a 100644
--- a/src/sbbs3/load_cfg.c
+++ b/src/sbbs3/load_cfg.c
@@ -178,29 +178,6 @@ void prep_cfg(scfg_t* cfg)
 			prep_dir(cfg->ctrl_dir, cfg->lib[i]->parent_path, sizeof(cfg->lib[i]->parent_path));
 	}
 
-	for(i=0;i<cfg->total_dirs;i++) {
-
-		if(!cfg->dir[i]->data_dir[0])	/* no data storage path specified */
-			SAFEPRINTF(cfg->dir[i]->data_dir,"%sdirs",cfg->data_dir);
-		prep_dir(cfg->ctrl_dir, cfg->dir[i]->data_dir, sizeof(cfg->dir[i]->data_dir));
-
-		/* A directory's internal code is the combination of the lib's code_prefix & the dir's code_suffix */
-		SAFEPRINTF2(cfg->dir[i]->code,"%s%s"
-			,cfg->lib[cfg->dir[i]->lib]->code_prefix
-			,cfg->dir[i]->code_suffix);
-
-		strlwr(cfg->dir[i]->code); 		/* data filenames are all lowercase */
-
-		if(!cfg->dir[i]->path[0])
-			SAFECOPY(cfg->dir[i]->path, cfg->dir[i]->code);
-		if(cfg->lib[cfg->dir[i]->lib]->parent_path[0])
-			prep_dir(cfg->lib[cfg->dir[i]->lib]->parent_path, cfg->dir[i]->path, sizeof(cfg->dir[i]->path));
-		else
-			prep_dir(cfg->dir[i]->data_dir, cfg->dir[i]->path, sizeof(cfg->dir[i]->path));
-
-		prep_path(cfg->dir[i]->upload_sem);
-	}
-
 	for(i=0;i<cfg->total_libs;i++) {
 		if((cfg->lib[i]->misc&LIB_DIRS) == 0 || cfg->lib[i]->parent_path[0] == 0)
 			continue;
@@ -255,6 +232,28 @@ void prep_cfg(scfg_t* cfg)
 		}
 	}
 
+	for(i=0;i<cfg->total_dirs;i++) {
+
+		if(!cfg->dir[i]->data_dir[0])	/* no data storage path specified */
+			SAFEPRINTF(cfg->dir[i]->data_dir,"%sdirs",cfg->data_dir);
+		prep_dir(cfg->ctrl_dir, cfg->dir[i]->data_dir, sizeof(cfg->dir[i]->data_dir));
+
+		/* A directory's internal code is the combination of the lib's code_prefix & the dir's code_suffix */
+		SAFEPRINTF2(cfg->dir[i]->code,"%s%s"
+			,cfg->lib[cfg->dir[i]->lib]->code_prefix
+			,cfg->dir[i]->code_suffix);
+
+		strlwr(cfg->dir[i]->code); 		/* data filenames are all lowercase */
+
+		if(!cfg->dir[i]->path[0])
+			SAFECOPY(cfg->dir[i]->path, cfg->dir[i]->code);
+		if(cfg->lib[cfg->dir[i]->lib]->parent_path[0])
+			prep_dir(cfg->lib[cfg->dir[i]->lib]->parent_path, cfg->dir[i]->path, sizeof(cfg->dir[i]->path));
+		else
+			prep_dir(cfg->dir[i]->data_dir, cfg->dir[i]->path, sizeof(cfg->dir[i]->path));
+
+		prep_path(cfg->dir[i]->upload_sem);
+	}
 
 	/* make data filenames are all lowercase */
 	for(i=0;i<cfg->total_shells;i++)
-- 
GitLab