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

scribe at crosswire.org scribe at crosswire.org
Thu Oct 15 13:32:41 EDT 2020


Author: scribe
Date: 2020-10-15 13:32:41 -0400 (Thu, 15 Oct 2020)
New Revision: 3812

Modified:
   trunk/include/filemgr.h
   trunk/src/mgr/curlftpt.cpp
   trunk/src/mgr/filemgr.cpp
   trunk/src/mgr/installmgr.cpp
Log:
Exposed more FileMgr statics which isolate OS-specific implementations so they can be used outside of FileMgr's pooled handles
Changed CURLFTPTransport to only use FileMgr statics instead of pooled handles


Modified: trunk/include/filemgr.h
===================================================================
--- trunk/include/filemgr.h	2020-10-11 21:35:19 UTC (rev 3811)
+++ trunk/include/filemgr.h	2020-10-15 17:32:41 UTC (rev 3812)
@@ -186,6 +186,8 @@
 	 */
 	static int openFile(const char *fName, int mode, int perms);
 	static int openFileReadOnly(const char *fName);
+	static void closeFile(int fd);
+	static long write(int fd, const void *buf, long count);
 
 	static int copyFile(const char *srcFile, const char *destFile);
 	static int copyDir(const char *srcDir, const char *destDir);

Modified: trunk/src/mgr/curlftpt.cpp
===================================================================
--- trunk/src/mgr/curlftpt.cpp	2020-10-11 21:35:19 UTC (rev 3811)
+++ trunk/src/mgr/curlftpt.cpp	2020-10-15 17:32:41 UTC (rev 3812)
@@ -36,7 +36,7 @@
 
 	struct FtpFile {
 		const char *filename;
-		FileDesc *stream;
+		int fd;
 		SWBuf *destBuf;
 	};
 
@@ -56,10 +56,10 @@
 
 	static int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
 		struct FtpFile *out=(struct FtpFile *)stream;
-		if (out && !out->stream && !out->destBuf) {
+		if (out && !out->fd && !out->destBuf) {
 			/* open file for writing */
-			out->stream=FileMgr::getSystemFileMgr()->open(out->filename, FileMgr::CREAT|FileMgr::WRONLY);
-			if (!out->stream || out->stream->getFd() < 0)
+			out->fd = FileMgr::createPathAndFile(out->filename);
+			if (out->fd < 0)
 				return -1; /* failure, can't open file to write */
 		}
 		if (out->destBuf) {
@@ -68,7 +68,7 @@
 			memcpy(out->destBuf->getRawData()+s, buffer, size*nmemb);
 			return (int)nmemb;
 		}
-		return (int)out->stream->write(buffer, size *nmemb);
+		return (int)FileMgr::write(out->fd, buffer, size * nmemb);
 	}
 
 
@@ -199,8 +199,8 @@
 		}
 	}
 
-	if (ftpfile.stream)
-		FileMgr::getSystemFileMgr()->close(ftpfile.stream); /* close the local file */
+	if (ftpfile.fd > 0)
+		FileMgr::closeFile(ftpfile.fd); /* close the local file */
 
 	return retVal;
 }

Modified: trunk/src/mgr/filemgr.cpp
===================================================================
--- trunk/src/mgr/filemgr.cpp	2020-10-11 21:35:19 UTC (rev 3811)
+++ trunk/src/mgr/filemgr.cpp	2020-10-15 17:32:41 UTC (rev 3812)
@@ -112,6 +112,10 @@
 	systemFileMgr = newFileMgr;
 }
 
+long FileMgr::write(int fd, const void *buf, long count) {
+	return ::write(fd, buf, count);
+}
+
 // --------------- end statics --------------
 
 
@@ -129,7 +133,7 @@
 
 FileDesc::~FileDesc() {
 	if (fd > 0)
-		::close(fd);
+		FileMgr::closeFile(fd);
 
 	if (path)
 		delete [] path;
@@ -147,7 +151,7 @@
 
 
 long FileDesc::write(const void *buf, long count) {
-	return ::write(getFd(), buf, count);
+	return FileMgr::write(getFd(), buf, count);
 }
 
 
@@ -484,6 +488,11 @@
 }
 
 
+void FileMgr::closeFile(int fd) {
+	::close(fd);
+}
+
+
 int FileMgr::copyFile(const char *sourceFile, const char *targetFile) {
 	int sfd, dfd, len;
 	char buf[4096];

Modified: trunk/src/mgr/installmgr.cpp
===================================================================
--- trunk/src/mgr/installmgr.cpp	2020-10-11 21:35:19 UTC (rev 3811)
+++ trunk/src/mgr/installmgr.cpp	2020-10-15 17:32:41 UTC (rev 3812)
@@ -276,7 +276,7 @@
 			FileMgr::removeDir(modDir.c_str());
 			std::vector<DirEntry> dirList = FileMgr::getDirList(manager->configPath);
 			for (unsigned int i = 0; i < dirList.size(); ++i) {
-               	if (dirList[i].name.endsWith(".conf")) {
+				if (dirList[i].name.endsWith(".conf")) {
 					modFile = manager->configPath;
 					removeTrailingSlash(modFile);
 					modFile += "/";
@@ -513,8 +513,8 @@
 		if (!aborted) {
 			SWBuf confDir = sourceDir + "mods.d/";
 			std::vector<DirEntry> dirList = FileMgr::getDirList(confDir);
-               for (unsigned int i = 0; i < dirList.size() && !retVal; ++i) {
-               	if (dirList[i].name.endsWith(".conf")) {
+			for (unsigned int i = 0; i < dirList.size() && !retVal; ++i) {
+				if (dirList[i].name.endsWith(".conf")) {
 					modFile = confDir;
 					modFile += dirList[i].name;
 					SWConfig *config = new SWConfig(modFile);



More information about the sword-cvs mailing list