[sword-devel] Rough edges with installmgr

Isaac Dunham ibid.ag at gmail.com
Thu Jul 17 16:24:30 MST 2014


Hello,
I've run into a few rough edges with installmgr; I have patches for one of them.

First, when built with musl the "enable? [no]" prompt doesn't show up until
after you type in the response.
This is because stdio can buffer writes indefinately until fflush() is called
(the relevant standards explicitly state this); the solution is to call 
fflush() before reading the response.

Second, when sword.conf points to a read-only directory (for example, when
SWORD is installed systemwide with default /etc/sword.conf, and the user has
not yet set DataPath in ~/.sword/sword.conf), installmgr fails to install the
module but reports success.
I have not tested whether this happens on other *nix-like systems recently,
though I seem to recall seeing it on Debian in the past.
This _may_ be because installMgr::installModule() calls fileMgr::copyFile()
without checking the result.
I've tried patching this, but the patch I have so far (installModule.diff) 
breaks installmgr for reasons I'm not sure of.

The third point is a feature request: would it be possible for
installmgr -init
to check if DataPath is writeable, and if not to add something along
the lines of 
---
[INSTALL]
DataPath=~/.sword
---
to sword.conf?

Where I write ~/.sword, I mean the user directory where sword.conf lives.

The second and third points seem to cause a bit of confusion for new
users.

Thank you and God bless,
Isaac Dunham
-------------- next part --------------
diff --git a/utilities/installmgr.cpp b/utilities/installmgr.cpp
index b705c25..132314a 100644
--- a/utilities/installmgr.cpp
+++ b/utilities/installmgr.cpp
@@ -73,6 +73,7 @@ virtual bool isUserDisclaimerConfirmed() const {
 		cout << "If you understand this and are willing to enable remote source features\n";
 		cout << "then type yes at the prompt\n\n";
 		cout << "enable? [no] ";
+		fflush(stdout);
 
 		char prompt[10];
 		fgets(prompt, 9, stdin);
-------------- next part --------------
commit de8c90df1c8b2d8b7aab99444d20c5cdc5aee693
Author: Isaac Dunham <ibid.ag at gmail.com>
Date:   Thu Jul 17 14:29:00 2014 -0700

    Try to make installmgr realize when it can't write somewhere

diff --git a/src/mgr/installmgr.cpp b/src/mgr/installmgr.cpp
index 1e83db5..1045e6e 100644
--- a/src/mgr/installmgr.cpp
+++ b/src/mgr/installmgr.cpp
@@ -401,6 +401,7 @@ int InstallMgr::installModule(SWMgr *destMgr, const char *fromLocation, const ch
 	SWBuf buffer;
 	bool aborted = false;
 	bool cipher = false;
+	int badcopy = 0;
 	DIR *dir;
 	struct dirent *ent;
 	SWBuf modFile;
@@ -456,7 +457,7 @@ int InstallMgr::installModule(SWMgr *destMgr, const char *fromLocation, const ch
 					removeTrailingSlash(dest);
 					dest += '/';
 					dest += fileBegin->second.c_str();
-					FileMgr::copyFile(sourcePath.c_str(), dest.c_str());
+					badcopy = FileMgr::copyFile(sourcePath.c_str(), dest.c_str());
 
 					fileBegin++;
 				}
@@ -526,7 +527,7 @@ int InstallMgr::installModule(SWMgr *destMgr, const char *fromLocation, const ch
 							removeTrailingSlash(targetFile);
 							targetFile += "/";
 							targetFile += ent->d_name;
-							FileMgr::copyFile(modFile.c_str(), targetFile.c_str());
+							badcopy = FileMgr::copyFile(modFile.c_str(), targetFile.c_str());
 							if (cipher) {
 								if (getCipherCode(modName, config)) {
 									SWMgr newDest(destMgr->prefixPath);
@@ -535,7 +536,7 @@ int InstallMgr::installModule(SWMgr *destMgr, const char *fromLocation, const ch
 								}
 								else {
 									config->Save();
-									FileMgr::copyFile(modFile.c_str(), targetFile.c_str());
+									badcopy = FileMgr::copyFile(modFile.c_str(), targetFile.c_str());
 								}
 							}
 						}
@@ -545,7 +546,7 @@ int InstallMgr::installModule(SWMgr *destMgr, const char *fromLocation, const ch
 				closedir(dir);
 			}
 		}
-		return (aborted) ? -1 : 0;
+		return (aborted) ? -1 : badcopy;
 	}
 	return 1;
 }


More information about the sword-devel mailing list