[sword-svn] r3885 - in trunk: include src/mgr

scribe at crosswire.org scribe at crosswire.org
Thu Nov 3 19:10:05 EDT 2022


Author: scribe
Date: 2022-11-03 19:10:05 -0400 (Thu, 03 Nov 2022)
New Revision: 3885

Modified:
   trunk/include/swmgr.h
   trunk/src/mgr/installmgr.cpp
   trunk/src/mgr/swmgr.cpp
Log:
Add initial cut at a caching mechanism for a mods.d folder


Modified: trunk/include/swmgr.h
===================================================================
--- trunk/include/swmgr.h	2022-11-03 21:33:38 UTC (rev 3884)
+++ trunk/include/swmgr.h	2022-11-03 23:10:05 UTC (rev 3885)
@@ -265,7 +265,7 @@
 	//
 	StringList augPaths;
 	virtual char addModToConfig(FileDesc *conffd, const char *fname);
-	virtual void loadConfigDir(const char *ipath);
+	virtual void loadConfigDir(const char *ipath, bool skipCache = false);
 
 public:
 

Modified: trunk/src/mgr/installmgr.cpp
===================================================================
--- trunk/src/mgr/installmgr.cpp	2022-11-03 21:33:38 UTC (rev 3884)
+++ trunk/src/mgr/installmgr.cpp	2022-11-03 23:10:05 UTC (rev 3885)
@@ -296,6 +296,9 @@
 
 		SWBuf modFile;
 		SWBuf modDir;
+		SWBuf destRoot = manager->configPath;
+		removeTrailingSlash(destRoot);
+		destRoot += "/";
 		entry = module->second.find("AbsoluteDataPath");
 		modDir = entry->second.c_str();
 		removeTrailingSlash(modDir);
@@ -312,13 +315,10 @@
 		else {	//remove all files in DataPath directory
 			ConfigEntMap::iterator entry;
 			FileMgr::removeDir(modDir.c_str());
-			std::vector<DirEntry> dirList = FileMgr::getDirList(manager->configPath);
+			std::vector<DirEntry> dirList = FileMgr::getDirList(destRoot.c_str());
 			for (unsigned int i = 0; i < dirList.size(); ++i) {
 				if (dirList[i].name.endsWith(".conf")) {
-					modFile = manager->configPath;
-					removeTrailingSlash(modFile);
-					modFile += "/";
-					modFile += dirList[i].name;
+					modFile = destRoot + dirList[i].name;
 					SWConfig *config = new SWConfig(modFile.c_str());
 					if (config->getSections().find(modName) != config->getSections().end()) {
 						delete config;
@@ -328,6 +328,11 @@
 				}
 			}
 		}
+
+		// assure any cache file is removed
+		SWBuf modCache = destRoot + "modules-conf.cache";
+		FileMgr::removeFile(modCache.c_str());
+
 		return 0;
 	}
 	return 1;
@@ -480,6 +485,11 @@
 			cipher = true;
 		}
 
+		// root of where destination confs live
+		SWBuf destConfRoot = destMgr->configPath;
+		removeTrailingSlash(destConfRoot);
+		destConfRoot += "/";
+
 		// root of where to install or cache install during download
 		SWBuf destRoot = mgr.prefixPath;
 		entry = module->second.find("PrefixPath");
@@ -582,7 +592,14 @@
 				}
 
 				if (!errorCode) {
+					// if all is good, use the zip archive
 					errorCode = ZipCompress::unZip(absoluteArchivePath.c_str() , destRoot.c_str());
+
+					// assure any cache file is removed
+					SWBuf modCache = destRoot + "modules-conf.cache";
+					FileMgr::removeFile(modCache.c_str());
+
+					// remove the zip archive
 					FileMgr::removeFile(absoluteArchivePath.c_str());
 					
 				}
@@ -631,10 +648,7 @@
 
 					// we found a conf file with our module
 					if (config->getSections().find(modName) != config->getSections().end()) {
-						SWBuf targetFile = destMgr->configPath; //"./mods.d/";
-						removeTrailingSlash(targetFile);
-						targetFile += "/";
-						targetFile += dirList[i].name;
+						SWBuf targetFile = destConfRoot + dirList[i].name;
 						retVal = FileMgr::copyFile(modFile.c_str(), targetFile.c_str());
 						if (cipher) {
 							if (getCipherCode(modName, config)) {
@@ -661,6 +675,11 @@
 				}
 			}
 		}
+
+		// remove any cache file which might exist
+		SWBuf modCache = destConfRoot + "modules-conf.cache";
+		FileMgr::removeFile(modCache.c_str());
+
 		return (aborted) ? -9 : retVal;
 	}
 	return 1;

Modified: trunk/src/mgr/swmgr.cpp
===================================================================
--- trunk/src/mgr/swmgr.cpp	2022-11-03 21:33:38 UTC (rev 3884)
+++ trunk/src/mgr/swmgr.cpp	2022-11-03 23:10:05 UTC (rev 3885)
@@ -744,13 +744,26 @@
 }
 
 
-void SWMgr::loadConfigDir(const char *ipath)
+void SWMgr::loadConfigDir(const char *ipath, bool skipCache)
 {
 	SWBuf basePath = ipath;
 	if (!basePath.endsWith("/") && !basePath.endsWith("\\")) basePath += "/";
 
 	SWBuf newModFile;
+	newModFile = basePath + "modules-conf.cache";
+	skipCache = skipCache || !FileMgr::existsFile(newModFile.c_str());
+	SWConfig *pathConfig = new SWConfig(newModFile);
 
+	if (!skipCache) {
+		if (config) {
+			config->augment(*pathConfig);
+		}
+		else	config = myconfig = pathConfig;
+		return;
+	}
+
+	if (!config) config = myconfig = pathConfig;
+
 	std::vector<DirEntry> dirList = FileMgr::getDirList(ipath);
 	for (unsigned int i = 0; i < dirList.size(); ++i) {
 		//check whether it ends with .conf, if it doesn't skip it!
@@ -759,17 +772,18 @@
 		}
 
 		newModFile = basePath + dirList[i].name;
-		if (config) {
-			SWConfig tmpConfig(newModFile);
-			config->augment(tmpConfig);
-		}
-		else	config = myconfig = new SWConfig(newModFile);
+		SWConfig tmpConfig(newModFile);
+		config->augment(tmpConfig);
 	}
 
-	if (!config) {	// if no .conf file exist yet, create a default
-		newModFile = basePath + "globals.conf";
-		config = myconfig = new SWConfig(newModFile);
+	pathConfig->save();
+
+	// if we're not handing off our pathConfig to be managed by our object
+	// we need to clean up
+	if (pathConfig != myconfig) {
+		delete pathConfig;
 	}
+
 }
 
 



More information about the sword-cvs mailing list