From boxbackup-dev@fluffy.co.uk  Tue May  2 23:00:28 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue,  2 May 2006 22:00:28 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r560 - box/chris/general/bin/bbackupd
Message-ID: <20060502220028.CFD6695@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-02 22:00:21 +0000 (Tue, 02 May 2006)
New Revision: 560

Modified:
   box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp
Log:
* Win32ServiceFunctions.cpp
- Detect duplicate service name and respond with an appropriate error message


Modified: box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp
===================================================================
--- box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp	2006-04-26 21:36:06 UTC (rev 559)
+++ box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp	2006-05-02 22:00:21 UTC (rev 560)
@@ -253,6 +253,12 @@
 			::syslog(LOG_ERR, "Failed to create Box Backup "
 				"service: it is waiting to be deleted");
 		}
+		else if (err == ERROR_DUPLICATE_SERVICE_NAME)
+		{
+			::syslog(LOG_ERR, "Failed to create Box Backup "
+				"service: a service with this name "
+				"already exists");
+		}
 		else
 		{
 			::syslog(LOG_ERR, "Failed to create Box Backup "


From boxbackup-dev@fluffy.co.uk  Thu May  4 23:07:55 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Thu,  4 May 2006 22:07:55 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r561 - box/trunk/bin/bbackupquery
Message-ID: <20060504220755.4A5BB95@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-04 22:07:48 +0000 (Thu, 04 May 2006)
New Revision: 561

Modified:
   box/trunk/bin/bbackupquery/BackupQueries.cpp
Log:
* BackupQueries.cpp
- Fixed wrong path displayed during compare failure (duplicate local 
  variable names)
- Renamed some variables to make their purpose clearer, making the code 
  easier to read
- Fixed some cases where untranslated names would be shown on Win32, 
  probably with encoding errors if they contained intl characters
- Fixed a couple of minor spelling mistakes in compare output


Modified: box/trunk/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/trunk/bin/bbackupquery/BackupQueries.cpp	2006-05-02 22:00:21 UTC (rev 560)
+++ box/trunk/bin/bbackupquery/BackupQueries.cpp	2006-05-04 22:07:48 UTC (rev 561)
@@ -1184,14 +1184,14 @@
 #ifdef WIN32
 	// By this point, rStoreDir and rLocalDir should be in UTF-8 encoding
 
-	std::string localName;
-	std::string storeName;
+	std::string localDirDisplay;
+	std::string storeDirDisplay;
 
-	if(!ConvertUtf8ToConsole(rLocalDir.c_str(), localName)) return;
-	if(!ConvertUtf8ToConsole(rStoreDir.c_str(), storeName)) return;
+	if(!ConvertUtf8ToConsole(rLocalDir.c_str(), localDirDirsplay)) return;
+	if(!ConvertUtf8ToConsole(rStoreDir.c_str(), storeDirDisplay)) return;
 #else
-	const std::string& localName(rLocalDir);
-	const std::string& storeName(rStoreDir);
+	const std::string& localDirDisplay(rLocalDir);
+	const std::string& storeDirDisplay(rStoreDir);
 #endif
 
 	// Get info on the local directory
@@ -1203,19 +1203,21 @@
 		{
 			printf("Local object '%s' is a file, "
 				"server object '%s' is a directory\n", 
-				localName.c_str(), storeName.c_str());
+				localDirDisplay.c_str(), 
+				storeDirDisplay.c_str());
 			rParams.mDifferences ++;
 		}
 		else if(errno == ENOENT)
 		{
 			printf("Local directory '%s' does not exist "
 				"(compared to server directory '%s')\n",
-				localName.c_str(), storeName.c_str());
+				localDirDisplay.c_str(), 
+				storeDirDisplay.c_str());
 		}
 		else
 		{
 			printf("ERROR: stat on local dir '%s'\n", 
-				localName.c_str());
+				localDirDisplay.c_str());
 		}
 		return;
 	}
@@ -1236,7 +1238,7 @@
 	if(!dir.HasAttributes())
 	{
 		printf("Store directory '%s' doesn't have attributes.\n", 
-			storeName.c_str());
+			storeDirDisplay.c_str());
 	}
 	else
 	{
@@ -1253,7 +1255,8 @@
 		{
 			printf("Local directory '%s' has different attributes "
 				"to store directory '%s'.\n",
-				localName.c_str(), storeName.c_str());
+				localDirDisplay.c_str(), 
+				storeDirDisplay.c_str());
 			rParams.mDifferences ++;
 		}
 	}
@@ -1262,7 +1265,8 @@
 	DIR *dirhandle = ::opendir(rLocalDir.c_str());
 	if(dirhandle == 0)
 	{
-		printf("ERROR: opendir on local dir '%s'\n", localName.c_str());
+		printf("ERROR: opendir on local dir '%s'\n", 
+			localDirDisplay.c_str());
 		return;
 	}
 	try
@@ -1320,7 +1324,7 @@
 		if(::closedir(dirhandle) != 0)
 		{
 			printf("ERROR: closedir on local dir '%s'\n", 
-				localName.c_str());
+				localDirDisplay.c_str());
 		}
 		dirhandle = 0;
 	
@@ -1357,16 +1361,31 @@
 		// Now compare files.
 		for(std::set<std::pair<std::string, BackupStoreDirectory::Entry *> >::const_iterator i = storeFiles.begin(); i != storeFiles.end(); ++i)
 		{
+			const std::string& fileName(i->first);
+#ifdef WIN32
+			// File name is also in UTF-8 encoding, 
+			// need to convert to console
+			std::string fileNameDisplay;
+			if(!ConvertUtf8ToConsole(i->first.c_str(), 
+				fileNameDisplay)) return;
+#else
+			const std::string& fileNameDisplay(i->first);
+#endif
+
+			std::string localPathDisplay = localDirDisplay +
+				DIRECTORY_SEPARATOR + fileNameDisplay;
+			std::string storePathDisplay = storeDirDisplay +
+				"/" + fileNameDisplay;
+
 			// Does the file exist locally?
-			string_set_iter_t local(localFiles.find(i->first));
+			string_set_iter_t local(localFiles.find(fileName));
 			if(local == localFiles.end())
 			{
 				// Not found -- report
-				printf("Local file '%s" DIRECTORY_SEPARATOR 
-					"%s' does not exist, "
-					"but store file '%s/%s' does.\n",
-					localName.c_str(), i->first.c_str(), 
-					storeName.c_str(), i->first.c_str());
+				printf("Local file '%s' does not exist, "
+					"but store file '%s' does.\n",
+					localPathDisplay.c_str(),
+					storePathDisplay.c_str());
 				rParams.mDifferences ++;
 			}
 			else
@@ -1374,7 +1393,7 @@
 				try
 				{
 					// make local name of file for comparison
-					std::string localName(rLocalDir + DIRECTORY_SEPARATOR + i->first);
+					std::string localPath(rLocalDir + DIRECTORY_SEPARATOR + fileName);
 
 					// Files the same flag?
 					bool equal = true;
@@ -1391,7 +1410,7 @@
 						std::auto_ptr<IOStream> blockIndexStream(mrConnection.ReceiveStream());
 						
 						// Compare
-						equal = BackupStoreFile::CompareFileContentsAgainstBlockIndex(localName.c_str(), *blockIndexStream, mrConnection.GetTimeout());
+						equal = BackupStoreFile::CompareFileContentsAgainstBlockIndex(localPath.c_str(), *blockIndexStream, mrConnection.GetTimeout());
 					}
 					else
 					{
@@ -1426,17 +1445,17 @@
 						// Compare attributes
 						BackupClientFileAttributes localAttr;
 						box_time_t fileModTime = 0;
-						localAttr.ReadAttributes(localName.c_str(), false /* don't zero mod times */, &fileModTime);					
+						localAttr.ReadAttributes(localPath.c_str(), false /* don't zero mod times */, &fileModTime);					
 						modifiedAfterLastSync = (fileModTime > rParams.mLatestFileUploadTime);
 						if(!localAttr.Compare(fileOnServerStream->GetAttributes(),
 								true /* ignore attr mod time */,
 								fileOnServerStream->IsSymLink() /* ignore modification time if it's a symlink */))
 						{
-							printf("Local file '%s"
-								DIRECTORY_SEPARATOR
-								"%s' has different attributes "
-								"to store file '%s/%s'.\n",
-								localName.c_str(), i->first.c_str(), storeName.c_str(), i->first.c_str());						
+							printf("Local file '%s' "
+								"has different attributes "
+								"to store file '%s'.\n",
+								localPathDisplay.c_str(), 
+								storePathDisplay.c_str());						
 							rParams.mDifferences ++;
 							if(modifiedAfterLastSync)
 							{
@@ -1454,7 +1473,7 @@
 						if(!fileOnServerStream->IsSymLink())
 						{
 							// Open the local file
-							FileStream l(localName.c_str());
+							FileStream l(localPath.c_str());
 							
 							// Size
 							IOStream::pos_type fileSizeLocal = l.BytesLeftToRead();
@@ -1500,11 +1519,11 @@
 					// Report if not equal.
 					if(!equal)
 					{
-						printf("Local file '%s"
-							DIRECTORY_SEPARATOR
-							"%s' has different contents "
-							"to store file '%s/%s'.\n",
-							localName.c_str(), i->first.c_str(), storeName.c_str(), i->first.c_str());
+						printf("Local file '%s' "
+							"has different contents "
+							"to store file '%s'.\n",
+							localPathDisplay.c_str(), 
+							storePathDisplay.c_str());
 						rParams.mDifferences ++;
 						if(modifiedAfterLastSync)
 						{
@@ -1519,15 +1538,14 @@
 				}
 				catch(BoxException &e)
 				{
-					printf("ERROR: (%d/%d) during file fetch and comparsion for '%s/%s'\n",
+					printf("ERROR: (%d/%d) during file fetch and comparison for '%s'\n",
 						e.GetType(),
 						e.GetSubType(),
-						storeName.c_str(), 
-						i->first.c_str());
+						storePathDisplay.c_str());
 				}
 				catch(...)
 				{
-					printf("ERROR: (unknown) during file fetch and comparsion for '%s/%s'\n", storeName.c_str(), i->first.c_str());
+					printf("ERROR: (unknown) during file fetch and comparison for '%s'\n", storePathDisplay.c_str());
 				}
 
 				// Remove from set so that we know it's been compared
@@ -1538,23 +1556,37 @@
 		// Report any files which exist on the locally, but not on the store
 		for(string_set_iter_t i = localFiles.begin(); i != localFiles.end(); ++i)
 		{
-			std::string localFileName(rLocalDir + 
+#ifdef WIN32
+			// File name is also in UTF-8 encoding, 
+			// need to convert to console
+			std::string fileNameDisplay;
+			if(!ConvertUtf8ToConsole(*i, fileNameDisplay)) return;
+#else
+			const std::string& fileNameDisplay(*i);
+#endif
+
+			std::string localPath(rLocalDir + 
 				DIRECTORY_SEPARATOR + *i);
+			std::string localPathDisplay(localDirDisplay +
+				DIRECTORY_SEPARATOR + fileNameDisplay);
+			std::string storePathDisplay(storeDirDisplay +
+				"/" + fileNameDisplay);
+
 			// Should this be ignored (ie is excluded)?
 			if(rParams.mpExcludeFiles == 0 || 
-				!(rParams.mpExcludeFiles->IsExcluded(localFileName)))
+				!(rParams.mpExcludeFiles->IsExcluded(localPath)))
 			{
-				printf("Local file '%s" DIRECTORY_SEPARATOR
-					"%s' exists, but store file '%s/%s' "
+				printf("Local file '%s' exists, "
+					"but store file '%s' "
 					"does not exist.\n",
-					localName.c_str(), (*i).c_str(), 
-					storeName.c_str(), (*i).c_str());
+					localPathDisplay.c_str(),
+					storePathDisplay.c_str());
 				rParams.mDifferences ++;
 				
 				// Check the file modification time
 				{
 					struct stat st;
-					if(::stat(localFileName.c_str(), &st) == 0)
+					if(::stat(localPath.c_str(), &st) == 0)
 					{
 						if(FileModificationTime(st) > rParams.mLatestFileUploadTime)
 						{
@@ -1577,17 +1609,30 @@
 		// Now do the directories, recusively to check subdirectories
 		for(std::set<std::pair<std::string, BackupStoreDirectory::Entry *> >::const_iterator i = storeDirs.begin(); i != storeDirs.end(); ++i)
 		{
+#ifdef WIN32
+			// Directory name is also in UTF-8 encoding, 
+			// need to convert to console
+			std::string subdirNameDisplay;
+			if(!ConvertUtf8ToConsole(i->first, subdirNameDisplay))
+				return;
+#else
+			const std::string& subdirNameDisplay(i->first);
+#endif
+
+			std::string localPathDisplay = localDirDisplay +
+				DIRECTORY_SEPARATOR + subdirNameDisplay;
+			std::string storePathDisplay = storeDirDisplay +
+				"/" + subdirNameDisplay;
+
 			// Does the directory exist locally?
 			string_set_iter_t local(localDirs.find(i->first));
 			if(local == localDirs.end())
 			{
 				// Not found -- report
-				printf("Local directory '%s" 
-					DIRECTORY_SEPARATOR "%s' "
-					"does not exist, but store directory "
-					"'%s/%s' does.\n",
-					localName.c_str(), i->first.c_str(), 
-					storeName.c_str(), i->first.c_str());
+				printf("Local directory '%s' does not exist, "
+					"but store directory '%s' does.\n",
+					localPathDisplay.c_str(),
+					storePathDisplay.c_str());
 				rParams.mDifferences ++;
 			}
 			else
@@ -1603,14 +1648,33 @@
 		// Report any files which exist on the locally, but not on the store
 		for(std::set<std::string>::const_iterator i = localDirs.begin(); i != localDirs.end(); ++i)
 		{
-			std::string localName(rLocalDir + DIRECTORY_SEPARATOR + *i);
+#ifdef WIN32
+			// File name is also in UTF-8 encoding, 
+			// need to convert to console
+			std::string fileNameDisplay;
+			if(!ConvertUtf8ToConsole(*i, fileNameDisplay))
+				return;
+#else
+			const std::string& fileNameDisplay(*i);
+#endif
+
+			std::string localPath = rLocalDir +
+				DIRECTORY_SEPARATOR + *i;
+			std::string storePath = rStoreDir +
+				"/" + *i;
+
+			std::string localPathDisplay = localDirDisplay +
+				DIRECTORY_SEPARATOR + fileNameDisplay;
+			std::string storePathDisplay = storeDirDisplay +
+				"/" + fileNameDisplay;
+
 			// Should this be ignored (ie is excluded)?
-			if(rParams.mpExcludeDirs == 0 || !(rParams.mpExcludeDirs->IsExcluded(localName)))
+			if(rParams.mpExcludeDirs == 0 || !(rParams.mpExcludeDirs->IsExcluded(localPath)))
 			{
-				printf("Local directory '%s/%s' exists, but "
-					"store directory '%s/%s' does not exist.\n",
-					localName.c_str(), (*i).c_str(), 
-					storeName.c_str(), (*i).c_str());
+				printf("Local directory '%s' exists, but "
+					"store directory '%s' does not exist.\n",
+					localPathDisplay.c_str(),
+					storePathDisplay.c_str());
 				rParams.mDifferences ++;
 			}
 			else


From boxbackup-dev@fluffy.co.uk  Fri May  5 10:33:53 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Fri,  5 May 2006 09:33:53 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r562 - box/chris/general/bin/bbackupquery
Message-ID: <20060505093353.E2E8195@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-05 09:33:48 +0000 (Fri, 05 May 2006)
New Revision: 562

Modified:
   box/chris/general/bin/bbackupquery/BackupQueries.cpp
Log:
* BackupQueries.cpp
- Fixed compile errors on Windows (introduced by the last change)


Modified: box/chris/general/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/chris/general/bin/bbackupquery/BackupQueries.cpp	2006-05-04 22:07:48 UTC (rev 561)
+++ box/chris/general/bin/bbackupquery/BackupQueries.cpp	2006-05-05 09:33:48 UTC (rev 562)
@@ -1225,14 +1225,14 @@
 #ifdef WIN32
 	// By this point, rStoreDir and rLocalDir should be in UTF-8 encoding
 
-	std::string localName;
-	std::string storeName;
+	std::string localDirDisplay;
+	std::string storeDirDisplay;
 
-	if(!ConvertUtf8ToConsole(rLocalDir.c_str(), localName)) return;
-	if(!ConvertUtf8ToConsole(rStoreDir.c_str(), storeName)) return;
+	if(!ConvertUtf8ToConsole(rLocalDir.c_str(), localDirDisplay)) return;
+	if(!ConvertUtf8ToConsole(rStoreDir.c_str(), storeDirDisplay)) return;
 #else
-	const std::string& localName(rLocalDir);
-	const std::string& storeName(rStoreDir);
+	const std::string& localDirDisplay(rLocalDir);
+	const std::string& storeDirDisplay(rStoreDir);
 #endif
 
 	// Get info on the local directory
@@ -1244,19 +1244,21 @@
 		{
 			printf("Local object '%s' is a file, "
 				"server object '%s' is a directory\n", 
-				localName.c_str(), storeName.c_str());
+				localDirDisplay.c_str(), 
+				storeDirDisplay.c_str());
 			rParams.mDifferences ++;
 		}
 		else if(errno == ENOENT)
 		{
 			printf("Local directory '%s' does not exist "
 				"(compared to server directory '%s')\n",
-				localName.c_str(), storeName.c_str());
+				localDirDisplay.c_str(), 
+				storeDirDisplay.c_str());
 		}
 		else
 		{
 			printf("ERROR: stat on local dir '%s'\n", 
-				localName.c_str());
+				localDirDisplay.c_str());
 		}
 		return;
 	}
@@ -1277,7 +1279,7 @@
 	if(!dir.HasAttributes())
 	{
 		printf("Store directory '%s' doesn't have attributes.\n", 
-			storeName.c_str());
+			storeDirDisplay.c_str());
 	}
 	else
 	{
@@ -1294,7 +1296,8 @@
 		{
 			printf("Local directory '%s' has different attributes "
 				"to store directory '%s'.\n",
-				localName.c_str(), storeName.c_str());
+				localDirDisplay.c_str(), 
+				storeDirDisplay.c_str());
 			rParams.mDifferences ++;
 		}
 	}
@@ -1303,7 +1306,8 @@
 	DIR *dirhandle = ::opendir(rLocalDir.c_str());
 	if(dirhandle == 0)
 	{
-		printf("ERROR: opendir on local dir '%s'\n", localName.c_str());
+		printf("ERROR: opendir on local dir '%s'\n", 
+			localDirDisplay.c_str());
 		return;
 	}
 	try
@@ -1361,7 +1365,7 @@
 		if(::closedir(dirhandle) != 0)
 		{
 			printf("ERROR: closedir on local dir '%s'\n", 
-				localName.c_str());
+				localDirDisplay.c_str());
 		}
 		dirhandle = 0;
 	
@@ -1398,16 +1402,31 @@
 		// Now compare files.
 		for(std::set<std::pair<std::string, BackupStoreDirectory::Entry *> >::const_iterator i = storeFiles.begin(); i != storeFiles.end(); ++i)
 		{
+			const std::string& fileName(i->first);
+#ifdef WIN32
+			// File name is also in UTF-8 encoding, 
+			// need to convert to console
+			std::string fileNameDisplay;
+			if(!ConvertUtf8ToConsole(i->first.c_str(), 
+				fileNameDisplay)) return;
+#else
+			const std::string& fileNameDisplay(i->first);
+#endif
+
+			std::string localPathDisplay = localDirDisplay +
+				DIRECTORY_SEPARATOR + fileNameDisplay;
+			std::string storePathDisplay = storeDirDisplay +
+				"/" + fileNameDisplay;
+
 			// Does the file exist locally?
-			string_set_iter_t local(localFiles.find(i->first));
+			string_set_iter_t local(localFiles.find(fileName));
 			if(local == localFiles.end())
 			{
 				// Not found -- report
-				printf("Local file '%s" DIRECTORY_SEPARATOR 
-					"%s' does not exist, "
-					"but store file '%s/%s' does.\n",
-					localName.c_str(), i->first.c_str(), 
-					storeName.c_str(), i->first.c_str());
+				printf("Local file '%s' does not exist, "
+					"but store file '%s' does.\n",
+					localPathDisplay.c_str(),
+					storePathDisplay.c_str());
 				rParams.mDifferences ++;
 			}
 			else
@@ -1415,7 +1434,7 @@
 				try
 				{
 					// make local name of file for comparison
-					std::string localName(rLocalDir + DIRECTORY_SEPARATOR + i->first);
+					std::string localPath(rLocalDir + DIRECTORY_SEPARATOR + fileName);
 
 					// Files the same flag?
 					bool equal = true;
@@ -1432,7 +1451,7 @@
 						std::auto_ptr<IOStream> blockIndexStream(mrConnection.ReceiveStream());
 						
 						// Compare
-						equal = BackupStoreFile::CompareFileContentsAgainstBlockIndex(localName.c_str(), *blockIndexStream, mrConnection.GetTimeout());
+						equal = BackupStoreFile::CompareFileContentsAgainstBlockIndex(localPath.c_str(), *blockIndexStream, mrConnection.GetTimeout());
 					}
 					else
 					{
@@ -1467,17 +1486,17 @@
 						// Compare attributes
 						BackupClientFileAttributes localAttr;
 						box_time_t fileModTime = 0;
-						localAttr.ReadAttributes(localName.c_str(), false /* don't zero mod times */, &fileModTime);					
+						localAttr.ReadAttributes(localPath.c_str(), false /* don't zero mod times */, &fileModTime);					
 						modifiedAfterLastSync = (fileModTime > rParams.mLatestFileUploadTime);
 						if(!localAttr.Compare(fileOnServerStream->GetAttributes(),
 								true /* ignore attr mod time */,
 								fileOnServerStream->IsSymLink() /* ignore modification time if it's a symlink */))
 						{
-							printf("Local file '%s"
-								DIRECTORY_SEPARATOR
-								"%s' has different attributes "
-								"to store file '%s/%s'.\n",
-								localName.c_str(), i->first.c_str(), storeName.c_str(), i->first.c_str());						
+							printf("Local file '%s' "
+								"has different attributes "
+								"to store file '%s'.\n",
+								localPathDisplay.c_str(), 
+								storePathDisplay.c_str());						
 							rParams.mDifferences ++;
 							if(modifiedAfterLastSync)
 							{
@@ -1495,7 +1514,7 @@
 						if(!fileOnServerStream->IsSymLink())
 						{
 							// Open the local file
-							FileStream l(localName.c_str());
+							FileStream l(localPath.c_str());
 							
 							// Size
 							IOStream::pos_type fileSizeLocal = l.BytesLeftToRead();
@@ -1541,11 +1560,11 @@
 					// Report if not equal.
 					if(!equal)
 					{
-						printf("Local file '%s"
-							DIRECTORY_SEPARATOR
-							"%s' has different contents "
-							"to store file '%s/%s'.\n",
-							localName.c_str(), i->first.c_str(), storeName.c_str(), i->first.c_str());
+						printf("Local file '%s' "
+							"has different contents "
+							"to store file '%s'.\n",
+							localPathDisplay.c_str(), 
+							storePathDisplay.c_str());
 						rParams.mDifferences ++;
 						if(modifiedAfterLastSync)
 						{
@@ -1560,15 +1579,14 @@
 				}
 				catch(BoxException &e)
 				{
-					printf("ERROR: (%d/%d) during file fetch and comparsion for '%s/%s'\n",
+					printf("ERROR: (%d/%d) during file fetch and comparison for '%s'\n",
 						e.GetType(),
 						e.GetSubType(),
-						storeName.c_str(), 
-						i->first.c_str());
+						storePathDisplay.c_str());
 				}
 				catch(...)
 				{
-					printf("ERROR: (unknown) during file fetch and comparsion for '%s/%s'\n", storeName.c_str(), i->first.c_str());
+					printf("ERROR: (unknown) during file fetch and comparison for '%s'\n", storePathDisplay.c_str());
 				}
 
 				// Remove from set so that we know it's been compared
@@ -1579,23 +1597,38 @@
 		// Report any files which exist on the locally, but not on the store
 		for(string_set_iter_t i = localFiles.begin(); i != localFiles.end(); ++i)
 		{
-			std::string localFileName(rLocalDir + 
+#ifdef WIN32
+			// File name is also in UTF-8 encoding, 
+			// need to convert to console
+			std::string fileNameDisplay;
+			if(!ConvertUtf8ToConsole(i->c_str(), fileNameDisplay)) 
+				return;
+#else
+			const std::string& fileNameDisplay(*i);
+#endif
+
+			std::string localPath(rLocalDir + 
 				DIRECTORY_SEPARATOR + *i);
+			std::string localPathDisplay(localDirDisplay +
+				DIRECTORY_SEPARATOR + fileNameDisplay);
+			std::string storePathDisplay(storeDirDisplay +
+				"/" + fileNameDisplay);
+
 			// Should this be ignored (ie is excluded)?
 			if(rParams.mpExcludeFiles == 0 || 
-				!(rParams.mpExcludeFiles->IsExcluded(localFileName)))
+				!(rParams.mpExcludeFiles->IsExcluded(localPath)))
 			{
-				printf("Local file '%s" DIRECTORY_SEPARATOR
-					"%s' exists, but store file '%s/%s' "
+				printf("Local file '%s' exists, "
+					"but store file '%s' "
 					"does not exist.\n",
-					localName.c_str(), (*i).c_str(), 
-					storeName.c_str(), (*i).c_str());
+					localPathDisplay.c_str(),
+					storePathDisplay.c_str());
 				rParams.mDifferences ++;
 				
 				// Check the file modification time
 				{
 					struct stat st;
-					if(::stat(localFileName.c_str(), &st) == 0)
+					if(::stat(localPath.c_str(), &st) == 0)
 					{
 						if(FileModificationTime(st) > rParams.mLatestFileUploadTime)
 						{
@@ -1618,17 +1651,31 @@
 		// Now do the directories, recusively to check subdirectories
 		for(std::set<std::pair<std::string, BackupStoreDirectory::Entry *> >::const_iterator i = storeDirs.begin(); i != storeDirs.end(); ++i)
 		{
+#ifdef WIN32
+			// Directory name is also in UTF-8 encoding, 
+			// need to convert to console
+			std::string subdirNameDisplay;
+			if(!ConvertUtf8ToConsole(i->first.c_str(), 
+				subdirNameDisplay))
+				return;
+#else
+			const std::string& subdirNameDisplay(i->first);
+#endif
+
+			std::string localPathDisplay = localDirDisplay +
+				DIRECTORY_SEPARATOR + subdirNameDisplay;
+			std::string storePathDisplay = storeDirDisplay +
+				"/" + subdirNameDisplay;
+
 			// Does the directory exist locally?
 			string_set_iter_t local(localDirs.find(i->first));
 			if(local == localDirs.end())
 			{
 				// Not found -- report
-				printf("Local directory '%s" 
-					DIRECTORY_SEPARATOR "%s' "
-					"does not exist, but store directory "
-					"'%s/%s' does.\n",
-					localName.c_str(), i->first.c_str(), 
-					storeName.c_str(), i->first.c_str());
+				printf("Local directory '%s' does not exist, "
+					"but store directory '%s' does.\n",
+					localPathDisplay.c_str(),
+					storePathDisplay.c_str());
 				rParams.mDifferences ++;
 			}
 			else
@@ -1644,14 +1691,33 @@
 		// Report any files which exist on the locally, but not on the store
 		for(std::set<std::string>::const_iterator i = localDirs.begin(); i != localDirs.end(); ++i)
 		{
-			std::string localName(rLocalDir + DIRECTORY_SEPARATOR + *i);
+#ifdef WIN32
+			// File name is also in UTF-8 encoding, 
+			// need to convert to console
+			std::string fileNameDisplay;
+			if(!ConvertUtf8ToConsole(i->c_str(), fileNameDisplay))
+				return;
+#else
+			const std::string& fileNameDisplay(*i);
+#endif
+
+			std::string localPath = rLocalDir +
+				DIRECTORY_SEPARATOR + *i;
+			std::string storePath = rStoreDir +
+				"/" + *i;
+
+			std::string localPathDisplay = localDirDisplay +
+				DIRECTORY_SEPARATOR + fileNameDisplay;
+			std::string storePathDisplay = storeDirDisplay +
+				"/" + fileNameDisplay;
+
 			// Should this be ignored (ie is excluded)?
-			if(rParams.mpExcludeDirs == 0 || !(rParams.mpExcludeDirs->IsExcluded(localName)))
+			if(rParams.mpExcludeDirs == 0 || !(rParams.mpExcludeDirs->IsExcluded(localPath)))
 			{
-				printf("Local directory '%s/%s' exists, but "
-					"store directory '%s/%s' does not exist.\n",
-					localName.c_str(), (*i).c_str(), 
-					storeName.c_str(), (*i).c_str());
+				printf("Local directory '%s' exists, but "
+					"store directory '%s' does not exist.\n",
+					localPathDisplay.c_str(),
+					storePathDisplay.c_str());
 				rParams.mDifferences ++;
 			}
 			else


From boxbackup-dev@fluffy.co.uk  Fri May  5 10:34:45 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Fri,  5 May 2006 09:34:45 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r563 - box/chris/general/lib/win32
Message-ID: <20060505093445.9B53795@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-05 09:34:39 +0000 (Fri, 05 May 2006)
New Revision: 563

Modified:
   box/chris/general/lib/win32/emu.h
Log:
* emu.h
- Ensure that MinGW's dirent.h is never included on Win32


Modified: box/chris/general/lib/win32/emu.h
===================================================================
--- box/chris/general/lib/win32/emu.h	2006-05-05 09:33:48 UTC (rev 562)
+++ box/chris/general/lib/win32/emu.h	2006-05-05 09:34:39 UTC (rev 563)
@@ -249,6 +249,10 @@
 }
 #endif
 
+#ifdef _DIRENT_H_
+#error You must not include MinGW's dirent.h!
+#endif
+
 struct dirent
 {
 	char *d_name;


From boxbackup-dev@fluffy.co.uk  Fri May  5 10:35:27 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Fri,  5 May 2006 09:35:27 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r564 - box/chris/general
Message-ID: <20060505093527.B00E395@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-05 09:35:18 +0000 (Fri, 05 May 2006)
New Revision: 564

Modified:
   box/chris/general/configure.ac
Log:
* configure.ac
- Fixed test for regular expression library on Win32/MinGW


Modified: box/chris/general/configure.ac
===================================================================
--- box/chris/general/configure.ac	2006-05-05 09:34:39 UTC (rev 563)
+++ box/chris/general/configure.ac	2006-05-05 09:35:18 UTC (rev 564)
@@ -79,13 +79,15 @@
 
 AC_HEADER_STDC
 AC_HEADER_SYS_WAIT
-AC_CHECK_HEADERS([execinfo.h process.h pwd.h regex.h signal.h])
+AC_CHECK_HEADERS([execinfo.h process.h pwd.h signal.h])
 AC_CHECK_HEADERS([syslog.h time.h])
 AC_CHECK_HEADERS([netinet/in.h])
 AC_CHECK_HEADERS([sys/param.h sys/socket.h sys/time.h sys/types.h sys/wait.h])
 AC_CHECK_HEADERS([sys/xattr.h])
 
-if test "$ac_cv_header_regex_h" = "yes"; then
+AC_CHECK_HEADER([regex.h], [have_regex_h=yes])
+
+if test "$have_regex_h" = "yes"; then
   AC_SEARCH_LIBS([regcomp], [pcreposix])
 fi
 


From boxbackup-dev@fluffy.co.uk  Fri May  5 10:56:59 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Fri,  5 May 2006 09:56:59 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r565 - box/chris/win32/releases
Message-ID: <20060505095659.E6F1295@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-05 09:48:12 +0000 (Fri, 05 May 2006)
New Revision: 565

Added:
   box/chris/win32/releases/boxbackup-chris_general_564-backup-client-mingw32.zip
Log:
* boxbackup-chris_general_564-backup-client-mingw32.zip
- New release (r564)
- Fixed potential encoding problems when displaying filenames during compare
- Fixed wrong path reported on some compare errors


Added: box/chris/win32/releases/boxbackup-chris_general_564-backup-client-mingw32.zip
===================================================================
(Binary files differ)


Property changes on: box/chris/win32/releases/boxbackup-chris_general_564-backup-client-mingw32.zip
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream


From boxbackup-dev@fluffy.co.uk  Mon May  8 23:45:54 2006
From: boxbackup-dev@fluffy.co.uk (Chris Wilson)
Date: Mon, 8 May 2006 22:45:54 +0000 (GMT)
Subject: [Box Backup-dev] Re: how to deal with mountpoints
In-Reply-To: <445FBF90.6090301@logical-progress.com>
References: <445FBF90.6090301@logical-progress.com>
Message-ID: <Pine.LNX.4.64.0605082228420.24435@localhost>

Hi Dave,

On Mon, 8 May 2006, Dave Bamford wrote:

> I hope you don't mind me contacting you via private email but I don't 
> think this is relevant for the Box list.

Perhaps not for the users list, but I would say it definitely belongs on 
the developers' list, so I'm copying them in.

> I am porting the latest 0.10 client to OS/2 and got it through configure 
> but had to edit the configure file when it tests for mountpoints I 
> substituted OS2-EMX for WINNT in the condition so it did not exit.
>
> However coming to build the client it crashes out here
> BackupDaemon.cpp: In member function `void
>  BackupDaemon::SetupLocations(BackupClientContext&, const Configuration&)':
> BackupDaemon.cpp:1400: error: `mountPoints' undeclared (first use this
>  function)

You have "#undef HAVE_MOUNTS" in BoxConfig.h, so the definition of 
mountPoints is not compiled in. I suspect that the problem is this code, 
at line 1367 in trunk (maybe slightly different in 0.10):

 	for(; i != mountPoints.end(); ++i)

Just above it, at line 1338:

 	#if defined HAVE_STRUCT_STATFS_F_MNTONNAME || defined
 		HAVE_STRUCT_STATVFS_F_MNTONNAME || defined WIN32
 	// BSD style statfs -- includes mount point, which is nice.

We use a fake (emulated) statfs() function on Windows, which you can find 
in lib/win32/emu.cpp at line 758 or thereabouts. It uses the Windows API 
function GetFileInformationByHandle to return the volume identifier, and 
constructs a fake "mount point" for the file, based on the volume 
identifier.

I don't know what the OS/2 API is like, but you might want to do something 
similar there. I don't think you can safely disable the entire #if ... 
#endif chunk (lines 1338 - 1383 of BackupDaemon.cpp), but you could try it 
if all else fails, and define a fake value for mountName.

Cheers, Chris.
-- 
_ ___ __     _
  / __/ / ,__(_)_  | Chris Wilson <0000 at qwirx.com> - Cambs UK |
/ (_/ ,\/ _/ /_ \ | Security/C/C++/Java/Perl/SQL/HTML Developer |
\ _/_/_/_//_/___/ | We are GNU-free your mind-and your software |

From boxbackup-dev@fluffy.co.uk  Wed May 10 10:41:38 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Wed, 10 May 2006 09:41:38 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r566 - box/trunk/bin/bbackupquery
Message-ID: <20060510094138.36BF295@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-10 09:41:19 +0000 (Wed, 10 May 2006)
New Revision: 566

Modified:
   box/trunk/bin/bbackupquery/BackupQueries.cpp
Log:
* bin/bbackupquery/BackupQueries.cpp
- Win32 compile fixes


Modified: box/trunk/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/trunk/bin/bbackupquery/BackupQueries.cpp	2006-05-05 09:48:12 UTC (rev 565)
+++ box/trunk/bin/bbackupquery/BackupQueries.cpp	2006-05-10 09:41:19 UTC (rev 566)
@@ -1187,7 +1187,7 @@
 	std::string localDirDisplay;
 	std::string storeDirDisplay;
 
-	if(!ConvertUtf8ToConsole(rLocalDir.c_str(), localDirDirsplay)) return;
+	if(!ConvertUtf8ToConsole(rLocalDir.c_str(), localDirDisplay)) return;
 	if(!ConvertUtf8ToConsole(rStoreDir.c_str(), storeDirDisplay)) return;
 #else
 	const std::string& localDirDisplay(rLocalDir);
@@ -1560,7 +1560,8 @@
 			// File name is also in UTF-8 encoding, 
 			// need to convert to console
 			std::string fileNameDisplay;
-			if(!ConvertUtf8ToConsole(*i, fileNameDisplay)) return;
+			if(!ConvertUtf8ToConsole(i->c_str(), fileNameDisplay)) 
+				return;
 #else
 			const std::string& fileNameDisplay(*i);
 #endif
@@ -1613,7 +1614,8 @@
 			// Directory name is also in UTF-8 encoding, 
 			// need to convert to console
 			std::string subdirNameDisplay;
-			if(!ConvertUtf8ToConsole(i->first, subdirNameDisplay))
+			if(!ConvertUtf8ToConsole(i->first.c_str(), 
+				subdirNameDisplay))
 				return;
 #else
 			const std::string& subdirNameDisplay(i->first);
@@ -1652,7 +1654,7 @@
 			// File name is also in UTF-8 encoding, 
 			// need to convert to console
 			std::string fileNameDisplay;
-			if(!ConvertUtf8ToConsole(*i, fileNameDisplay))
+			if(!ConvertUtf8ToConsole(i->c_str(), fileNameDisplay))
 				return;
 #else
 			const std::string& fileNameDisplay(*i);


From boxbackup-dev@fluffy.co.uk  Wed May 10 20:24:16 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Wed, 10 May 2006 19:24:16 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r567 - box/trunk/bin/bbackupquery
Message-ID: <20060510192416.3EDE495@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-10 19:24:00 +0000 (Wed, 10 May 2006)
New Revision: 567

Modified:
   box/trunk/bin/bbackupquery/BackupQueries.cpp
Log:
* BackupQueries.cpp
- Check for d_type not working on this platform, and abort compare


Modified: box/trunk/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/trunk/bin/bbackupquery/BackupQueries.cpp	2006-05-10 09:41:19 UTC (rev 566)
+++ box/trunk/bin/bbackupquery/BackupQueries.cpp	2006-05-10 19:24:00 UTC (rev 567)
@@ -1282,6 +1282,17 @@
 				(localDirEn->d_name[1] == '\0' || (localDirEn->d_name[1] == '.' && localDirEn->d_name[2] == '\0')))
 			{
 				// ignore, it's . or ..
+				
+#ifdef HAVE_VALID_DIRENT_D_TYPE
+				if (localDirEn->d_type != DT_DIR)
+				{
+					fprintf(stderr, "ERROR: d_type does "
+						"not really work on your "
+						"platform. Reconfigure Box!\n");
+					return;
+				}
+#endif
+				
 				continue;
 			}
 
@@ -1305,7 +1316,7 @@
 			{
 			    // Directory
 			    localDirs.insert(std::string(localDirEn->d_name));
-			}			
+			}
 #else
 			// Entry -- file or dir?
 			if(localDirEn->d_type == DT_REG || localDirEn->d_type == DT_LNK)


From boxbackup-dev@fluffy.co.uk  Tue May 16 10:21:22 2006
From: boxbackup-dev@fluffy.co.uk (Dave Bamford)
Date: Tue, 16 May 2006 10:21:22 +0100
Subject: [Box Backup-dev] Re: how to deal with mountpoints
In-Reply-To: <Pine.LNX.4.64.0605082228420.24435@localhost>
References: <445FBF90.6090301@logical-progress.com> <Pine.LNX.4.64.0605082228420.24435@localhost>
Message-ID: <44699992.5040408@logical-progress.com>

Chris Wilson wrote:

> Hi Dave,
>
> On Mon, 8 May 2006, Dave Bamford wrote:
>
>> I hope you don't mind me contacting you via private email but I don't 
>> think this is relevant for the Box list.
>
>
> Perhaps not for the users list, but I would say it definitely belongs 
> on the developers' list, so I'm copying them in.
>
>> I am porting the latest 0.10 client to OS/2 and got it through 
>> configure but had to edit the configure file when it tests for 
>> mountpoints I substituted OS2-EMX for WINNT in the condition so it 
>> did not exit.
>>
>> However coming to build the client it crashes out here
>> BackupDaemon.cpp: In member function `void
>>  BackupDaemon::SetupLocations(BackupClientContext&, const 
>> Configuration&)':
>> BackupDaemon.cpp:1400: error: `mountPoints' undeclared (first use this
>>  function)
>
>
> You have "#undef HAVE_MOUNTS" in BoxConfig.h, so the definition of 
> mountPoints is not compiled in. I suspect that the problem is this 
> code, at line 1367 in trunk (maybe slightly different in 0.10):
>
>     for(; i != mountPoints.end(); ++i)
>
> Just above it, at line 1338:
>
>     #if defined HAVE_STRUCT_STATFS_F_MNTONNAME || defined
>         HAVE_STRUCT_STATVFS_F_MNTONNAME || defined WIN32
>     // BSD style statfs -- includes mount point, which is nice.
>
> We use a fake (emulated) statfs() function on Windows, which you can 
> find in lib/win32/emu.cpp at line 758 or thereabouts. It uses the 
> Windows API function GetFileInformationByHandle to return the volume 
> identifier, and constructs a fake "mount point" for the file, based on 
> the volume identifier.
>
> I don't know what the OS/2 API is like, but you might want to do 
> something similar there. I don't think you can safely disable the 
> entire #if ... #endif chunk (lines 1338 - 1383 of BackupDaemon.cpp), 
> but you could try it if all else fails, and define a fake value for 
> mountName.
>
> Cheers, Chris.

Hi Chris

I only just saw your reply in the list, monitoring emails is getting quite
time consuming.

Thanks for your reply - I got over the problem by editing the configure file
produced by autoconfigure and added os2-emx into this code

>   if test "$target_os" != "mingw32" -a "$target_os" != "os2-emx"; then
>     { { echo "$as_me:$LINENO: error: cannot work out how to discover 
> mount points on your platform" >&5
> echo "$as_me: error: cannot work out how to discover mount points on 
> your platform" >&2;}
>    { (exit 1); exit 1; }; }
>   fi

But I think the problem really got solved by fixing the build environment.

I did not have to change anything in BackupDaemon.cpp as some time ago I 
built a polling
routine which seems to work, just have to add -lpoll to the makefiles.
I built bbackupd.exe and bbackupquery.exe, both work with 2 exceptions 
for OS2.

In SocketStreamTLS::Close I had to comment out ::SSL_free(mpSSL) after 
the SocketStream::Close();
Not sure why, but with it in I got "Abnormal Program Termination"

The only other thing was making sure the files were opened with O_BINARY.

Running bbackupquery retrned errors on the get command until I commented
out the GetAttribute code from BackupStoreFile::DecodeFile. I need to 
look into
this as the attributes would be nice to have back

Can't generate the test code as I can't find a nanosleep() for OS/2.
And I also don't have a vfork (its on the todo list)

Cheers

Dave Bamford


From boxbackup-dev@fluffy.co.uk  Tue May 16 18:03:49 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue, 16 May 2006 17:03:49 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r568 - box/chris/general/bin/bbackupd
Message-ID: <20060516170349.A499495@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-16 17:03:42 +0000 (Tue, 16 May 2006)
New Revision: 568

Modified:
   box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp
   box/chris/general/bin/bbackupd/bbackupd.cpp
Log:
* bin/bbackupd/bbackupd.cpp
* bin/bbackupd/Win32ServiceFunctions.cpp
- Fixed handling of service installation where the configuration file is
  specified and the path contains spaces


Modified: box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp
===================================================================
--- box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp	2006-05-10 19:24:00 UTC (rev 567)
+++ box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp	2006-05-16 17:03:42 UTC (rev 568)
@@ -223,8 +223,9 @@
 
 	if (pConfigFileName != NULL)
 	{
-		cmdWithArgs += " ";
+		cmdWithArgs += " \"";
 		cmdWithArgs += pConfigFileName;
+		cmdWithArgs += "\"";
 	}
 
 	SC_HANDLE newService = CreateService(

Modified: box/chris/general/bin/bbackupd/bbackupd.cpp
===================================================================
--- box/chris/general/bin/bbackupd/bbackupd.cpp	2006-05-10 19:24:00 UTC (rev 567)
+++ box/chris/general/bin/bbackupd/bbackupd.cpp	2006-05-16 17:03:42 UTC (rev 568)
@@ -53,7 +53,7 @@
 	}
 
 	bool runAsWin32Service = false;
-	if ((argc == 2 || argc == 3) && ::strcmp(argv[1], "--service") == 0)
+	if (argc >= 2 && ::strcmp(argv[1], "--service") == 0)
 	{
 		runAsWin32Service = true;
 	}
@@ -81,7 +81,7 @@
 		syslog(LOG_INFO, "Box Backup service starting");
 
 		char* config = NULL;
-		if (argc == 3)
+		if (argc >= 3)
 		{
 			config = strdup(argv[2]);
 		}


From boxbackup-dev@fluffy.co.uk  Wed May 17 00:20:19 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue, 16 May 2006 23:20:19 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r569 - box/chris/win32/releases
Message-ID: <20060516232019.E57C395@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-16 23:10:09 +0000 (Tue, 16 May 2006)
New Revision: 569

Added:
   box/chris/win32/releases/boxbackup-chris_general_568-backup-client-mingw32.zip
Log:
* boxbackup-chris_general_568-backup-client-mingw32.zip
- Fixed regular expression problem in r564 by clean rebuild
- Fixed service installation with config file path containing spaces


Added: box/chris/win32/releases/boxbackup-chris_general_568-backup-client-mingw32.zip
===================================================================
(Binary files differ)


Property changes on: box/chris/win32/releases/boxbackup-chris_general_568-backup-client-mingw32.zip
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream


From boxbackup-dev@fluffy.co.uk  Thu May 18 22:21:31 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Thu, 18 May 2006 21:21:31 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r570 - box/chris/general/bin/bbackupd
Message-ID: <20060518212131.9C60D96@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-18 21:21:21 +0000 (Thu, 18 May 2006)
New Revision: 570

Modified:
   box/chris/general/bin/bbackupd/BackupClientContext.cpp
Log:
* BackupClientContext.cpp
- Exceeded Storage Limits should be a warning, not info


Modified: box/chris/general/bin/bbackupd/BackupClientContext.cpp
===================================================================
--- box/chris/general/bin/bbackupd/BackupClientContext.cpp	2006-05-16 23:10:09 UTC (rev 569)
+++ box/chris/general/bin/bbackupd/BackupClientContext.cpp	2006-05-18 21:21:21 UTC (rev 570)
@@ -176,7 +176,7 @@
 			// no -- flag so only things like deletions happen
 			mStorageLimitExceeded = true;
 			// Log
-			::syslog(LOG_INFO, "Exceeded storage limits on server -- not uploading changes to files");
+			::syslog(LOG_WARNING, "Exceeded storage limits on server -- not uploading changes to files");
 		}
 	}
 	catch(...)


From boxbackup-dev@fluffy.co.uk  Sat May 20 18:19:28 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 20 May 2006 17:19:28 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r571 - box/chris/general/docs/backup
Message-ID: <20060520171928.D5F9896@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-20 17:19:09 +0000 (Sat, 20 May 2006)
New Revision: 571

Modified:
   box/chris/general/docs/backup/win32_build_on_linux_using_mingw.txt
Log:
* win32_build_on_linux_using_mingw.txt
- Added instructions on building OpenSSL


Modified: box/chris/general/docs/backup/win32_build_on_linux_using_mingw.txt
===================================================================
--- box/chris/general/docs/backup/win32_build_on_linux_using_mingw.txt	2006-05-18 21:21:21 UTC (rev 570)
+++ box/chris/general/docs/backup/win32_build_on_linux_using_mingw.txt	2006-05-20 17:19:09 UTC (rev 571)
@@ -7,6 +7,11 @@
 - Fedora and SuSE users can download RPM packages from 
   [http://mirzam.it.vu.nl/mingw/]
 
+You will need to know the prefix used by the cross-compiler executables.
+It will usually be something like "ix86-mingw32*-". All the binaries in the
+cross-compiler package will start with this prefix. The documentation below
+assumes that it is "i386-mingw32-". Adjust to taste.
+
 Download Zlib from [http://www.zlib.net/], unpack and enter source directory:
 
 	export CC=i386-mingw32-gcc 
@@ -16,8 +21,19 @@
 	make
 	make install prefix=/usr/local/i386-mingw32
 
-Download OpenSSL 0.9.7 from 
+Download OpenSSL 0.9.8a from 
+[http://www.openssl.org/source/openssl-0.9.8b.tar.gz]
 
+Unpack and configure:
+
+	tar xzvf openssl-0.9.8b.tar.gz
+	cd openssl-0.9.8b
+	./Configure mingw
+	make makefile.one
+	wget http://bbdev.fluffy.co.uk/svn/box/chris/win32/support/openssl-0.9.8b-mingw-cross.patch
+	patch -p1 < openssl-0.9.8b-mingw-cross.patch
+	make -f makefile.one
+
 Configure Box with:
 
 	export CXX="i386-mingw32-g++"
@@ -27,5 +43,6 @@
 	export CXXFLAGS="-mthreads"
 	export LDFLAGS="-mthreads"
 	export LIBS="-lcrypto -lws2_32 -lgdi32"
+	(if you don't have a "configure" file, run "./bootstrap")
 	./configure --target=i386-mingw32
 	make CXX="$CXX" AR="$AR" RANLIB="$RANLIB"


From boxbackup-dev@fluffy.co.uk  Sat May 20 18:46:53 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 20 May 2006 17:46:53 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r572 - box/chris/win32/support
Message-ID: <20060520174653.8FA6396@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-20 17:46:07 +0000 (Sat, 20 May 2006)
New Revision: 572

Added:
   box/chris/win32/support/openssl-0.9.8b-mingw-cross.patch
Log:
* openssl-0.9.8b-mingw-cross.patch
- Added OpenSSL patch needed to cross-compile for Windows on Linux


Added: box/chris/win32/support/openssl-0.9.8b-mingw-cross.patch
===================================================================
--- box/chris/win32/support/openssl-0.9.8b-mingw-cross.patch	2006-05-20 17:19:09 UTC (rev 571)
+++ box/chris/win32/support/openssl-0.9.8b-mingw-cross.patch	2006-05-20 17:46:07 UTC (rev 572)
@@ -0,0 +1,324 @@
+diff -ru openssl-0.9.8b/makefile.one openssl-0.9.8b-mingw/makefile.one
+--- openssl-0.9.8b/makefile.one	2006-05-20 17:01:12.000000000 +0000
++++ openssl-0.9.8b-mingw/makefile.one	2006-05-20 16:41:31.000000000 +0000
+@@ -15,8 +15,8 @@
+ 
+ # Set your compiler options
+ PLATFORM=
+-CC=cc
+-CFLAG=-O -DTERMIO -DOPENSSL_NO_RC5 -DOPENSSL_NO_MDC2 -DOPENSSL_NO_KRB5 -DOPENSSL_NO_DYNAMIC_ENGINE    
++CC=i586-mingw32msvc-gcc
++CFLAG=-O -DOPENSSL_NO_RC5 -DOPENSSL_NO_MDC2 -DOPENSSL_NO_KRB5 -DOPENSSL_NO_DYNAMIC_ENGINE    
+ APP_CFLAG=
+ LIB_CFLAG=
+ SHLIB_CFLAG=
+@@ -24,7 +24,7 @@
+ SHLIB_EX_OBJ=
+ # add extra libraries to this define, for solaris -lsocket -lnsl would
+ # be added
+-EX_LIBS=
++EX_LIBS=-lgdi32 -lws2_32
+ 
+ # The OpenSSL directory
+ SRC_D=.
+@@ -65,11 +65,11 @@
+ PERL=perl
+ CP=/bin/cp
+ RM=/bin/rm -f
+-RANLIB=/usr/bin/ranlib
++RANLIB=i586-mingw32msvc-ranlib
+ MKDIR=-mkdir
+-MKLIB=ar r
++MKLIB=i586-mingw32msvc-ar r
+ MLFLAGS=
+-ASM=as
++ASM=i586-mingw32msvc-as
+ 
+ ######################################################
+ # You should not need to touch anything below this point
+@@ -160,7 +160,8 @@
+ 	$(INCO_D)/ui_compat.h $(INCO_D)/krb5_asn.h $(INCO_D)/store.h \
+ 	$(INCO_D)/pqueue.h $(INCO_D)/pq_compat.h $(INCO_D)/ssl.h \
+ 	$(INCO_D)/ssl2.h $(INCO_D)/ssl3.h $(INCO_D)/ssl23.h \
+-	$(INCO_D)/tls1.h $(INCO_D)/dtls1.h $(INCO_D)/kssl.h 
++	$(INCO_D)/tls1.h $(INCO_D)/dtls1.h $(INCO_D)/kssl.h \
++	$(INCO_D)/x509.h $(INCO_D)/x509_vfy.h 
+ 
+ T_OBJ=$(OBJ_D)/md2test.o \
+ 	$(OBJ_D)/md4test.o $(OBJ_D)/md5test.o $(OBJ_D)/shatest.o \
+@@ -361,7 +362,15 @@
+ 	$(OBJ_D)/str_meth.o $(OBJ_D)/str_mem.o $(OBJ_D)/pqueue.o \
+ 	$(OBJ_D)/e_4758cca.o $(OBJ_D)/e_aep.o $(OBJ_D)/e_atalla.o \
+ 	$(OBJ_D)/e_cswift.o $(OBJ_D)/e_gmp.o $(OBJ_D)/e_chil.o \
+-	$(OBJ_D)/e_nuron.o $(OBJ_D)/e_sureware.o $(OBJ_D)/e_ubsec.o 
++	$(OBJ_D)/e_nuron.o $(OBJ_D)/e_sureware.o $(OBJ_D)/e_ubsec.o \
++	$(OBJ_D)/x86cpuid-elf.o $(OBJ_D)/x509_err.o $(OBJ_D)/x509_obj.o \
++	$(OBJ_D)/x509_cmp.o $(OBJ_D)/x509_ext.o $(OBJ_D)/x509_v3.o \
++	$(OBJ_D)/x509name.o $(OBJ_D)/x509_def.o  $(OBJ_D)/x509_req.o \
++	$(OBJ_D)/x509_att.o $(OBJ_D)/x_all.o $(OBJ_D)/x509rset.o \
++	$(OBJ_D)/x509_vfy.o $(OBJ_D)/x509_vpm.o $(OBJ_D)/x509_trs.o \
++	$(OBJ_D)/x509_lu.o $(OBJ_D)/x509_d2.o $(OBJ_D)/by_dir.o \
++	$(OBJ_D)/by_file.o $(OBJ_D)/x509type.o $(OBJ_D)/x509_txt.o \
++	$(OBJ_D)/x509_set.o $(OBJ_D)/x509spki.o $(OBJ_D)/x509cset.o
+ 
+ T_EXE=$(TEST_D)/md2test \
+ 	$(TEST_D)/md4test $(TEST_D)/md5test $(TEST_D)/shatest \
+@@ -422,8 +431,7 @@
+ 
+ 
+ test: $(T_EXE)
+-	cd $(BIN_D)
+-	../ms/test
++	( cd $(BIN_D); ../ms/test.sh; )
+ 
+ clean:
+ 	$(RM) $(TMP_D)/*.*
+@@ -753,6 +761,12 @@
+ $(INCO_D)/x509v3.h: $(SRC_D)/crypto/x509v3/x509v3.h
+ 	$(CP) $(SRC_D)/crypto/x509v3/x509v3.h $(INCO_D)/x509v3.h
+ 
++$(INCO_D)/x509.h: $(SRC_D)/crypto/x509/x509.h
++	$(CP) $(SRC_D)/crypto/x509/x509.h $(INCO_D)/x509.h
++
++$(INCO_D)/x509_vfy.h: $(SRC_D)/crypto/x509/x509_vfy.h
++	$(CP) $(SRC_D)/crypto/x509/x509_vfy.h $(INCO_D)/x509_vfy.h
++
+ $(INCO_D)/conf.h: $(SRC_D)/crypto/conf/conf.h
+ 	$(CP) $(SRC_D)/crypto/conf/conf.h $(INCO_D)/conf.h
+ 
+@@ -2100,6 +2114,75 @@
+ $(OBJ_D)/x_x509.o: $(SRC_D)/crypto/asn1/x_x509.c
+ 	$(CC) -o $(OBJ_D)/x_x509.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/asn1/x_x509.c
+ 
++$(OBJ_D)/by_dir.o: $(SRC_D)/crypto/x509/by_dir.c
++	$(CC) -o $(OBJ_D)/by_dir.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/by_dir.c
++
++$(OBJ_D)/by_file.o: $(SRC_D)/crypto/x509/by_file.c
++	$(CC) -o $(OBJ_D)/by_file.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/by_file.c
++
++$(OBJ_D)/x509_att.o: $(SRC_D)/crypto/x509/x509_att.c
++	$(CC) -o $(OBJ_D)/x509_att.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509_att.c
++
++$(OBJ_D)/x509_cmp.o: $(SRC_D)/crypto/x509/x509_cmp.c
++	$(CC) -o $(OBJ_D)/x509_cmp.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509_cmp.c
++
++$(OBJ_D)/x509cset.o: $(SRC_D)/crypto/x509/x509cset.c
++	$(CC) -o $(OBJ_D)/x509cset.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509cset.c
++
++$(OBJ_D)/x509_d2.o: $(SRC_D)/crypto/x509/x509_d2.c
++	$(CC) -o $(OBJ_D)/x509_d2.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509_d2.c
++
++$(OBJ_D)/x509_def.o: $(SRC_D)/crypto/x509/x509_def.c
++	$(CC) -o $(OBJ_D)/x509_def.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509_def.c
++
++$(OBJ_D)/x509_err.o: $(SRC_D)/crypto/x509/x509_err.c
++	$(CC) -o $(OBJ_D)/x509_err.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509_err.c
++
++$(OBJ_D)/x509_ext.o: $(SRC_D)/crypto/x509/x509_ext.c
++	$(CC) -o $(OBJ_D)/x509_ext.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509_ext.c
++
++$(OBJ_D)/x509_lu.o: $(SRC_D)/crypto/x509/x509_lu.c
++	$(CC) -o $(OBJ_D)/x509_lu.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509_lu.c
++
++$(OBJ_D)/x509name.o: $(SRC_D)/crypto/x509/x509name.c
++	$(CC) -o $(OBJ_D)/x509name.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509name.c
++
++$(OBJ_D)/x509_obj.o: $(SRC_D)/crypto/x509/x509_obj.c
++	$(CC) -o $(OBJ_D)/x509_obj.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509_obj.c
++
++$(OBJ_D)/x509_req.o: $(SRC_D)/crypto/x509/x509_req.c
++	$(CC) -o $(OBJ_D)/x509_req.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509_req.c
++
++$(OBJ_D)/x509rset.o: $(SRC_D)/crypto/x509/x509rset.c
++	$(CC) -o $(OBJ_D)/x509rset.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509rset.c
++
++$(OBJ_D)/x509_set.o: $(SRC_D)/crypto/x509/x509_set.c
++	$(CC) -o $(OBJ_D)/x509_set.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509_set.c
++
++$(OBJ_D)/x509spki.o: $(SRC_D)/crypto/x509/x509spki.c
++	$(CC) -o $(OBJ_D)/x509spki.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509spki.c
++
++$(OBJ_D)/x509_trs.o: $(SRC_D)/crypto/x509/x509_trs.c
++	$(CC) -o $(OBJ_D)/x509_trs.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509_trs.c
++
++$(OBJ_D)/x509_txt.o: $(SRC_D)/crypto/x509/x509_txt.c
++	$(CC) -o $(OBJ_D)/x509_txt.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509_txt.c
++
++$(OBJ_D)/x509type.o: $(SRC_D)/crypto/x509/x509type.c
++	$(CC) -o $(OBJ_D)/x509type.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509type.c
++
++$(OBJ_D)/x509_v3.o: $(SRC_D)/crypto/x509/x509_v3.c
++	$(CC) -o $(OBJ_D)/x509_v3.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509_v3.c
++
++$(OBJ_D)/x509_vfy.o: $(SRC_D)/crypto/x509/x509_vfy.c
++	$(CC) -o $(OBJ_D)/x509_vfy.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509_vfy.c
++
++$(OBJ_D)/x509_vpm.o: $(SRC_D)/crypto/x509/x509_vpm.c
++	$(CC) -o $(OBJ_D)/x509_vpm.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x509_vpm.c
++
++$(OBJ_D)/x_all.o: $(SRC_D)/crypto/x509/x_all.c
++	$(CC) -o $(OBJ_D)/x_all.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/x509/x_all.c
++
+ $(OBJ_D)/x_x509a.o: $(SRC_D)/crypto/asn1/x_x509a.c
+ 	$(CC) -o $(OBJ_D)/x_x509a.o  $(LIB_CFLAGS) -c $(SRC_D)/crypto/asn1/x_x509a.c
+ 
+@@ -2647,3 +2730,9 @@
+ $(BIN_D)/$(E_EXE): $(E_OBJ) $(LIBS_DEP)
+ 	$(LINK) -o $(BIN_D)/$(E_EXE) $(LFLAGS) $(E_OBJ) $(L_LIBS) $(EX_LIBS)
+ 
++$(OBJ_D)/x86cpuid-elf.o: $(SRC_D)/crypto/x86cpuid-elf.s
++	$(CC) -o $(OBJ_D)/x86cpuid-elf.o $(LIB_CFLAGS) -c $(SRC_D)/crypto/x86cpuid-elf.s
++
++$(SRC_D)/crypto/x86cpuid-elf.s: $(SRC_D)/crypto/x86cpuid.pl $(SRC_D)/crypto/perlasm/x86asm.pl
++	( cd $(SRC_D)/crypto; $(PERL) x86cpuid.pl a.out $(CFLAGS) $(PROCESSOR) > x86cpuid-elf.s; )
++
+
+--- openssl-0.9.8b/ms/test.sh	1970-01-01 00:00:00.000000000 +0000
++++ openssl-0.9.8b-mingw/ms/test.sh	2006-05-20 16:59:05.000000000 +0000
+@@ -0,0 +1,146 @@
++#!/bin/sh
++
++test=../ms
++PATH=../ms:$PATH
++OPENSSL_CONF=../apps/openssl.cnf
++
++# run this from inside the bin directory
++
++echo rsa_test
++./rsa_test || exit 1
++
++echo destest
++./destest || exit 1
++
++echo ideatest
++./ideatest || exit 1
++
++echo bftest
++./bftest || exit 1
++
++echo shatest
++./shatest || exit 1
++
++echo sha1test
++./sha1test || exit 1
++
++echo md5test
++./md5test || exit 1
++
++echo md2test
++./md2test || exit 1
++
++echo rc2test
++./rc2test || exit 1
++
++echo rc4test
++./rc4test || exit 1
++
++echo randtest
++./randtest || exit 1
++
++echo dhtest
++./dhtest || exit 1
++
++echo exptest
++./exptest || exit 1
++
++echo dsatest
++./dsatest || exit 1
++
++echo ectest
++./ectest || exit 1
++
++# echo testenc
++# $test/testenc openssl || exit 1
++
++# echo testpem
++# $test/testpem openssl || exit 1
++
++echo verify
++cat ../certs/*.pem > cert.tmp
++./openssl verify -CAfile cert.tmp ../certs/*.pem || exit 1
++
++# echo testss
++# $test/testss openssl || exit 1
++
++SSL_TEST="./ssltest -key $test/keyU.ss -cert $test/certU.ss -c_key $test/keyU.ss -c_cert $test/certU.ss -CAfile $test/certCA.ss"
++
++echo test sslv2
++./ssltest -ssl2 || exit 1
++
++echo test sslv2 with server authentication
++$SSL_TEST -ssl2 -server_auth || exit 1
++
++echo test sslv2 with client authentication
++$SSL_TEST -ssl2 -client_auth || exit 1
++
++echo test sslv2 with both client and server authentication
++$SSL_TEST -ssl2 -server_auth -client_auth || exit 1
++
++echo test sslv3
++./ssltest -ssl3 || exit 1
++
++echo test sslv3 with server authentication
++$SSL_TEST -ssl3 -server_auth || exit 1
++
++echo test sslv3 with client authentication
++$SSL_TEST -ssl3 -client_auth || exit 1
++
++echo test sslv3 with both client and server authentication
++$SSL_TEST -ssl3 -server_auth -client_auth || exit 1
++
++echo test sslv2/sslv3
++./ssltest || exit 1
++
++echo test sslv2/sslv3 with server authentication
++$SSL_TEST -server_auth || exit 1
++
++echo test sslv2/sslv3 with client authentication
++$SSL_TEST -client_auth || exit 1
++
++echo test sslv2/sslv3 with both client and server authentication
++$SSL_TEST -server_auth -client_auth || exit 1
++
++echo test sslv2 via BIO pair
++./ssltest -bio_pair -ssl2 || exit 1
++
++echo test sslv2/sslv3 with 1024 bit DHE via BIO pair
++./ssltest -bio_pair -dhe1024dsa -v || exit 1
++
++echo test sslv2 with server authentication via BIO pair
++$SSL_TEST -bio_pair -ssl2 -server_auth || exit 1
++
++echo test sslv2 with client authentication via BIO pair
++$SSL_TEST -bio_pair -ssl2 -client_auth || exit 1
++
++echo test sslv2 with both client and server authentication via BIO pair
++$SSL_TEST -bio_pair -ssl2 -server_auth -client_auth || exit 1
++
++echo test sslv3 via BIO pair
++./ssltest -bio_pair -ssl3 || exit 1
++
++echo test sslv3 with server authentication via BIO pair
++$SSL_TEST -bio_pair -ssl3 -server_auth || exit 1
++
++echo test sslv3 with client authentication  via BIO pair
++$SSL_TEST -bio_pair -ssl3 -client_auth || exit 1
++
++echo test sslv3 with both client and server authentication via BIO pair
++$SSL_TEST -bio_pair -ssl3 -server_auth -client_auth || exit 1
++
++echo test sslv2/sslv3 via BIO pair
++./ssltest -bio_pair || exit 1
++
++echo test sslv2/sslv3 with server authentication
++$SSL_TEST -bio_pair -server_auth || exit 1
++
++echo test sslv2/sslv3 with client authentication via BIO pair
++$SSL_TEST -bio_pair -client_auth || exit 1
++
++echo test sslv2/sslv3 with both client and server authentication via BIO pair
++$SSL_TEST -bio_pair -server_auth -client_auth || exit 1
++
++rm cert.tmp
++
++echo passed all tests


From boxbackup-dev@fluffy.co.uk  Sat May 20 19:04:29 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 20 May 2006 18:04:29 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r573 - in box/chris/general: . infrastructure
Message-ID: <20060520180429.325A996@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-20 18:04:15 +0000 (Sat, 20 May 2006)
New Revision: 573

Modified:
   box/chris/general/configure.ac
   box/chris/general/infrastructure/makebuildenv.pl
   box/chris/general/modules.txt
   box/chris/general/parcels.txt
Log:
* configure.ac
* parcels.txt
* modules.txt
* infrastructure/makebuildenv.pl
- Fixes for cross-compiling from Ubuntu Breezy


Modified: box/chris/general/configure.ac
===================================================================
--- box/chris/general/configure.ac	2006-05-20 17:46:07 UTC (rev 572)
+++ box/chris/general/configure.ac	2006-05-20 18:04:15 UTC (rev 573)
@@ -30,10 +30,15 @@
 
 ### Checks for libraries.
 
-if test "$target_os" != "mingw32" -a "$target_os" != "winnt"; then
+case $target_os in
+mingw32*) ;;
+winnt)    ;;
+*)
   AC_SEARCH_LIBS([nanosleep], [rt], [ac_have_nanosleep=yes],
                  [AC_MSG_ERROR([[cannot find a short sleep function (nanosleep)]])])
-fi
+	;;
+esac
+
 AC_CHECK_LIB([z], [zlibVersion],, [AC_MSG_ERROR([[cannot find zlib]])])
 VL_LIB_READLINE([have_libreadline=yes], [have_libreadline=no])
 
@@ -73,9 +78,13 @@
 
 ### Checks for header files.
 
-if test "$target_os" != "mingw32"; then
+case $target_os in
+mingw32*) ;;
+winnt*)   ;;
+*)
   AC_HEADER_DIRENT
-fi
+  ;;
+esac
 
 AC_HEADER_STDC
 AC_HEADER_SYS_WAIT
@@ -121,14 +130,18 @@
 if test "x$ac_cv_c_bigendian" != "xyes"; then
   AX_BSWAP64
 fi
-if test "$target_os" != "mingw32"; then
+
+case $target_os in
+mingw32*) ;;
+winnt*)   ;;
+*)
   AX_RANDOM_DEVICE
-fi
-AX_CHECK_MOUNT_POINT(,[
-  if test "$target_os" != "mingw32" -a "$target_os" != "winnt"; then
+  AX_CHECK_MOUNT_POINT(,[
     AC_MSG_ERROR([[cannot work out how to discover mount points on your platform]])
-  fi
   ])
+;;
+esac
+
 AX_CHECK_MALLOC_WORKAROUND
 
 
@@ -166,13 +179,19 @@
 AC_CHECK_FUNCS([flock])
 AC_CHECK_DECLS([O_EXLOCK],,, [[#include <fcntl.h>]])
 AC_CHECK_DECLS([F_SETLK],,, [[#include <fcntl.h>]])
+
+case $target_os in
+mingw32*) ;;
+winnt*)   ;;
+*)
 if test "x$ac_cv_func_flock" != "xyes" && \
    test "x$ac_cv_have_decl_O_EXLOCK" != "xyes" && \
-   test "x$ac_cv_have_decl_F_SETLK" != "xyes" && \
-   test "$target_os" != "mingw32" -a "$target_os" != "winnt"
+   test "x$ac_cv_have_decl_F_SETLK" != "xyes"
 then
   AC_MSG_ERROR([[cannot work out how to do file locking on your platform]])
 fi
+;;
+esac
 
 ## Get tmpdir
 temp_directory_name="/tmp"

Modified: box/chris/general/infrastructure/makebuildenv.pl
===================================================================
--- box/chris/general/infrastructure/makebuildenv.pl	2006-05-20 17:46:07 UTC (rev 572)
+++ box/chris/general/infrastructure/makebuildenv.pl	2006-05-20 18:04:15 UTC (rev 573)
@@ -39,7 +39,7 @@
 my %env_flags;
 
 my $windows_include_path = "-I../../lib/win32 ";
-if ($target_os ne "mingw32" && $target_os ne "winnt")
+if ($target_os !~ m'^mingw32' && $target_os ne "winnt")
 {
 	$windows_include_path = "";
 	$env_flags{'IGNORE_lib/win32'} = 1;
@@ -484,7 +484,7 @@
 	my $debug_link_extra = ($target_is_library)?'':'../../debug/lib/debug/debug.a';
 
 	my $release_flags = "-O2";
-	if ($target_os eq "mingw32")
+	if ($target_os =~ m'^mingw32')
 	{
 		$release_flags = "-O0 -g";
 	}
@@ -498,6 +498,7 @@
 CXX = g++
 AR = ar
 RANLIB = ranlib
+WINDRES = windres
 .ifdef RELEASE
 CXXFLAGS = -DNDEBUG $release_flags -Wall $include_paths $extra_platform_defines -DBOX_VERSION="\\"$product_version\\""
 OUTBASE = ../../release
@@ -569,8 +570,9 @@
 	{
 		my $is_cpp = $file =~ m/\A(.+)\.cpp\Z/i;
 		my $is_rc  = $file =~ m/\A(.+)\.rc\Z/i;
+		my $base = $1;
 
-		if ($target_os eq "mingw32")
+		if ($target_os =~ m'^mingw32')
 		{
 			next if not $is_cpp and not $is_rc;
 		}
@@ -582,7 +584,6 @@
 		next if $file =~ /\A\._/; # Temp Mac OS Resource hack
 
 		# store for later
-		my $base = $1;
 		push @obj_base,$base;
 	
 		# get the file...
@@ -619,7 +620,7 @@
 		}
 		elsif ($is_rc)
 		{
-			$make .= "\twindres $file $out_name\n\n";
+			$make .= "\t\$(WINDRES) $file $out_name\n\n";
 			my $res_list = $module_resources_win32{$mod};
 			$res_list ||= [];
 			push @$res_list, $base.'.o';
@@ -682,7 +683,7 @@
 	print MAKE " ",$lib_files unless $target_is_library;
 	print MAKE "\n";
 	
-	if ($target_os eq "mingw32")
+	if ($target_os =~ m'^mingw32')
 	{
 		foreach my $dep (@all_deps_for_module)
 		{

Modified: box/chris/general/modules.txt
===================================================================
--- box/chris/general/modules.txt	2006-05-20 17:46:07 UTC (rev 572)
+++ box/chris/general/modules.txt	2006-05-20 18:04:15 UTC (rev 573)
@@ -10,6 +10,7 @@
 # Generic support code and modules
 
 OMIT:mingw32
+OMIT:mingw32msvc
 OMIT:CYGWIN
 lib/raidfile
 END-OMIT
@@ -23,6 +24,7 @@
 test/compress		lib/compress	lib/win32
 
 OMIT:mingw32
+OMIT:mingw32msvc
 test/basicserver	lib/server	lib/win32
 OMIT:CYGWIN
 test/raidfile		lib/raidfile
@@ -35,6 +37,7 @@
 lib/backupclient	lib/server	lib/crypto	lib/compress
 
 OMIT:mingw32
+OMIT:mingw32msvc
 OMIT:CYGWIN
 lib/backupstore		lib/server	lib/raidfile	lib/backupclient
 bin/bbstored		lib/raidfile	lib/server	lib/backupstore	lib/backupclient	lib/win32
@@ -47,6 +50,7 @@
 bin/bbackupctl		lib/server	lib/backupclient	lib/win32
 
 OMIT:mingw32
+OMIT:mingw32msvc
 OMIT:CYGWIN
 test/backupstore	bin/bbstored	bin/bbstoreaccounts lib/server lib/backupstore lib/backupclient lib/raidfile
 test/backupstorefix	bin/bbstored	bin/bbstoreaccounts	lib/backupstore	lib/raidfile	bin/bbackupquery	bin/bbackupd

Modified: box/chris/general/parcels.txt
===================================================================
--- box/chris/general/parcels.txt	2006-05-20 17:46:07 UTC (rev 572)
+++ box/chris/general/parcels.txt	2006-05-20 18:04:15 UTC (rev 573)
@@ -9,16 +9,20 @@
 	bin bbackupctl
 	script bin/bbackupd/bbackupd-config
 
-ONLY:mingw32
+ONLY:mingw32,mingw32msvc
 	script bin/bbackupd/win32/installer.iss 
 	script bin/bbackupd/win32/ReadMe.txt 
 	script bin/bbackupd/win32/bbackupd.conf
+END-ONLY
+
+ONLY:mingw32
 	script /bin/mgwz.dll
 	script /bin/mingwm10.dll
 	optional script /bin/pcreposix.dll
 END-ONLY
 
 OMIT:mingw32
+OMIT:mingw32msvc
 OMIT:CYGWIN
 
 backup-server


From boxbackup-dev@fluffy.co.uk  Sat May 20 19:10:46 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 20 May 2006 18:10:46 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r574 - box/chris/general/docs/backup
Message-ID: <20060520181046.B56CE96@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-20 18:10:38 +0000 (Sat, 20 May 2006)
New Revision: 574

Modified:
   box/chris/general/docs/backup/win32_build_on_linux_using_mingw.txt
Log:
* win32_build_on_linux_using_mingw.txt
- Small but important typo


Modified: box/chris/general/docs/backup/win32_build_on_linux_using_mingw.txt
===================================================================
--- box/chris/general/docs/backup/win32_build_on_linux_using_mingw.txt	2006-05-20 18:04:15 UTC (rev 573)
+++ box/chris/general/docs/backup/win32_build_on_linux_using_mingw.txt	2006-05-20 18:10:38 UTC (rev 574)
@@ -21,7 +21,7 @@
 	make
 	make install prefix=/usr/local/i386-mingw32
 
-Download OpenSSL 0.9.8a from 
+Download OpenSSL 0.9.8b from 
 [http://www.openssl.org/source/openssl-0.9.8b.tar.gz]
 
 Unpack and configure:
@@ -45,4 +45,4 @@
 	export LIBS="-lcrypto -lws2_32 -lgdi32"
 	(if you don't have a "configure" file, run "./bootstrap")
 	./configure --target=i386-mingw32
-	make CXX="$CXX" AR="$AR" RANLIB="$RANLIB"
+	make CXX="$CXX" AR="$AR" RANLIB="$RANLIB" WINDRES="i386-mingw32-windres"


From boxbackup-dev@fluffy.co.uk  Sat May 20 19:58:53 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 20 May 2006 18:58:53 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r575 - in box/chris/general: . lib/common lib/raidfile lib/win32 test/raidfile
Message-ID: <20060520185853.4768696@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-20 18:58:21 +0000 (Sat, 20 May 2006)
New Revision: 575

Modified:
   box/chris/general/configure.ac
   box/chris/general/lib/common/BoxPlatform.h
   box/chris/general/lib/raidfile/RaidFileRead.cpp
   box/chris/general/lib/raidfile/RaidFileWrite.cpp
   box/chris/general/lib/win32/emu.cpp
   box/chris/general/lib/win32/emu.h
   box/chris/general/modules.txt
   box/chris/general/test/raidfile/intercept.cpp
   box/chris/general/test/raidfile/testraidfile.cpp
Log:
* test/raidfile/testraidfile.cpp
* test/raidfile/intercept.cpp
* modules.txt
* configure.ac
* lib/raidfile/RaidFileWrite.cpp
* lib/raidfile/RaidFileRead.cpp
* lib/win32/emu.cpp
* lib/win32/emu.h
* lib/common/BoxPlatform.h
- Made raidfile and tests compile on Win32


Modified: box/chris/general/configure.ac
===================================================================
--- box/chris/general/configure.ac	2006-05-20 18:10:38 UTC (rev 574)
+++ box/chris/general/configure.ac	2006-05-20 18:58:21 UTC (rev 575)
@@ -92,7 +92,7 @@
 AC_CHECK_HEADERS([syslog.h time.h])
 AC_CHECK_HEADERS([netinet/in.h])
 AC_CHECK_HEADERS([sys/param.h sys/socket.h sys/time.h sys/types.h sys/wait.h])
-AC_CHECK_HEADERS([sys/xattr.h])
+AC_CHECK_HEADERS([sys/uio.h sys/xattr.h])
 
 AC_CHECK_HEADER([regex.h], [have_regex_h=yes])
 

Modified: box/chris/general/lib/common/BoxPlatform.h
===================================================================
--- box/chris/general/lib/common/BoxPlatform.h	2006-05-20 18:10:38 UTC (rev 574)
+++ box/chris/general/lib/common/BoxPlatform.h	2006-05-20 18:58:21 UTC (rev 575)
@@ -41,7 +41,7 @@
 #endif
 
 // Slight hack; disable interception on Darwin within raidfile test
-#ifdef __APPLE__
+#if defined __APPLE__ || defined WIN32
 	// TODO: Replace with autoconf test
 	#define PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE
 #endif

Modified: box/chris/general/lib/raidfile/RaidFileRead.cpp
===================================================================
--- box/chris/general/lib/raidfile/RaidFileRead.cpp	2006-05-20 18:10:38 UTC (rev 574)
+++ box/chris/general/lib/raidfile/RaidFileRead.cpp	2006-05-20 18:58:21 UTC (rev 575)
@@ -14,10 +14,20 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <sys/stat.h>
+
+#ifdef HAVE_SYS_UIO_H
 #include <sys/uio.h>
+#endif
+
+#ifdef HAVE_SYSLOG_H
 #include <syslog.h>
+#endif
+
 #include <stdarg.h>
+
+#ifdef HAVE_DIRENT_H
 #include <dirent.h>
+#endif
 
 #include <stdio.h>
 #include <string.h>

Modified: box/chris/general/lib/raidfile/RaidFileWrite.cpp
===================================================================
--- box/chris/general/lib/raidfile/RaidFileWrite.cpp	2006-05-20 18:10:38 UTC (rev 574)
+++ box/chris/general/lib/raidfile/RaidFileWrite.cpp	2006-05-20 18:58:21 UTC (rev 575)
@@ -115,7 +115,7 @@
 #ifdef HAVE_FLOCK
 	int errnoBlock = EWOULDBLOCK;
 	if(::flock(mOSFileHandle, LOCK_EX | LOCK_NB) != 0)
-#else
+#elif HAVE_DECL_F_SETLK
 	int errnoBlock = EAGAIN;
 	struct flock desc;
 	desc.l_type = F_WRLCK;
@@ -123,6 +123,9 @@
 	desc.l_start = 0;
 	desc.l_len = 0;
 	if(::fcntl(mOSFileHandle, F_SETLK, &desc) != 0)
+#else
+	int errnoBlock = ENOSYS;
+	if (0)
 #endif
 	{
 		// Lock was not obtained.

Modified: box/chris/general/lib/win32/emu.cpp
===================================================================
--- box/chris/general/lib/win32/emu.cpp	2006-05-20 18:10:38 UTC (rev 574)
+++ box/chris/general/lib/win32/emu.cpp	2006-05-20 18:58:21 UTC (rev 575)
@@ -1374,4 +1374,40 @@
 	return strlen(pBuffer);
 }
 
+int readv (int filedes, const struct iovec *vector, size_t count)
+{
+	int bytes = 0;
+	
+	for (int i = 0; i < count; i++)
+	{
+		int result = read(filedes, vector[i].iov_base, 
+			vector[i].iov_len);
+		if (result < 0)
+		{
+			return result;
+		}
+		bytes += result;
+	}
+
+	return bytes;
+}
+
+int writev(int filedes, const struct iovec *vector, size_t count)
+{
+	int bytes = 0;
+	
+	for (int i = 0; i < count; i++)
+	{
+		int result = write(filedes, vector[i].iov_base, 
+			vector[i].iov_len);
+		if (result < 0)
+		{
+			return result;
+		}
+		bytes += result;
+	}
+
+	return bytes;
+}
+
 #endif // WIN32

Modified: box/chris/general/lib/win32/emu.h
===================================================================
--- box/chris/general/lib/win32/emu.h	2006-05-20 18:10:38 UTC (rev 574)
+++ box/chris/general/lib/win32/emu.h	2006-05-20 18:58:21 UTC (rev 575)
@@ -278,6 +278,7 @@
 #define LOG_WARNING 4
 #define LOG_ERR 3
 #define LOG_PID 0
+#define LOG_LOCAL5 0
 #define LOG_LOCAL6 0
 
 void openlog (const char * daemonName, int, int);
@@ -409,4 +410,12 @@
 // replacement for _cgetws which requires a relatively recent C runtime lib
 int console_read(char* pBuffer, size_t BufferSize);
 
+struct iovec {
+	void *iov_base;   /* Starting address */
+	size_t iov_len;   /* Number of bytes */
+};
+
+int readv (int filedes, const struct iovec *vector, size_t count);
+int writev(int filedes, const struct iovec *vector, size_t count);
+
 #endif // !EMU_INCLUDE && WIN32

Modified: box/chris/general/modules.txt
===================================================================
--- box/chris/general/modules.txt	2006-05-20 18:10:38 UTC (rev 574)
+++ box/chris/general/modules.txt	2006-05-20 18:58:21 UTC (rev 575)
@@ -9,10 +9,8 @@
 
 # Generic support code and modules
 
-OMIT:mingw32
-OMIT:mingw32msvc
 OMIT:CYGWIN
-lib/raidfile
+lib/raidfile		lib/win32
 END-OMIT
 
 lib/crypto
@@ -26,8 +24,10 @@
 OMIT:mingw32
 OMIT:mingw32msvc
 test/basicserver	lib/server	lib/win32
+END-OMIT
+
 OMIT:CYGWIN
-test/raidfile		lib/raidfile
+test/raidfile		lib/raidfile	lib/win32
 END-OMIT
 
 # IF_DISTRIBUTION(boxbackup)

Modified: box/chris/general/test/raidfile/intercept.cpp
===================================================================
--- box/chris/general/test/raidfile/intercept.cpp	2006-05-20 18:10:38 UTC (rev 574)
+++ box/chris/general/test/raidfile/intercept.cpp	2006-05-20 18:58:21 UTC (rev 575)
@@ -14,7 +14,11 @@
 #endif
 #include <sys/types.h>
 #include <unistd.h>
+
+#ifdef HAVE_SYS_UIO_H
 #include <sys/uio.h>
+#endif
+
 #include <errno.h>
 
 #ifndef PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE

Modified: box/chris/general/test/raidfile/testraidfile.cpp
===================================================================
--- box/chris/general/test/raidfile/testraidfile.cpp	2006-05-20 18:10:38 UTC (rev 574)
+++ box/chris/general/test/raidfile/testraidfile.cpp	2006-05-20 18:58:21 UTC (rev 575)
@@ -12,7 +12,10 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
+
+#ifdef HAVE_SYSCALL
 #include <sys/syscall.h>
+#endif
 
 #include <string.h>
 


From boxbackup-dev@fluffy.co.uk  Sat May 20 20:09:05 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 20 May 2006 19:09:05 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r576 - box/chris/general
Message-ID: <20060520190905.B285F96@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-20 19:08:55 +0000 (Sat, 20 May 2006)
New Revision: 576

Modified:
   box/chris/general/configure.ac
Log:
* configure.ac
- Cosmetic fix to the message when BDB not found


Modified: box/chris/general/configure.ac
===================================================================
--- box/chris/general/configure.ac	2006-05-20 18:58:21 UTC (rev 575)
+++ box/chris/general/configure.ac	2006-05-20 19:08:55 UTC (rev 576)
@@ -43,7 +43,7 @@
 VL_LIB_READLINE([have_libreadline=yes], [have_libreadline=no])
 
 ## Check for Berkely DB. Restrict to certain versions
-AX_PATH_BDB(, [
+AX_PATH_BDB("1.x or 4.1", [
   LIBS="$BDB_LIBS $LIBS"
   LDFLAGS="$BDB_LDFLAGS $LDFLAGS"
   CPPFLAGS="$CPPFLAGS $BDB_CPPFLAGS"


From boxbackup-dev@fluffy.co.uk  Sun May 21 04:46:38 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun, 21 May 2006 03:46:38 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r577 - in box/chris/general: . lib/common lib/raidfile test/raidfile test/raidfile/testfiles
Message-ID: <20060521034638.E6CC996@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-21 03:45:48 +0000 (Sun, 21 May 2006)
New Revision: 577

Modified:
   box/chris/general/lib/common/Guards.h
   box/chris/general/lib/raidfile/RaidFileRead.cpp
   box/chris/general/lib/raidfile/RaidFileWrite.cpp
   box/chris/general/modules.txt
   box/chris/general/test/raidfile/testfiles/raidfile.conf
   box/chris/general/test/raidfile/testraidfile.cpp
Log:
* modules.txt
- Enabled lib/raidfile on Cygwin: it's not a supported target platform any 
  more, and we want to build Box (cross-compile) from it

* test/raidfile/testraidfile.cpp
- Fixed tests using Unix path separator, and other Windows bugs

* test/raidfile/testfiles/raidfile.conf
- Changed paths to work on Windows

* lib/raidfile/RaidFileWrite.cpp
* lib/raidfile/RaidFileRead.cpp
* lib/common/Guards.h
- Fixed opening files in text mode by default, and other things that don't
  work on Windows, like renaming open files and renaming over existing files.


Modified: box/chris/general/lib/common/Guards.h
===================================================================
--- box/chris/general/lib/common/Guards.h	2006-05-20 19:08:55 UTC (rev 576)
+++ box/chris/general/lib/common/Guards.h	2006-05-21 03:45:48 UTC (rev 577)
@@ -24,7 +24,7 @@
 
 #include "MemLeakFindOn.h"
 
-template <int flags = O_RDONLY, int mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)>
+template <int flags = O_RDONLY | O_BINARY, int mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)>
 class FileHandleGuard
 {
 public:

Modified: box/chris/general/lib/raidfile/RaidFileRead.cpp
===================================================================
--- box/chris/general/lib/raidfile/RaidFileRead.cpp	2006-05-20 19:08:55 UTC (rev 576)
+++ box/chris/general/lib/raidfile/RaidFileRead.cpp	2006-05-21 03:45:48 UTC (rev 577)
@@ -593,7 +593,8 @@
 
 	// Open the parity file
 	std::string parityFilename(RaidFileUtil::MakeRaidComponentName(rdiscSet, mFilename, (2 + startDisc) % READ_NUMBER_DISCS_REQUIRED));
-	mParityHandle = ::open(parityFilename.c_str(), O_RDONLY, 0555);
+	mParityHandle = ::open(parityFilename.c_str(), 
+		O_RDONLY | O_BINARY, 0555);
 	if(mParityHandle == -1)
 	{
 		THROW_EXCEPTION(RaidFileException, OSError)
@@ -1027,7 +1028,8 @@
 		std::string writeFilename(RaidFileUtil::MakeWriteFileName(rdiscSet, Filename));
 
 		// Attempt to open
-		int osFileHandle = ::open(writeFilename.c_str(), O_RDONLY, 0);
+		int osFileHandle = ::open(writeFilename.c_str(), 
+			O_RDONLY | O_BINARY, 0);
 		if(osFileHandle == -1)
 		{
 			THROW_EXCEPTION(RaidFileException, ErrorOpeningFileForRead)
@@ -1065,13 +1067,15 @@
 		try
 		{
 			// Open stripe1
-			stripe1 = ::open(stripe1Filename.c_str(), O_RDONLY, 0555);
+			stripe1 = ::open(stripe1Filename.c_str(), 
+				O_RDONLY | O_BINARY, 0555);
 			if(stripe1 == -1)
 			{
 				stripe1errno = errno;
 			}
 			// Open stripe2
-			stripe2 = ::open(stripe2Filename.c_str(), O_RDONLY, 0555);
+			stripe2 = ::open(stripe2Filename.c_str(), 
+				O_RDONLY | O_BINARY, 0555);
 			if(stripe2 == -1)
 			{
 				stripe2errno = errno;
@@ -1179,7 +1183,8 @@
 			// Open stripe1?
 			if(existingFiles & RaidFileUtil::Stripe1Exists)
 			{
-				stripe1 = ::open(stripe1Filename.c_str(), O_RDONLY, 0555);
+				stripe1 = ::open(stripe1Filename.c_str(), 
+					O_RDONLY | O_BINARY, 0555);
 				if(stripe1 == -1)
 				{
 					THROW_EXCEPTION(RaidFileException, OSError)
@@ -1188,14 +1193,16 @@
 			// Open stripe2?
 			if(existingFiles & RaidFileUtil::Stripe2Exists)
 			{
-				stripe2 = ::open(stripe2Filename.c_str(), O_RDONLY, 0555);
+				stripe2 = ::open(stripe2Filename.c_str(), 
+					O_RDONLY | O_BINARY, 0555);
 				if(stripe2 == -1)
 				{
 					THROW_EXCEPTION(RaidFileException, OSError)
 				}
 			}
 			// Open parity
-			parity = ::open(parityFilename.c_str(), O_RDONLY, 0555);
+			parity = ::open(parityFilename.c_str(), 
+				O_RDONLY | O_BINARY, 0555);
 			if(parity == -1)
 			{
 				THROW_EXCEPTION(RaidFileException, OSError)

Modified: box/chris/general/lib/raidfile/RaidFileWrite.cpp
===================================================================
--- box/chris/general/lib/raidfile/RaidFileWrite.cpp	2006-05-20 19:08:55 UTC (rev 576)
+++ box/chris/general/lib/raidfile/RaidFileWrite.cpp	2006-05-21 03:45:48 UTC (rev 577)
@@ -104,7 +104,8 @@
 	writeFilename += 'X';
 
 	// Attempt to open
-	mOSFileHandle = ::open(writeFilename.c_str(), O_WRONLY | O_CREAT,
+	mOSFileHandle = ::open(writeFilename.c_str(), 
+		O_WRONLY | O_CREAT | O_BINARY,
 		S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
 	if(mOSFileHandle == -1)
 	{
@@ -245,23 +246,46 @@
 	}
 	
 	// Rename it into place -- BEFORE it's closed so lock remains
+
+#ifdef WIN32
+	// Except on Win32 which doesn't allow renaming open files
+	// Close file...
+	if(::close(mOSFileHandle) != 0)
+	{
+		THROW_EXCEPTION(RaidFileException, OSError)
+	}
+	mOSFileHandle = -1;
+#endif // WIN32
+
 	RaidFileController &rcontroller(RaidFileController::GetController());
 	RaidFileDiscSet rdiscSet(rcontroller.GetDiscSet(mSetNumber));
 	// Get the filename for the write file
 	std::string renameTo(RaidFileUtil::MakeWriteFileName(rdiscSet, mFilename));
 	// And the current name
 	std::string renameFrom(renameTo + 'X');
+
+#ifdef WIN32
+	// need to delete the target first
+	if(::unlink(renameTo.c_str()) != 0 && 
+		GetLastError() != ERROR_FILE_NOT_FOUND)
+	{
+		THROW_EXCEPTION(RaidFileException, OSError)
+	}
+#endif
+
 	if(::rename(renameFrom.c_str(), renameTo.c_str()) != 0)
 	{
 		THROW_EXCEPTION(RaidFileException, OSError)
 	}
-	
+
+#ifndef WIN32	
 	// Close file...
 	if(::close(mOSFileHandle) != 0)
 	{
 		THROW_EXCEPTION(RaidFileException, OSError)
 	}
 	mOSFileHandle = -1;
+#endif // !WIN32
 	
 	// Raid it?
 	if(ConvertToRaidNow)
@@ -295,12 +319,19 @@
 	writeFilename += 'X';
 	
 	// Unlink and close it
-	if((::unlink(writeFilename.c_str()) != 0)
-		|| (::close(mOSFileHandle) != 0))
+
+#ifdef WIN32
+	// On Win32 we must close it first
+	if (::close(mOSFileHandle) != 0 ||
+		::unlink(writeFilename.c_str()) != 0)
+#else // !WIN32
+	if (::unlink(writeFilename.c_str()) != 0 ||
+		::close(mOSFileHandle) != 0))
+#endif // !WIN32
 	{
 		THROW_EXCEPTION(RaidFileException, OSError)
 	}
-	
+
 	// reset file handle
 	mOSFileHandle = -1;
 }
@@ -391,13 +422,13 @@
 	try
 	{
 #if HAVE_DECL_O_EXLOCK
-		FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK)> stripe1(stripe1FilenameW.c_str());
-		FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK)> stripe2(stripe2FilenameW.c_str());
-		FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK)> parity(parityFilenameW.c_str());
+		FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK | O_BINARY)> stripe1(stripe1FilenameW.c_str());
+		FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK | O_BINARY)> stripe2(stripe2FilenameW.c_str());
+		FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK | O_BINARY)> parity(parityFilenameW.c_str());
 #else
-		FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> stripe1(stripe1FilenameW.c_str());
-		FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> stripe2(stripe2FilenameW.c_str());
-		FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> parity(parityFilenameW.c_str());
+		FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_BINARY)> stripe1(stripe1FilenameW.c_str());
+		FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_BINARY)> stripe2(stripe2FilenameW.c_str());
+		FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_BINARY)> parity(parityFilenameW.c_str());
 #endif
 
 		// Then... read in data...

Modified: box/chris/general/modules.txt
===================================================================
--- box/chris/general/modules.txt	2006-05-20 19:08:55 UTC (rev 576)
+++ box/chris/general/modules.txt	2006-05-21 03:45:48 UTC (rev 577)
@@ -9,10 +9,7 @@
 
 # Generic support code and modules
 
-OMIT:CYGWIN
 lib/raidfile		lib/win32
-END-OMIT
-
 lib/crypto
 lib/server
 lib/win32		lib/server
@@ -20,16 +17,13 @@
 test/common		lib/win32
 test/crypto		lib/crypto	lib/win32
 test/compress		lib/compress	lib/win32
+test/raidfile		lib/raidfile	lib/win32
 
 OMIT:mingw32
 OMIT:mingw32msvc
 test/basicserver	lib/server	lib/win32
 END-OMIT
 
-OMIT:CYGWIN
-test/raidfile		lib/raidfile	lib/win32
-END-OMIT
-
 # IF_DISTRIBUTION(boxbackup)
 
 # Backup system

Modified: box/chris/general/test/raidfile/testfiles/raidfile.conf
===================================================================
--- box/chris/general/test/raidfile/testfiles/raidfile.conf	2006-05-20 19:08:55 UTC (rev 576)
+++ box/chris/general/test/raidfile/testfiles/raidfile.conf	2006-05-21 03:45:48 UTC (rev 577)
@@ -3,27 +3,28 @@
 {
 	SetNumber = 0
 	BlockSize = 2048
-	Dir0 = testfiles/0_0
-	Dir1 = testfiles/0_1
-	Dir2 = testfiles/0_2
+	Dir0 = testfiles\0_0
+	Dir1 = testfiles\0_1
+	Dir2 = testfiles\0_2
+	# this will break tests on Unix! Fix me!
 }
 
 disc1
 {
 	SetNumber = 1
 	BlockSize = 2048
-	Dir0 = testfiles/1_0
-	Dir1 = testfiles/1_1
-	Dir2 = testfiles/1_2
+	Dir0 = testfiles\1_0
+	Dir1 = testfiles\1_1
+	Dir2 = testfiles\1_2
 }
 
 disc2
 {
 	SetNumber = 2
 	BlockSize = 2048
-	Dir0 = testfiles/2
-	Dir1 = testfiles/2
-	Dir2 = testfiles/2
+	Dir0 = testfiles\2
+	Dir1 = testfiles\2
+	Dir2 = testfiles\2
 }
 
 

Modified: box/chris/general/test/raidfile/testraidfile.cpp
===================================================================
--- box/chris/general/test/raidfile/testraidfile.cpp	2006-05-20 19:08:55 UTC (rev 576)
+++ box/chris/general/test/raidfile/testraidfile.cpp	2006-05-21 03:45:48 UTC (rev 577)
@@ -210,16 +210,24 @@
 		bytesread += r;
 	}
 	TEST_THAT(!readstream4.StreamDataLeft());		// check IOStream interface is correct
+	pread.reset();
 
 	// Be nasty, and create some errors for the RAID stuff to recover from...
 	if(TestRAIDProperties)
 	{
 		char stripe1fn[256], stripe1fnRename[256];
-		sprintf(stripe1fn, "testfiles/%d_%d/%s.rf", set, startDisc, filename);
-		sprintf(stripe1fnRename, "testfiles/%d_%d/%s.rf-REMOVED", set, startDisc, filename);
+		sprintf(stripe1fn, "testfiles" DIRECTORY_SEPARATOR "%d_%d"
+			DIRECTORY_SEPARATOR "%s.rf", set, startDisc, filename);
+		sprintf(stripe1fnRename, "testfiles" DIRECTORY_SEPARATOR "%d_%d"
+			DIRECTORY_SEPARATOR "%s.rf-REMOVED", set, startDisc, 
+			filename);
 		char stripe2fn[256], stripe2fnRename[256];
-		sprintf(stripe2fn, "testfiles/%d_%d/%s.rf", set, (startDisc + 1) % RAID_NUMBER_DISCS, filename);
-		sprintf(stripe2fnRename, "testfiles/%d_%d/%s.rf-REMOVED", set, (startDisc + 1) % RAID_NUMBER_DISCS, filename);
+		sprintf(stripe2fn, "testfiles" DIRECTORY_SEPARATOR "%d_%d"
+			DIRECTORY_SEPARATOR "%s.rf", set, 
+			(startDisc + 1) % RAID_NUMBER_DISCS, filename);
+		sprintf(stripe2fnRename, "testfiles" DIRECTORY_SEPARATOR "%d_%d"
+			DIRECTORY_SEPARATOR "%s.rf-REMOVED", set, 
+			(startDisc + 1) % RAID_NUMBER_DISCS, filename);
 
 		// Read with stripe1 + parity		
 		TEST_THAT(::rename(stripe2fn, stripe2fnRename) == 0);
@@ -255,9 +263,15 @@
 		}
 		mungefilename[m++] = '\0';
 		char stripe1munge[256];
-		sprintf(stripe1munge, "testfiles/%d_%d/.raidfile-unreadable/%s", set, startDisc, mungefilename);
+		sprintf(stripe1munge, "testfiles" DIRECTORY_SEPARATOR "%d_%d"
+			DIRECTORY_SEPARATOR ".raidfile-unreadable"
+			DIRECTORY_SEPARATOR "%s", set, startDisc, 
+			mungefilename);
 		char stripe2munge[256];
-		sprintf(stripe2munge, "testfiles/%d_%d/.raidfile-unreadable/%s", set, (startDisc + 1) % RAID_NUMBER_DISCS, mungefilename);
+		sprintf(stripe2munge, "testfiles" DIRECTORY_SEPARATOR "%d_%d"
+			DIRECTORY_SEPARATOR ".raidfile-unreadable"
+			DIRECTORY_SEPARATOR "%s", set, 
+			(startDisc + 1) % RAID_NUMBER_DISCS, mungefilename);
 		
 
 #ifdef TRF_CAN_INTERCEPT
@@ -362,10 +376,12 @@
 	write4.Write(data, datasize);
 	// This time, don't discard and transform it to a RAID File
 	char writefnPre[256];
-	sprintf(writefnPre, "testfiles/%d_%d/%s.rfwX", set, startDisc, filename);
+	sprintf(writefnPre, "testfiles" DIRECTORY_SEPARATOR "%d_%d"
+		DIRECTORY_SEPARATOR "%s.rfwX", set, startDisc, filename);
 	TEST_THAT(TestFileExists(writefnPre));
 	char writefn[256];
-	sprintf(writefn, "testfiles/%d_%d/%s.rfw", set, startDisc, filename);
+	sprintf(writefn, "testfiles" DIRECTORY_SEPARATOR "%d_%d"
+		DIRECTORY_SEPARATOR "%s.rfw", set, startDisc, filename);
 	int usageInBlocks = write4.GetDiscUsageInBlocks();
 	write4.Commit(DoTransform);
 	// Check that files are nicely done...
@@ -393,14 +409,19 @@
 			fs1 = ((fullblocks / 2)+1) * RAID_BLOCK_SIZE;
 		}
 		char stripe1fn[256];
-		sprintf(stripe1fn, "testfiles/%d_%d/%s.rf", set, startDisc, filename);
+		sprintf(stripe1fn, "testfiles" DIRECTORY_SEPARATOR "%d_%d"
+			DIRECTORY_SEPARATOR "%s.rf", set, startDisc, filename);
 		TEST_THAT(TestGetFileSize(stripe1fn) == fs1);
 		char stripe2fn[256];
-		sprintf(stripe2fn, "testfiles/%d_%d/%s.rf", set, (startDisc + 1) % RAID_NUMBER_DISCS, filename);
+		sprintf(stripe2fn, "testfiles" DIRECTORY_SEPARATOR "%d_%d"
+			DIRECTORY_SEPARATOR "%s.rf", set, 
+			(startDisc + 1) % RAID_NUMBER_DISCS, filename);
 		TEST_THAT(TestGetFileSize(stripe2fn) == (int)(datasize - fs1));
 		// Parity file size
 		char parityfn[256];
-		sprintf(parityfn, "testfiles/%d_%d/%s.rf", set, (startDisc + 2) % RAID_NUMBER_DISCS, filename);
+		sprintf(parityfn, "testfiles" DIRECTORY_SEPARATOR "%d_%d"
+			DIRECTORY_SEPARATOR "%s.rf", set, 
+			(startDisc + 2) % RAID_NUMBER_DISCS, filename);
 		// Mildly complex calculation
 		unsigned int blocks = datasize / RAID_BLOCK_SIZE;
 		unsigned int bytesOver = datasize % RAID_BLOCK_SIZE;
@@ -439,14 +460,16 @@
 		if(datasize > (3*1024))
 		{
 			int f;
-			TEST_THAT((f = ::open(stripe1fn, O_RDONLY, 0)) != -1);
+			TEST_THAT((f = ::open(stripe1fn, O_RDONLY | O_BINARY, 
+				0)) != -1);
 			TEST_THAT(sizeof(testblock) == ::read(f, testblock, sizeof(testblock)));
 			for(unsigned int q = 0; q < sizeof(testblock); ++q)
 			{
 				TEST_THAT(testblock[q] == ((char*)data)[q]);
 			}
 			::close(f);
-			TEST_THAT((f = ::open(stripe2fn, O_RDONLY, 0)) != -1);
+			TEST_THAT((f = ::open(stripe2fn, O_RDONLY | O_BINARY, 
+				0)) != -1);
 			TEST_THAT(sizeof(testblock) == ::read(f, testblock, sizeof(testblock)));
 			for(unsigned int q = 0; q < sizeof(testblock); ++q)
 			{
@@ -539,7 +562,9 @@
 	
 	// Generate a random pre-existing write file (and ensure that it doesn't exist already)
 	int f;
-	TEST_THAT((f = ::open("testfiles/0_2/overwrite_B.rfwX", O_WRONLY | O_CREAT | O_EXCL, 0755)) != -1);
+	TEST_THAT((f = ::open("testfiles" DIRECTORY_SEPARATOR "0_2" 
+		DIRECTORY_SEPARATOR "overwrite_B.rfwX", 
+		O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0755)) != -1);
 	TEST_THAT(::write(f, "TESTTEST", 8) == 8);
 	::close(f);
 
@@ -560,7 +585,7 @@
 
 	// Initialise the controller
 	RaidFileController &rcontroller = RaidFileController::GetController();
-	rcontroller.Initialise("testfiles/raidfile.conf");
+	rcontroller.Initialise("testfiles" DIRECTORY_SEPARATOR "raidfile.conf");
 
 	// some data
 	char data[TEST_DATA_SIZE];
@@ -577,9 +602,12 @@
 	
 	// Try creating a directory
 	RaidFileWrite::CreateDirectory(0, "test-dir");
-	TEST_THAT(TestDirExists("testfiles/0_0/test-dir"));
-	TEST_THAT(TestDirExists("testfiles/0_1/test-dir"));
-	TEST_THAT(TestDirExists("testfiles/0_2/test-dir"));
+	TEST_THAT(TestDirExists("testfiles" DIRECTORY_SEPARATOR "0_0" 
+		DIRECTORY_SEPARATOR "test-dir"));
+	TEST_THAT(TestDirExists("testfiles" DIRECTORY_SEPARATOR "0_1"
+		DIRECTORY_SEPARATOR "test-dir"));
+	TEST_THAT(TestDirExists("testfiles" DIRECTORY_SEPARATOR "0_2"
+		DIRECTORY_SEPARATOR "test-dir"));
 	TEST_THAT(RaidFileRead::DirectoryExists(0, "test-dir"));
 	TEST_THAT(!RaidFileRead::DirectoryExists(0, "test-dir-not"));
 
@@ -611,9 +639,12 @@
 	
 	// Before it's deleted, check to see the contents are as expected
 	int f;
-	TEST_THAT((f = ::open("testfiles/0_2/test1.rfwX", O_RDONLY, 0)) >= 0);
+	TEST_THAT((f = ::open("testfiles" DIRECTORY_SEPARATOR "0_2"
+		DIRECTORY_SEPARATOR "test1.rfwX", O_RDONLY | O_BINARY, 0)) 
+		>= 0);
 	char buffer[sizeof(data)];
-	TEST_THAT(::read(f, buffer, sizeof(buffer)) == sizeof(buffer));
+	int bytes_read = ::read(f, buffer, sizeof(buffer));
+	TEST_THAT(bytes_read == sizeof(buffer));
 	for(unsigned int l = 0; l < 1024; ++l)
 	{
 		TEST_THAT(buffer[l] == data[l]);
@@ -627,7 +658,8 @@
 		TEST_THAT(buffer[l+2048+sizeof(data2)] == data2[l]);
 	}
 	TEST_THAT(::lseek(f, sizeof(data), SEEK_SET) == sizeof(buffer));
-	TEST_THAT(::read(f, buffer, sizeof(buffer)) == sizeof(buffer));
+	bytes_read = ::read(f, buffer, sizeof(buffer));
+	TEST_THAT(bytes_read == sizeof(buffer));
 	for(unsigned int l = 0; l < 1024; ++l)
 	{
 		TEST_THAT(buffer[l] == data[l]);
@@ -638,7 +670,9 @@
 	
 	// Commit the data
 	write1.Commit();
-	TEST_THAT((f = ::open("testfiles/0_2/test1.rfw", O_RDONLY, 0)) >= 0);
+	TEST_THAT((f = ::open("testfiles" DIRECTORY_SEPARATOR "0_2"
+		DIRECTORY_SEPARATOR "test1.rfw", O_RDONLY | O_BINARY, 0)) 
+		>= 0);
 	::close(f);
 
 	// Now try and read it
@@ -690,7 +724,9 @@
 	write2.Write(data, sizeof(data));
 	// This time, discard it
 	write2.Discard();
-	TEST_THAT((f = ::open("testfiles/0_2/test1.rfw", O_RDONLY, 0)) == -1);
+	TEST_THAT((f = ::open("testfiles" DIRECTORY_SEPARATOR "0_2"
+		DIRECTORY_SEPARATOR "test1.rfw", O_RDONLY | O_BINARY, 0)) 
+		== -1);
 	
 	// And leaving it there...
 	RaidFileWrite writeLeave(0, "test1");
@@ -698,7 +734,9 @@
 	writeLeave.Write(data, sizeof(data));
 	// This time, commit it
 	writeLeave.Commit();
-	TEST_THAT((f = ::open("testfiles/0_2/test1.rfw", O_RDONLY, 0)) != -1);
+	TEST_THAT((f = ::open("testfiles" DIRECTORY_SEPARATOR "0_2" 
+		DIRECTORY_SEPARATOR "test1.rfw", O_RDONLY | O_BINARY, 0)) 
+		!= -1);
 	::close(f);
 	
 	// Then check that the thing will refuse to open it again.
@@ -715,7 +753,8 @@
 	write3b.Write(data + 3, sizeof(data) - 3);
 	write3b.Commit();
 	// Test it
-	testReadingFileContents(0, "test1", data+3, sizeof(data) - 3, false /*TestRAIDProperties*/);
+	testReadingFileContents(0, "test1", data+3, sizeof(data) - 3, false 
+		/* TestRAIDProperties */);
 
 	// And once again, but this time making it a raid file
 	RaidFileWrite write3c(0, "test1");
@@ -724,7 +763,8 @@
 	write3c.Write(data + 7, sizeof(data) - 7);
 	write3c.Commit(true);	// make RAID
 	// Test it
-	testReadingFileContents(0, "test1", data+7, sizeof(data) - 7, false /*TestRAIDProperties*/);
+	testReadingFileContents(0, "test1", data+7, sizeof(data) - 7, false 
+		/*TestRAIDProperties*/);
 
 	// Test opening a file which doesn't exist
 	TEST_CHECK_THROWS(
@@ -739,20 +779,23 @@
 		w.Commit(true);
 
 		// Try removing the parity file
-		TEST_THAT(::rename("testfiles/0_0/damage.rf", "testfiles/0_0/damage.rf-NT") == 0);
+		TEST_THAT(::rename("testfiles" DIRECTORY_SEPARATOR "0_0"
+			DIRECTORY_SEPARATOR "damage.rf", 
+			"testfiles" DIRECTORY_SEPARATOR "0_0"
+			DIRECTORY_SEPARATOR "damage.rf-NT") == 0);
 		{
 			std::auto_ptr<RaidFileRead> pr0 = RaidFileRead::Open(0, "damage");
 			pr0->Read(buffer, sizeof(data));
 		}		
-		TEST_THAT(::rename("testfiles/0_0/damage.rf-NT", "testfiles/0_0/damage.rf") == 0);
-		
+		TEST_THAT(::rename("testfiles" DIRECTORY_SEPARATOR "0_0" DIRECTORY_SEPARATOR "damage.rf-NT", "testfiles" DIRECTORY_SEPARATOR "0_0" DIRECTORY_SEPARATOR "damage.rf") == 0);
+	
 		// Delete one of the files
-		TEST_THAT(::unlink("testfiles/0_1/damage.rf") == 0);	// stripe 1
+		TEST_THAT(::unlink("testfiles" DIRECTORY_SEPARATOR "0_1" DIRECTORY_SEPARATOR "damage.rf") == 0); // stripe 1
 		
 #ifdef TRF_CAN_INTERCEPT
 		// Open it and read...
 		{
-			intercept_setup_error("testfiles/0_2/damage.rf", 0, EIO, SYS_read);	// stripe 2
+			intercept_setup_error("testfiles" DIRECTORY_SEPARATOR "0_2" DIRECTORY_SEPARATOR "damage.rf", 0, EIO, SYS_read);	// stripe 2
 			std::auto_ptr<RaidFileRead> pr1 = RaidFileRead::Open(0, "damage");
 			TEST_CHECK_THROWS(
 				pr1->Read(buffer, sizeof(data)),
@@ -764,7 +807,7 @@
 #endif //TRF_CAN_INTERCEPT
 
 		// Delete another
-		TEST_THAT(::unlink("testfiles/0_0/damage.rf") == 0);		// parity
+		TEST_THAT(::unlink("testfiles" DIRECTORY_SEPARATOR "0_0" DIRECTORY_SEPARATOR "damage.rf") == 0); // parity
 		
 		TEST_CHECK_THROWS(
 			std::auto_ptr<RaidFileRead> pread2 = RaidFileRead::Open(0, "damage"),
@@ -775,22 +818,22 @@
 	{
 		RaidFileWrite::CreateDirectory(0, "dirread");
 		// Make some contents
-		RaidFileWrite::CreateDirectory(0, "dirread/dfsdf1");
-		RaidFileWrite::CreateDirectory(0, "dirread/ponwq2");
+		RaidFileWrite::CreateDirectory(0, "dirread" DIRECTORY_SEPARATOR "dfsdf1");
+		RaidFileWrite::CreateDirectory(0, "dirread" DIRECTORY_SEPARATOR "ponwq2");
 		{
-			RaidFileWrite w(0, "dirread/sdf9873241");
+			RaidFileWrite w(0, "dirread" DIRECTORY_SEPARATOR "sdf9873241");
 			w.Open();
 			w.Write(data, sizeof(data));
 			w.Commit(true);
 		}
 		{
-			RaidFileWrite w(0, "dirread/fsdcxjni3242");
+			RaidFileWrite w(0, "dirread" DIRECTORY_SEPARATOR "fsdcxjni3242");
 			w.Open();
 			w.Write(data, sizeof(data));
 			w.Commit(true);
 		}
 		{
-			RaidFileWrite w(0, "dirread/cskjnds3");
+			RaidFileWrite w(0, "dirread" DIRECTORY_SEPARATOR "cskjnds3");
 			w.Open();
 			w.Write(data, sizeof(data));
 			w.Commit(false);
@@ -806,15 +849,15 @@
 		TEST_THAT(true == RaidFileRead::ReadDirectoryContents(0, std::string("dirread"), RaidFileRead::DirReadType_DirsOnly, names));
 		TEST_THAT(list_matches(names, dir_list1));
 		// Delete things
-		TEST_THAT(::unlink("testfiles/0_0/dirread/sdf9873241.rf") == 0);
+		TEST_THAT(::unlink("testfiles" DIRECTORY_SEPARATOR "0_0" DIRECTORY_SEPARATOR "dirread" DIRECTORY_SEPARATOR "sdf9873241.rf") == 0);
 		TEST_THAT(true == RaidFileRead::ReadDirectoryContents(0, std::string("dirread"), RaidFileRead::DirReadType_FilesOnly, names));
 		TEST_THAT(list_matches(names, file_list1));
 		// Delete something else so that it's not recoverable
-		TEST_THAT(::unlink("testfiles/0_1/dirread/sdf9873241.rf") == 0);
+		TEST_THAT(::unlink("testfiles" DIRECTORY_SEPARATOR "0_1" DIRECTORY_SEPARATOR "dirread" DIRECTORY_SEPARATOR "sdf9873241.rf") == 0);
 		TEST_THAT(false == RaidFileRead::ReadDirectoryContents(0, std::string("dirread"), RaidFileRead::DirReadType_FilesOnly, names));
 		TEST_THAT(list_matches(names, file_list1));
 		// And finally...
-		TEST_THAT(::unlink("testfiles/0_2/dirread/sdf9873241.rf") == 0);
+		TEST_THAT(::unlink("testfiles" DIRECTORY_SEPARATOR "0_2" DIRECTORY_SEPARATOR "dirread" DIRECTORY_SEPARATOR "sdf9873241.rf") == 0);
 		TEST_THAT(true == RaidFileRead::ReadDirectoryContents(0, std::string("dirread"), RaidFileRead::DirReadType_FilesOnly, names));
 		TEST_THAT(list_matches(names, file_list2));
 	}


From boxbackup-dev@fluffy.co.uk  Sun May 21 13:55:59 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun, 21 May 2006 12:55:59 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r578 - in box/chris/general: . lib/common lib/server test/basicserver
Message-ID: <20060521125559.2AEA896@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-21 12:55:17 +0000 (Sun, 21 May 2006)
New Revision: 578

Modified:
   box/chris/general/lib/common/Test.h
   box/chris/general/lib/server/ServerStream.h
   box/chris/general/modules.txt
   box/chris/general/test/basicserver/TestCommands.cpp
   box/chris/general/test/basicserver/testbasicserver.cpp
Log:
* modules.txt
- Enable basicserver tests on Win32

* lib/server/ServerStream.h
- Work around lack of fork() on Win32

* lib/common/Test.h
- Work around lack of getpid() and kill() on Win32

* test/basicserver/testbasicserver.cpp
- Work around lack of nanosleep() on Win32

* test/basicserver/TestCommands.cpp
- Don't include syslog.h unless configure detected that we have one


Modified: box/chris/general/lib/common/Test.h
===================================================================
--- box/chris/general/lib/common/Test.h	2006-05-21 03:45:48 UTC (rev 577)
+++ box/chris/general/lib/common/Test.h	2006-05-21 12:55:17 UTC (rev 578)
@@ -81,12 +81,45 @@
 
 inline int LaunchServer(const char *CommandLine, const char *pidFile)
 {
+#ifdef WIN32
+	PROCESS_INFORMATION procInfo;
+
+	CHAR* tempCmd = strdup(CommandLine);
+
+	DWORD result = CreateProcess
+	(
+		NULL,        // lpApplicationName, naughty!
+		tempCmd,     // lpCommandLine
+		NULL,        // lpProcessAttributes
+		NULL,        // lpThreadAttributes
+		false,       // bInheritHandles
+		0,           // dwCreationFlags
+		NULL,        // lpEnvironment
+		NULL,        // lpCurrentDirectory
+		NULL,        // lpStartupInfo
+		&procInfo    // lpProcessInformation
+	);
+
+	free(tempCmd);
+
+	if (result != 0)
+	{
+		DWORD err = GetLastError();
+		printf("Launch failed: %s: error %d\n", CommandLine, (int)err);
+		return -1;
+	}
+
+	CloseHandle(procInfo.hProcess);
+	CloseHandle(procInfo.hThread);
+#else // !WIN32
 	if(::system(CommandLine) != 0)
 	{
 		printf("Server: %s\n", CommandLine);
 		TEST_FAIL_WITH_MESSAGE("Couldn't start server");
 		return -1;
 	}
+#endif // WIN32
+
 	// time for it to start up
 	::sleep(1);
 	
@@ -107,17 +140,50 @@
 		return -1;
 	}
 	fclose(f);
-	
+
+#ifdef WIN32
+	if (pid != (int)procInfo.dwProcessId)
+	{
+		printf("Server wrote wrong pid to file (%s): expected %d "
+			"but found %d\n", pidFile, 
+			(int)procInfo.dwProcessId, pid);
+		TEST_FAIL_WITH_MESSAGE("Server wrote wrong pid to file");	
+		return -1;
+	}
+#endif
+
 	return pid;
 }
 
 #ifdef WIN32
+#include <windows.h>
+#endif
 
+inline bool ServerIsAlive(int pid)
+{
+#ifdef WIN32
+	HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, false, pid);
+	if (hProcess == NULL)
+	{
+		printf("Failed to open process %d: error %d\n",
+			pid, (int)GetLastError());
+		return false;
+	}
+	CloseHandle(hProcess);
+	return true;
+#else // !WIN32
+	if(pid == 0) return false;
+	return ::kill(pid, 0) != -1;
+#endif // WIN32
+}
+
+#ifdef WIN32
+
 #include "WinNamedPipeStream.h"
 #include "IOStreamGetLine.h"
 #include "BoxPortsAndFiles.h"
 
-bool SendCommands(const std::string& rCmd)
+inline bool SendCommands(const std::string& rCmd)
 {
 	WinNamedPipeStream connection;
 
@@ -202,11 +268,6 @@
 	return statusOk;
 }
 
-inline bool ServerIsAlive()
-{
-	return SendCommands("");
-}
-
 inline bool HUPServer(int pid)
 {
 	return SendCommands("reload");
@@ -216,17 +277,11 @@
 {
 	TEST_THAT(SendCommands("terminate"));
 	::sleep(1);
-	return !ServerIsAlive();
+	return !ServerIsAlive(pid);
 }
 
 #else // !WIN32
 
-inline bool ServerIsAlive(int pid)
-{
-	if(pid == 0) return false;
-	return ::kill(pid, 0) != -1;
-}
-
 inline bool HUPServer(int pid)
 {
 	if(pid == 0) return false;

Modified: box/chris/general/lib/server/ServerStream.h
===================================================================
--- box/chris/general/lib/server/ServerStream.h	2006-05-21 03:45:48 UTC (rev 577)
+++ box/chris/general/lib/server/ServerStream.h	2006-05-21 12:55:17 UTC (rev 578)
@@ -215,6 +215,7 @@
 					if(connection.get())
 					{
 						// Since this is a template parameter, the if() will be optimised out by the compiler
+#ifndef WIN32 // no fork on Win32
 						if(ForkToHandleRequests)
 						{
 							pid_t pid = ::fork();
@@ -255,14 +256,18 @@
 						}
 						else
 						{
+#endif // !WIN32
 							// Just handle in this connection
 							SetProcessTitle("handling");
 							HandleConnection(*connection);
 							SetProcessTitle("idle");										
+#ifndef WIN32
 						}
+#endif // !WIN32
 					}
 				}
-				
+
+#ifndef WIN32				
 				// Clean up child processes (if forking daemon)
 				if(ForkToHandleRequests)
 				{
@@ -277,6 +282,7 @@
 						}
 					} while(p > 0);
 				}
+#endif // !WIN32
 			}
 		}
 		catch(...)
@@ -301,7 +307,11 @@
 	// depends on the forking model in case someone changes it later.
 	bool WillForkToHandleRequests()
 	{
+#ifdef WIN32
+		return false;
+#else
 		return ForkToHandleRequests;
+#endif // WIN32
 	}
 
 private:

Modified: box/chris/general/modules.txt
===================================================================
--- box/chris/general/modules.txt	2006-05-21 03:45:48 UTC (rev 577)
+++ box/chris/general/modules.txt	2006-05-21 12:55:17 UTC (rev 578)
@@ -18,11 +18,7 @@
 test/crypto		lib/crypto	lib/win32
 test/compress		lib/compress	lib/win32
 test/raidfile		lib/raidfile	lib/win32
-
-OMIT:mingw32
-OMIT:mingw32msvc
 test/basicserver	lib/server	lib/win32
-END-OMIT
 
 # IF_DISTRIBUTION(boxbackup)
 

Modified: box/chris/general/test/basicserver/TestCommands.cpp
===================================================================
--- box/chris/general/test/basicserver/TestCommands.cpp	2006-05-21 03:45:48 UTC (rev 577)
+++ box/chris/general/test/basicserver/TestCommands.cpp	2006-05-21 12:55:17 UTC (rev 578)
@@ -1,7 +1,9 @@
 
 #include "Box.h"
 
+#ifdef HAVE_SYSLOG_H
 #include <syslog.h>
+#endif
 
 #include "autogen_TestProtocolServer.h"
 #include "CollectInBufferStream.h"

Modified: box/chris/general/test/basicserver/testbasicserver.cpp
===================================================================
--- box/chris/general/test/basicserver/testbasicserver.cpp	2006-05-21 03:45:48 UTC (rev 577)
+++ box/chris/general/test/basicserver/testbasicserver.cpp	2006-05-21 12:55:17 UTC (rev 578)
@@ -62,10 +62,14 @@
 
 void testservers_pause_before_reply()
 {
-	 struct timespec t;
-	 t.tv_sec = 0;
-	 t.tv_nsec = COMMS_SERVER_WAIT_BEFORE_REPLYING * 1000 * 1000;	// convert to ns
-	 ::nanosleep(&t, NULL);
+#ifdef WIN32
+	Sleep(COMMS_SERVER_WAIT_BEFORE_REPLYING * 1000);
+#else
+	struct timespec t;
+	t.tv_sec = 0;
+	t.tv_nsec = COMMS_SERVER_WAIT_BEFORE_REPLYING * 1000 * 1000;	// convert to ns
+	::nanosleep(&t, NULL);
+#endif
 }
 
 #define LARGE_DATA_BLOCK_SIZE 19870


From boxbackup-dev@fluffy.co.uk  Sun May 21 13:57:57 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun, 21 May 2006 12:57:57 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r579 - box/chris/general/infrastructure
Message-ID: <20060521125757.7166596@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-21 12:57:42 +0000 (Sun, 21 May 2006)
New Revision: 579

Modified:
   box/chris/general/infrastructure/makebuildenv.pl
Log:
* makebuildenv.pl
- Space between command name and executable extension?


Modified: box/chris/general/infrastructure/makebuildenv.pl
===================================================================
--- box/chris/general/infrastructure/makebuildenv.pl	2006-05-21 12:55:17 UTC (rev 578)
+++ box/chris/general/infrastructure/makebuildenv.pl	2006-05-21 12:57:42 UTC (rev 579)
@@ -416,9 +416,9 @@
 		}
 		
 		writetestfile("$mod/_t", 
-			'./test' . $platform_exe_ext . '$1 $2 $3 $4 $5', $mod);
+			'./test' . $platform_exe_ext . ' $1 $2 $3 $4 $5', $mod);
 		writetestfile("$mod/_t-gdb", 
-			'gdb ./test ' . $platform_exe_ext, $mod);
+			'gdb ./test' . $platform_exe_ext, $mod);
 		
 	}
 	


From boxbackup-dev@fluffy.co.uk  Sun May 21 15:11:57 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun, 21 May 2006 14:11:57 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r580 - in box/chris/general: lib/common lib/server test/basicserver
Message-ID: <20060521141157.9FD1D96@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-21 14:11:18 +0000 (Sun, 21 May 2006)
New Revision: 580

Modified:
   box/chris/general/lib/common/Test.h
   box/chris/general/lib/server/Daemon.cpp
   box/chris/general/test/basicserver/testbasicserver.cpp
Log:
* lib/common/Test.h
- Fixed launching of server processes

* lib/server/Daemon.cpp
- Save PID file and open syslog on Windows

* test/basicserver/testbasicserver.cpp
- Fixed some wrong path separators on Windows


Modified: box/chris/general/lib/common/Test.h
===================================================================
--- box/chris/general/lib/common/Test.h	2006-05-21 12:57:42 UTC (rev 579)
+++ box/chris/general/lib/common/Test.h	2006-05-21 14:11:18 UTC (rev 580)
@@ -84,6 +84,15 @@
 #ifdef WIN32
 	PROCESS_INFORMATION procInfo;
 
+	STARTUPINFO startInfo;
+	startInfo.cb = sizeof(startInfo);
+	startInfo.lpReserved = NULL;
+	startInfo.lpDesktop  = NULL;
+	startInfo.lpTitle    = NULL;
+	startInfo.dwFlags = 0;
+	startInfo.cbReserved2 = 0;
+	startInfo.lpReserved2 = NULL;
+
 	CHAR* tempCmd = strdup(CommandLine);
 
 	DWORD result = CreateProcess
@@ -96,13 +105,13 @@
 		0,           // dwCreationFlags
 		NULL,        // lpEnvironment
 		NULL,        // lpCurrentDirectory
-		NULL,        // lpStartupInfo
+		&startInfo,  // lpStartupInfo
 		&procInfo    // lpProcessInformation
 	);
 
 	free(tempCmd);
 
-	if (result != 0)
+	if (result == 0)
 	{
 		DWORD err = GetLastError();
 		printf("Launch failed: %s: error %d\n", CommandLine, (int)err);

Modified: box/chris/general/lib/server/Daemon.cpp
===================================================================
--- box/chris/general/lib/server/Daemon.cpp	2006-05-21 12:57:42 UTC (rev 579)
+++ box/chris/general/lib/server/Daemon.cpp	2006-05-21 14:11:18 UTC (rev 580)
@@ -189,6 +189,7 @@
 		{
 			THROW_EXCEPTION(ServerException, DaemoniseFailed)
 		}
+#endif // !WIN32
 		
 		// Server configuration
 		const Configuration &serverConfig(
@@ -197,7 +198,8 @@
 		// Open PID file for writing
 		pidFileName = serverConfig.GetKeyValue("PidFile");
 		FileHandleGuard<(O_WRONLY | O_CREAT | O_TRUNC), (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)> pidFile(pidFileName.c_str());
-		
+	
+#ifndef WIN32	
 		// Handle changing to a different user
 		if(serverConfig.KeyExists("User"))
 		{
@@ -263,25 +265,29 @@
 				break;
 			}
 		}
+#endif // ! WIN32
 
 		// open the log
 		::openlog(DaemonName(), LOG_PID, LOG_LOCAL6);
-#endif // ! WIN32
 
 		// Log the start message
 		::syslog(LOG_INFO, "Starting daemon (config: %s) (version " 
 			BOX_VERSION ")", mConfigFileName.c_str());
 
-#ifndef WIN32
 		// Write PID to file
 		char pid[32];
+
+#ifdef WIN32
+		int pidsize = sprintf(pid, "%d", (int)GetCurrentProcessId());
+#else
 		int pidsize = sprintf(pid, "%d", (int)getpid());
+#endif
+
 		if(::write(pidFile, pid, pidsize) != pidsize)
 		{
 			::syslog(LOG_ERR, "can't write pid file");
 			THROW_EXCEPTION(ServerException, DaemoniseFailed)
 		}
-#endif
 		
 		// Set up memory leak reporting
 		#ifdef BOX_MEMORY_LEAK_TESTING

Modified: box/chris/general/test/basicserver/testbasicserver.cpp
===================================================================
--- box/chris/general/test/basicserver/testbasicserver.cpp	2006-05-21 12:57:42 UTC (rev 579)
+++ box/chris/general/test/basicserver/testbasicserver.cpp	2006-05-21 14:11:18 UTC (rev 580)
@@ -436,21 +436,37 @@
 
 	// Launch a basic server
 	{
-		int pid = LaunchServer("./test srv1 testfiles/srv1.conf", "testfiles/srv1.pid");
+#ifdef WIN32
+		int pid = LaunchServer("test srv1 testfiles\\srv1.conf", 
+			"testfiles\\srv1.pid");
+#else
+		int pid = LaunchServer("./test srv1 testfiles/srv1.conf", 
+			"testfiles/srv1.pid");
+#endif
+
 		TEST_THAT(pid != -1 && pid != 0);
 		if(pid > 0)
 		{
 			// Check that it's written the expected file
-			TEST_THAT(TestFileExists("testfiles/srv1.test1"));
+			TEST_THAT(TestFileExists("testfiles" 
+				DIRECTORY_SEPARATOR "srv1.test1"));
 			TEST_THAT(ServerIsAlive(pid));
 			// Move the config file over
-			TEST_THAT(::rename("testfiles/srv1b.conf", "testfiles/srv1.conf") != -1);
+#ifdef WIN32
+			TEST_THAT(::unlink("testfiles" DIRECTORY_SEPARATOR 
+				"srv1.conf") != -1);
+#endif
+			TEST_THAT(::rename(
+				"testfiles" DIRECTORY_SEPARATOR "srv1b.conf", 
+				"testfiles" DIRECTORY_SEPARATOR "srv1.conf") 
+				!= -1);
 			// Get it to reread the config file
 			TEST_THAT(HUPServer(pid));
 			::sleep(1);
 			TEST_THAT(ServerIsAlive(pid));
 			// Check that new file exists
-			TEST_THAT(TestFileExists("testfiles/srv1.test2"));
+			TEST_THAT(TestFileExists("testfiles" 
+				DIRECTORY_SEPARATOR "srv1.test2"));
 			// Kill it off
 			TEST_THAT(KillServer(pid));
 			TestRemoteProcessMemLeaks("generic-daemon.memleaks");
@@ -459,7 +475,14 @@
 	
 	// Launch a test forking server
 	{
-		int pid = LaunchServer("./test srv2 testfiles/srv2.conf", "testfiles/srv2.pid");
+#ifdef WIN32
+		int pid = LaunchServer("test srv2 testfiles\\srv2.conf", 
+			"testfiles\\srv2.pid");
+#else
+		int pid = LaunchServer("./test srv2 testfiles/srv2.conf", 
+			"testfiles/srv2.pid");
+#endif
+
 		TEST_THAT(pid != -1 && pid != 0);
 		if(pid > 0)
 		{


From boxbackup-dev@fluffy.co.uk  Mon May 22 14:04:15 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Mon, 22 May 2006 13:04:15 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r581 - in box/chris/general: bin/bbackupd lib/common lib/server test/basicserver test/basicserver/testfiles
Message-ID: <20060522130415.21B6E96@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-22 13:03:59 +0000 (Mon, 22 May 2006)
New Revision: 581

Modified:
   box/chris/general/bin/bbackupd/bbackupd.cpp
   box/chris/general/lib/common/Test.h
   box/chris/general/lib/server/Daemon.cpp
   box/chris/general/test/basicserver/testbasicserver.cpp
   box/chris/general/test/basicserver/testfiles/srv2.conf
Log:
* test/basicserver/testfiles/srv2.conf
- UNIX sockets are not supported on Windows

* test/basicserver/testbasicserver.cpp
- Must initialise Winsock library before using it
- Don't try to HUP the server on Windows, we can't
- Don't check for memory leaks on Windows, the process dies before it can
  write the file

* lib/server/Daemon.cpp
- Must initialise Winsock library before using it

* lib/common/Test.h
- Don't log failure to open process that doesn't exist
- Use TerminateProcess (for now) to kill the server

* bin/bbackupd/bbackupd.cpp
- Moved Winsock initialisation to Daemon class


Modified: box/chris/general/bin/bbackupd/bbackupd.cpp
===================================================================
--- box/chris/general/bin/bbackupd/bbackupd.cpp	2006-05-21 14:11:18 UTC (rev 580)
+++ box/chris/general/bin/bbackupd/bbackupd.cpp	2006-05-22 13:03:59 UTC (rev 581)
@@ -57,19 +57,7 @@
 	{
 		runAsWin32Service = true;
 	}
-	
-	// Under win32 we must initialise the Winsock library
-	// before using sockets
-		
-	WSADATA info;
 
-	if (WSAStartup(0x0101, &info) == SOCKET_ERROR) 
-	{
-		// box backup will not run without sockets
-		::syslog(LOG_ERR, "Failed to initialise Windows Sockets");
-		THROW_EXCEPTION(BackupStoreException, Internal)
-	}
-
 	gpDaemonService = new Win32BackupService();
 
 	EnableBackupRights();
@@ -101,9 +89,6 @@
 			BOX_FILE_BBACKUPD_DEFAULT_CONFIG, argc, argv);
 	}
 
-	// Clean up our sockets
-	WSACleanup();
-
 	::closelog();
 
 	return ExitCode;

Modified: box/chris/general/lib/common/Test.h
===================================================================
--- box/chris/general/lib/common/Test.h	2006-05-21 14:11:18 UTC (rev 580)
+++ box/chris/general/lib/common/Test.h	2006-05-22 13:03:59 UTC (rev 581)
@@ -174,8 +174,11 @@
 	HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, false, pid);
 	if (hProcess == NULL)
 	{
-		printf("Failed to open process %d: error %d\n",
-			pid, (int)GetLastError());
+		if (GetLastError() != ERROR_INVALID_PARAMETER)
+		{
+			printf("Failed to open process %d: error %d\n",
+				pid, (int)GetLastError());
+		}
 		return false;
 	}
 	CloseHandle(hProcess);
@@ -284,7 +287,24 @@
 
 inline bool KillServer(int pid)
 {
-	TEST_THAT(SendCommands("terminate"));
+	HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, false, pid);
+	if (hProcess == NULL)
+	{
+		printf("Failed to open process %d: error %d\n",
+			pid, (int)GetLastError());
+		return false;
+	}
+
+	if (!TerminateProcess(hProcess, 1))
+	{
+		printf("Failed to terminate process %d: error %d\n",
+			pid, (int)GetLastError());
+		CloseHandle(hProcess);
+		return false;
+	}
+
+	CloseHandle(hProcess);
+
 	::sleep(1);
 	return !ServerIsAlive(pid);
 }

Modified: box/chris/general/lib/server/Daemon.cpp
===================================================================
--- box/chris/general/lib/server/Daemon.cpp	2006-05-21 14:11:18 UTC (rev 580)
+++ box/chris/general/lib/server/Daemon.cpp	2006-05-22 13:03:59 UTC (rev 581)
@@ -23,6 +23,10 @@
 	#include <syslog.h>
 #endif
 
+#ifdef WIN32
+	#include <ws2tcpip.h>
+#endif
+
 #include "Daemon.h"
 #include "Configuration.h"
 #include "ServerException.h"
@@ -359,6 +363,20 @@
 #endif
 		return 1;
 	}
+
+	// Under win32 we must initialise the Winsock library
+	// before using sockets
+
+	WSADATA info;
+
+	if (WSAStartup(0x0101, &info) == SOCKET_ERROR)
+	{
+		// will not run without sockets
+		::syslog(LOG_ERR, "Failed to initialise Windows Sockets");
+		THROW_EXCEPTION(CommonException, Internal)
+	}
+
+	int retcode = 0;
 	
 	// Main Daemon running
 	try
@@ -388,7 +406,8 @@
 						mConfigFileName.c_str(),
 						errors.c_str());
 					// And give up
-					return 1;
+					retcode = 1;
+					break;
 				}
 				
 				// delete old configuration
@@ -416,22 +435,24 @@
 		::syslog(LOG_ERR, "%s: terminating due to exception %s "
 			"(%d/%d)", DaemonName(), e.what(), e.GetType(), 
 			e.GetSubType());
-		return 1;
+		retcode = 1;
 	}
 	catch(std::exception &e)
 	{
 		::syslog(LOG_ERR, "%s: terminating due to exception %s", 
 			DaemonName(), e.what());
-		return 1;
+		retcode = 1;
 	}
 	catch(...)
 	{
 		::syslog(LOG_ERR, "%s: terminating due to unknown exception",
 			DaemonName());
-		return 1;
+		retcode = 1;
 	}
+
+	WSACleanup();
 	
-	return 0;
+	return retcode;
 }
 
 // --------------------------------------------------------------------------

Modified: box/chris/general/test/basicserver/testbasicserver.cpp
===================================================================
--- box/chris/general/test/basicserver/testbasicserver.cpp	2006-05-21 14:11:18 UTC (rev 580)
+++ box/chris/general/test/basicserver/testbasicserver.cpp	2006-05-22 13:03:59 UTC (rev 581)
@@ -431,6 +431,14 @@
 		}
 	}
 
+#ifdef WIN32
+	// Under win32 we must initialise the Winsock library
+	// before using sockets
+
+	WSADATA info;
+	TEST_THAT(WSAStartup(0x0101, &info) != SOCKET_ERROR)
+#endif
+
 //printf("SKIPPING TESTS------------------------\n");
 //goto protocolserver;
 
@@ -460,6 +468,7 @@
 				"testfiles" DIRECTORY_SEPARATOR "srv1b.conf", 
 				"testfiles" DIRECTORY_SEPARATOR "srv1.conf") 
 				!= -1);
+#ifndef WIN32
 			// Get it to reread the config file
 			TEST_THAT(HUPServer(pid));
 			::sleep(1);
@@ -467,9 +476,12 @@
 			// Check that new file exists
 			TEST_THAT(TestFileExists("testfiles" 
 				DIRECTORY_SEPARATOR "srv1.test2"));
+#endif // !WIN32
 			// Kill it off
 			TEST_THAT(KillServer(pid));
+#ifndef WIN32
 			TestRemoteProcessMemLeaks("generic-daemon.memleaks");
+#endif // !WIN32
 		}
 	}
 	
@@ -488,36 +500,46 @@
 		{
 			// Will it restart?
 			TEST_THAT(ServerIsAlive(pid));
+#ifndef WIN32
 			TEST_THAT(HUPServer(pid));
 			::sleep(1);
 			TEST_THAT(ServerIsAlive(pid));
+#endif // !WIN32
 			// Make some connections
 			{
 				SocketStream conn1;
 				conn1.Open(Socket::TypeINET, "localhost", 2003);
+#ifndef WIN32
 				SocketStream conn2;
 				conn2.Open(Socket::TypeUNIX, "testfiles/srv2.sock");
 				SocketStream conn3;
 				conn3.Open(Socket::TypeINET, "localhost", 2003);
+#endif // !WIN32
 				// Quick check that reconnections fail
 				TEST_CHECK_THROWS(conn1.Open(Socket::TypeUNIX, "testfiles/srv2.sock");, ServerException, SocketAlreadyOpen);
 				// Stuff some data around
 				std::vector<IOStream *> conns;
 				conns.push_back(&conn1);
+#ifndef WIN32
 				conns.push_back(&conn2);
 				conns.push_back(&conn3);
+#endif // !WIN32
 				Srv2TestConversations(conns);
 				// Implicit close
 			}
+#ifndef WIN32
 			// HUP again
 			TEST_THAT(HUPServer(pid));
 			::sleep(1);
 			TEST_THAT(ServerIsAlive(pid));
+#endif // !WIN32
 			// Kill it
 			TEST_THAT(KillServer(pid));
 			::sleep(1);
 			TEST_THAT(!ServerIsAlive(pid));
+#ifndef WIN32
 			TestRemoteProcessMemLeaks("test-srv2.memleaks");
+#endif // !WIN32
 		}
 	}
 

Modified: box/chris/general/test/basicserver/testfiles/srv2.conf
===================================================================
--- box/chris/general/test/basicserver/testfiles/srv2.conf	2006-05-21 14:11:18 UTC (rev 580)
+++ box/chris/general/test/basicserver/testfiles/srv2.conf	2006-05-22 13:03:59 UTC (rev 581)
@@ -1,6 +1,6 @@
 Server
 {
 	PidFile = testfiles/srv2.pid
-	ListenAddresses = inet:localhost,unix:testfiles/srv2.sock
+	ListenAddresses = inet:localhost
 }
 


From boxbackup-dev@fluffy.co.uk  Tue May 23 01:32:43 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue, 23 May 2006 00:32:43 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r582 - in box/chris/general: lib/server lib/win32 test/basicserver test/basicserver/testfiles
Message-ID: <20060523003243.D108C96@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-23 00:31:58 +0000 (Tue, 23 May 2006)
New Revision: 582

Modified:
   box/chris/general/lib/server/SocketStream.cpp
   box/chris/general/lib/server/SocketStream.h
   box/chris/general/lib/server/SocketStreamTLS.cpp
   box/chris/general/lib/win32/emu.cpp
   box/chris/general/test/basicserver/testbasicserver.cpp
   box/chris/general/test/basicserver/testfiles/srv3.conf
   box/chris/general/test/basicserver/testfiles/srv4.conf
Log:
* test/basicserver/testfiles/srv3.conf
* test/basicserver/testfiles/srv4.conf
- Fixed for Windows (breaks Unix)

* test/basicserver/testbasicserver.cpp
- Wakey wakey: don't sleep 1000 times too long
- Fixed test servers 3 and 4 command lines and PID file path on Windows
- Don't hup servers 3 and 4 on Windows, or check for memory leaks
- Don't try to use Unix sockets on Windows, it doesn't work and annoys the beast

* lib/win32/emu.cpp
- Better implementation of poll()

* lib/server/SocketStream.h
* lib/server/SocketStream.cpp
- Fixed invalid handle values (signed vs unsigned comparison)

* lib/server/SocketStreamTLS.cpp
- Fixed non-blocking sockets on Windows


Modified: box/chris/general/lib/server/SocketStream.cpp
===================================================================
--- box/chris/general/lib/server/SocketStream.cpp	2006-05-22 13:03:59 UTC (rev 581)
+++ box/chris/general/lib/server/SocketStream.cpp	2006-05-23 00:31:58 UTC (rev 582)
@@ -36,7 +36,7 @@
 //
 // --------------------------------------------------------------------------
 SocketStream::SocketStream()
-	: mSocketHandle(-1),
+	: mSocketHandle(mInvalidHandle),
 	  mReadClosed(false),
 	  mWriteClosed(false),
 	  mBytesRead(0),
@@ -85,7 +85,7 @@
 	{
 		THROW_EXCEPTION(ServerException, BadSocketHandle);
 	}
-	if(mSocketHandle == -1)
+	if(mSocketHandle == mInvalidHandle)
 	{
 		THROW_EXCEPTION(ServerException, DupError);
 	}
@@ -101,7 +101,7 @@
 // --------------------------------------------------------------------------
 SocketStream::~SocketStream()
 {
-	if(mSocketHandle != -1)
+	if(mSocketHandle != mInvalidHandle)
 	{
 		Close();
 	}
@@ -117,7 +117,10 @@
 // --------------------------------------------------------------------------
 void SocketStream::Attach(int socket)
 {
-	if(mSocketHandle != -1) {THROW_EXCEPTION(ServerException, SocketAlreadyOpen)}
+	if(mSocketHandle != mInvalidHandle) 
+	{
+		THROW_EXCEPTION(ServerException, SocketAlreadyOpen)
+	}
 
 	mSocketHandle = socket;
 	ResetCounters();
@@ -134,7 +137,10 @@
 // --------------------------------------------------------------------------
 void SocketStream::Open(int Type, const char *Name, int Port)
 {
-	if(mSocketHandle != -1) {THROW_EXCEPTION(ServerException, SocketAlreadyOpen)}
+	if(mSocketHandle != mInvalidHandle) 
+	{
+		THROW_EXCEPTION(ServerException, SocketAlreadyOpen)
+	}
 	
 	// Setup parameters based on type, looking up names if required
 	int sockDomain = 0;
@@ -144,7 +150,7 @@
 
 	// Create the socket
 	mSocketHandle = ::socket(sockDomain, SOCK_STREAM, 0 /* let OS choose protocol */);
-	if(mSocketHandle == -1)
+	if(mSocketHandle == mInvalidHandle)
 	{
 		THROW_EXCEPTION(ServerException, SocketOpenError)
 	}
@@ -158,7 +164,7 @@
 #else
 		::close(mSocketHandle);
 #endif
-		mSocketHandle = -1;
+		mSocketHandle = mInvalidHandle;
 		THROW_EXCEPTION(ConnectionException, Conn_SocketConnectError)
 	}
 	ResetCounters();
@@ -174,7 +180,10 @@
 // --------------------------------------------------------------------------
 int SocketStream::Read(void *pBuffer, int NBytes, int Timeout)
 {
-	if(mSocketHandle == -1) {THROW_EXCEPTION(ServerException, BadSocketHandle)}
+	if(mSocketHandle == mInvalidHandle) 
+	{
+		THROW_EXCEPTION(ServerException, BadSocketHandle)
+	}
 
 	if(Timeout != IOStream::TimeOutInfinite)
 	{
@@ -247,7 +256,10 @@
 // --------------------------------------------------------------------------
 void SocketStream::Write(const void *pBuffer, int NBytes)
 {
-	if(mSocketHandle == -1) {THROW_EXCEPTION(ServerException, BadSocketHandle)}
+	if(mSocketHandle == mInvalidHandle) 
+	{
+		THROW_EXCEPTION(ServerException, BadSocketHandle)
+	}
 	
 	// Buffer in byte sized type.
 	ASSERT(sizeof(char) == 1);
@@ -311,7 +323,10 @@
 // --------------------------------------------------------------------------
 void SocketStream::Close()
 {
-	if(mSocketHandle == -1) {THROW_EXCEPTION(ServerException, BadSocketHandle)}
+	if(mSocketHandle == mInvalidHandle) 
+	{
+		THROW_EXCEPTION(ServerException, BadSocketHandle)
+	}
 #ifdef WIN32
 	if(::closesocket(mSocketHandle) == -1)
 #else
@@ -333,7 +348,10 @@
 // --------------------------------------------------------------------------
 void SocketStream::Shutdown(bool Read, bool Write)
 {
-	if(mSocketHandle == -1) {THROW_EXCEPTION(ServerException, BadSocketHandle)}
+	if(mSocketHandle == mInvalidHandle) 
+	{
+		THROW_EXCEPTION(ServerException, BadSocketHandle)
+	}
 	
 	// Do anything?
 	if(!Read && !Write) return;
@@ -388,7 +406,10 @@
 // --------------------------------------------------------------------------
 tOSSocketHandle SocketStream::GetSocketHandle()
 {
-	if(mSocketHandle == -1) {THROW_EXCEPTION(ServerException, BadSocketHandle)}
+	if(mSocketHandle == mInvalidHandle) 
+	{
+		THROW_EXCEPTION(ServerException, BadSocketHandle)
+	}
 	return mSocketHandle;
 }
 

Modified: box/chris/general/lib/server/SocketStream.h
===================================================================
--- box/chris/general/lib/server/SocketStream.h	2006-05-22 13:03:59 UTC (rev 581)
+++ box/chris/general/lib/server/SocketStream.h	2006-05-23 00:31:58 UTC (rev 582)
@@ -56,6 +56,7 @@
 	tOSSocketHandle mSocketHandle;
 	bool mReadClosed;
 	bool mWriteClosed;
+	static const tOSSocketHandle mInvalidHandle = -1;
 
 protected:
 	off_t mBytesRead;

Modified: box/chris/general/lib/server/SocketStreamTLS.cpp
===================================================================
--- box/chris/general/lib/server/SocketStreamTLS.cpp	2006-05-22 13:03:59 UTC (rev 581)
+++ box/chris/general/lib/server/SocketStreamTLS.cpp	2006-05-23 00:31:58 UTC (rev 582)
@@ -137,8 +137,12 @@
 		THROW_EXCEPTION(ServerException, TLSAllocationFailed)
 	}
 
-#ifndef WIN32
 	// Make the socket non-blocking so timeouts on Read work
+
+#ifdef WIN32
+	u_long nonblocking = 1;
+	ioctlsocket(socket, FIONBIO, &nonblocking);
+#else // !WIN32
 	// This is more portable than using ioctl with FIONBIO
 	int statusFlags = 0;
 	if(::fcntl(socket, F_GETFL, &statusFlags) < 0
@@ -309,7 +313,7 @@
 
 		case SSL_ERROR_WANT_READ:
 		case SSL_ERROR_WANT_WRITE:
-			// wait for the requried data
+			// wait for the required data
 			// Will only get once around this loop, so don't need to calculate timeout values
 			if(WaitWhenRetryRequired(se, Timeout) == false)
 			{

Modified: box/chris/general/lib/win32/emu.cpp
===================================================================
--- box/chris/general/lib/win32/emu.cpp	2006-05-22 13:03:59 UTC (rev 581)
+++ box/chris/general/lib/win32/emu.cpp	2006-05-23 00:31:58 UTC (rev 582)
@@ -952,10 +952,10 @@
 		fd_set readfd;
 		fd_set writefd;
 
-		readfd.fd_count = 0;
-		writefd.fd_count = 0;
+		FD_ZERO(&readfd);
+		FD_ZERO(&writefd);
 
-		struct pollfd *ufdsTmp = ufds;
+		// struct pollfd *ufdsTmp = ufds;
 
 		timeval timOut;
 		timeval *tmpptr; 
@@ -968,41 +968,61 @@
 		timOut.tv_sec  = timeout / 1000;
 		timOut.tv_usec = timeout * 1000;
 
-		if (ufds->events & POLLIN)
+		for (int i = 0; i < nfds; i++)
 		{
-			for (unsigned long i = 0; i < nfds; i++)
+			struct pollfd* ufd = &(ufds[i]);
+
+			if (ufd->events & POLLIN)
 			{
-				readfd.fd_array[i] = ufdsTmp->fd;
-				readfd.fd_count++;
+				FD_SET(ufd->fd, &readfd);
 			}
-		}
 
-		if (ufds->events & POLLOUT)
-		{
-			for (unsigned long i = 0; i < nfds; i++)
+			if (ufd->events & POLLOUT)
 			{
+				FD_SET(ufd->fd, &writefd);
+			}
 
-				writefd.fd_array[i]=ufdsTmp->fd;
-				writefd.fd_count++;
+			if (ufd->events & ~(POLLIN | POLLOUT))
+			{
+				printf("Unsupported poll bits %d",
+					ufd->events);
+				return -1;
 			}
 		}	
 
-		int noffds = select(0, &readfd, &writefd, 0, tmpptr);
+		int nready = select(0, &readfd, &writefd, 0, tmpptr);
 
-		if (noffds == SOCKET_ERROR)
+		if (nready == SOCKET_ERROR)
 		{
 			// int errval = WSAGetLastError();
 
-			ufdsTmp = ufds;
+			struct pollfd* pufd = ufds;
 			for (unsigned long i = 0; i < nfds; i++)
 			{
-				ufdsTmp->revents = POLLERR;
-				ufdsTmp++;
+				pufd->revents = POLLERR;
+				pufd++;
 			}
 			return (-1);
 		}
+		else if (nready > 0)
+		{
+			for (int i = 0; i < nfds; i++)
+			{
+				struct pollfd *ufd = &(ufds[i]);
 
-		return noffds;
+				if (FD_ISSET(ufd->fd, &readfd))
+				{
+					ufd->revents |= POLLIN;
+				}
+
+				if (FD_ISSET(ufd->fd, &writefd))
+				{
+					ufd->revents |= POLLOUT;
+				}
+			}
+		}
+
+		return nready;
 	}
 	catch (...)
 	{

Modified: box/chris/general/test/basicserver/testbasicserver.cpp
===================================================================
--- box/chris/general/test/basicserver/testbasicserver.cpp	2006-05-22 13:03:59 UTC (rev 581)
+++ box/chris/general/test/basicserver/testbasicserver.cpp	2006-05-23 00:31:58 UTC (rev 582)
@@ -63,7 +63,7 @@
 void testservers_pause_before_reply()
 {
 #ifdef WIN32
-	Sleep(COMMS_SERVER_WAIT_BEFORE_REPLYING * 1000);
+	Sleep(COMMS_SERVER_WAIT_BEFORE_REPLYING);
 #else
 	struct timespec t;
 	t.tv_sec = 0;
@@ -545,15 +545,24 @@
 
 	// Launch a test SSL server
 	{
+#ifdef WIN32
+		int pid = LaunchServer("test srv3 testfiles\\srv3.conf", 
+			"testfiles\\srv3.pid");
+#else
 		int pid = LaunchServer("./test srv3 testfiles/srv3.conf", "testfiles/srv3.pid");
+#endif
 		TEST_THAT(pid != -1 && pid != 0);
 		if(pid > 0)
 		{
 			// Will it restart?
 			TEST_THAT(ServerIsAlive(pid));
+
+#ifndef WIN32
 			TEST_THAT(HUPServer(pid));
 			::sleep(1);
 			TEST_THAT(ServerIsAlive(pid));
+#endif
+
 			// Make some connections
 			{
 				// SSL library
@@ -568,36 +577,50 @@
 
 				SocketStreamTLS conn1;
 				conn1.Open(context, Socket::TypeINET, "localhost", 2003);
+#ifndef WIN32
 				SocketStreamTLS conn2;
 				conn2.Open(context, Socket::TypeUNIX, "testfiles/srv3.sock");
 				SocketStreamTLS conn3;
 				conn3.Open(context, Socket::TypeINET, "localhost", 2003);
+#endif
 				// Quick check that reconnections fail
 				TEST_CHECK_THROWS(conn1.Open(context, Socket::TypeUNIX, "testfiles/srv3.sock");, ServerException, SocketAlreadyOpen);
 				// Stuff some data around
 				std::vector<IOStream *> conns;
 				conns.push_back(&conn1);
+#ifndef WIN32
 				conns.push_back(&conn2);
 				conns.push_back(&conn3);
+#endif
 				Srv2TestConversations(conns);
 				// Implicit close
 			}
+#ifndef WIN32
 			// HUP again
 			TEST_THAT(HUPServer(pid));
 			::sleep(1);
 			TEST_THAT(ServerIsAlive(pid));
+#endif
 			// Kill it
 			TEST_THAT(KillServer(pid));
 			::sleep(1);
 			TEST_THAT(!ServerIsAlive(pid));
+#ifndef WIN32
 			TestRemoteProcessMemLeaks("test-srv3.memleaks");
+#endif
 		}
 	}
 	
 //protocolserver:
 	// Launch a test protocol handling server
 	{
-		int pid = LaunchServer("./test srv4 testfiles/srv4.conf", "testfiles/srv4.pid");
+#ifdef WIN32
+		int pid = LaunchServer("test srv4 testfiles\\srv4.conf", 
+			"testfiles\\srv4.pid");
+#else
+		int pid = LaunchServer("./test srv4 testfiles/srv4.conf", 
+			"testfiles/srv4.pid");
+#endif
 		TEST_THAT(pid != -1 && pid != 0);
 		if(pid > 0)
 		{
@@ -606,7 +629,11 @@
 
 			// Open a connection to it		
 			SocketStream conn;
+#ifdef WIN32
+			conn.Open(Socket::TypeINET, "localhost", 2003);
+#else
 			conn.Open(Socket::TypeUNIX, "testfiles/srv4.sock");
+#endif
 			
 			// Create a protocol
 			TestProtocolClient protocol(conn);
@@ -669,7 +696,9 @@
 			TEST_THAT(KillServer(pid));
 			::sleep(1);
 			TEST_THAT(!ServerIsAlive(pid));
+#ifndef WIN32
 			TestRemoteProcessMemLeaks("test-srv4.memleaks");
+#endif
 		}
 	}
 

Modified: box/chris/general/test/basicserver/testfiles/srv3.conf
===================================================================
--- box/chris/general/test/basicserver/testfiles/srv3.conf	2006-05-22 13:03:59 UTC (rev 581)
+++ box/chris/general/test/basicserver/testfiles/srv3.conf	2006-05-23 00:31:58 UTC (rev 582)
@@ -1,9 +1,9 @@
 Server
 {
-	PidFile = testfiles/srv3.pid
-	ListenAddresses = inet:localhost,unix:testfiles/srv3.sock
-	CertificateFile = testfiles/serverCerts.pem
-	PrivateKeyFile = testfiles/serverPrivKey.pem
-	TrustedCAsFile = testfiles/serverTrustedCAs.pem
+	PidFile = testfiles\srv3.pid
+	ListenAddresses = inet:localhost
+	CertificateFile = testfiles\serverCerts.pem
+	PrivateKeyFile = testfiles\serverPrivKey.pem
+	TrustedCAsFile = testfiles\serverTrustedCAs.pem
 }
 

Modified: box/chris/general/test/basicserver/testfiles/srv4.conf
===================================================================
--- box/chris/general/test/basicserver/testfiles/srv4.conf	2006-05-22 13:03:59 UTC (rev 581)
+++ box/chris/general/test/basicserver/testfiles/srv4.conf	2006-05-23 00:31:58 UTC (rev 582)
@@ -1,6 +1,6 @@
 Server
 {
-	PidFile = testfiles/srv4.pid
-	ListenAddresses = unix:testfiles/srv4.sock
+	PidFile = testfiles\srv4.pid
+	ListenAddresses = inet:localhost
 }
 


From boxbackup-dev@fluffy.co.uk  Tue May 23 02:24:53 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue, 23 May 2006 01:24:53 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r583 - in box/chris/general: . bin/bbstored test/backupstore test/backupstore/testfiles
Message-ID: <20060523012453.6176996@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-23 01:24:17 +0000 (Tue, 23 May 2006)
New Revision: 583

Modified:
   box/chris/general/bin/bbstored/BBStoreDHousekeeping.cpp
   box/chris/general/bin/bbstored/BackupCommands.cpp
   box/chris/general/bin/bbstored/BackupStoreDaemon.cpp
   box/chris/general/modules.txt
   box/chris/general/test/backupstore/testbackupstore.cpp
   box/chris/general/test/backupstore/testfiles/bbstored.conf
   box/chris/general/test/backupstore/testfiles/bbstored_multi.conf
   box/chris/general/test/backupstore/testfiles/query.conf
   box/chris/general/test/backupstore/testfiles/raidfile.conf
Log:
* modules.txt
- Compile lib/backupstore, bin/bbstored, bin/bbstoreaccounts, test/backupstore 
  on Win32

* bin/bbstored/BackupStoreDaemon.cpp
- Disable housekeeping daemon on Win32 (temporary hack)

* bin/bbstored/BackupCommands.cpp
* bin/bbstored/BBStoreDHousekeeping.cpp
- Don't include syslog.h unless we have one

* test/backupstore/testfiles/bbstored.conf
* test/backupstore/testfiles/query.conf
* test/backupstore/testfiles/bbstored_multi.conf
* test/backupstore/testfiles/raidfile.conf
- Hacked to work on Windows (broken on Unix)

* test/backupstore/testbackupstore.cpp
- Fixed some paths to work on Windows


Modified: box/chris/general/bin/bbstored/BBStoreDHousekeeping.cpp
===================================================================
--- box/chris/general/bin/bbstored/BBStoreDHousekeeping.cpp	2006-05-23 00:31:58 UTC (rev 582)
+++ box/chris/general/bin/bbstored/BBStoreDHousekeeping.cpp	2006-05-23 01:24:17 UTC (rev 583)
@@ -10,7 +10,10 @@
 #include "Box.h"
 
 #include <stdio.h>
+
+#ifdef HAVE_SYSLOG_H
 #include <syslog.h>
+#endif
 
 #include "BackupStoreDaemon.h"
 #include "BackupStoreAccountDatabase.h"

Modified: box/chris/general/bin/bbstored/BackupCommands.cpp
===================================================================
--- box/chris/general/bin/bbstored/BackupCommands.cpp	2006-05-23 00:31:58 UTC (rev 582)
+++ box/chris/general/bin/bbstored/BackupCommands.cpp	2006-05-23 01:24:17 UTC (rev 583)
@@ -9,7 +9,9 @@
 
 #include "Box.h"
 
+#ifdef HAVE_SYSLOG_H
 #include <syslog.h>
+#endif
 
 #include "autogen_BackupProtocolServer.h"
 #include "BackupConstants.h"

Modified: box/chris/general/bin/bbstored/BackupStoreDaemon.cpp
===================================================================
--- box/chris/general/bin/bbstored/BackupStoreDaemon.cpp	2006-05-23 00:31:58 UTC (rev 582)
+++ box/chris/general/bin/bbstored/BackupStoreDaemon.cpp	2006-05-23 01:24:17 UTC (rev 583)
@@ -11,9 +11,12 @@
 
 #include <stdlib.h>
 #include <stdio.h>
-#include <syslog.h>
 #include <signal.h>
 
+#ifdef HAVE_SYSLOG_H
+#include <syslog.h>
+#endif
+
 #include "BackupContext.h"
 #include "BackupStoreDaemon.h"
 #include "BackupStoreConfigVerify.h"
@@ -155,7 +158,8 @@
 	mExtendedLogging = false;
 	const Configuration &config(GetConfiguration());
 	mExtendedLogging = config.GetKeyValueBool("ExtendedLogging");
-	
+
+#ifndef WIN32	
 	// Fork off housekeeping daemon -- must only do this the first time Run() is called
 	if(!mHaveForkedHousekeeping)
 	{
@@ -211,6 +215,7 @@
 			THROW_EXCEPTION(ServerException, SocketCloseError)
 		}
 	}
+#endif // !WIN32
 
 	if(mIsHousekeepingProcess)
 	{

Modified: box/chris/general/modules.txt
===================================================================
--- box/chris/general/modules.txt	2006-05-23 00:31:58 UTC (rev 582)
+++ box/chris/general/modules.txt	2006-05-23 01:24:17 UTC (rev 583)
@@ -25,24 +25,25 @@
 # Backup system
 
 lib/backupclient	lib/server	lib/crypto	lib/compress
+lib/backupstore		lib/server	lib/raidfile	lib/backupclient
 
 OMIT:mingw32
 OMIT:mingw32msvc
 OMIT:CYGWIN
-lib/backupstore		lib/server	lib/raidfile	lib/backupclient
-bin/bbstored		lib/raidfile	lib/server	lib/backupstore	lib/backupclient	lib/win32
-bin/bbstoreaccounts	lib/raidfile	lib/backupstore	lib/win32
 bin/bbackupobjdump	lib/backupclient lib/backupstore	lib/win32
 END-OMIT
 
+bin/bbstored		lib/raidfile	lib/server	lib/backupstore	lib/backupclient	lib/win32
+bin/bbstoreaccounts	lib/raidfile	lib/backupstore	lib/win32
 bin/bbackupd		lib/server	lib/backupclient	lib/win32
 bin/bbackupquery	lib/server	lib/backupclient	lib/win32
 bin/bbackupctl		lib/server	lib/backupclient	lib/win32
 
+test/backupstore	bin/bbstored	bin/bbstoreaccounts lib/server lib/backupstore lib/backupclient lib/raidfile
+
 OMIT:mingw32
 OMIT:mingw32msvc
 OMIT:CYGWIN
-test/backupstore	bin/bbstored	bin/bbstoreaccounts lib/server lib/backupstore lib/backupclient lib/raidfile
 test/backupstorefix	bin/bbstored	bin/bbstoreaccounts	lib/backupstore	lib/raidfile	bin/bbackupquery	bin/bbackupd
 test/backupstorepatch	bin/bbstored	bin/bbstoreaccounts	lib/backupstore	lib/raidfile
 test/backupdiff		lib/backupclient

Modified: box/chris/general/test/backupstore/testbackupstore.cpp
===================================================================
--- box/chris/general/test/backupstore/testbackupstore.cpp	2006-05-23 00:31:58 UTC (rev 582)
+++ box/chris/general/test/backupstore/testbackupstore.cpp	2006-05-23 01:24:17 UTC (rev 583)
@@ -1520,35 +1520,48 @@
 		
 		// The test block to a file
 		{
-			FileStream f("testfiles/testenc1", O_WRONLY | O_CREAT | O_EXCL);
+			FileStream f("testfiles" DIRECTORY_SEPARATOR 
+				"testenc1", O_WRONLY | O_CREAT | O_EXCL);
 			f.Write(encfile, sizeof(encfile));
 		}
 		
 		// Encode it
 		{
-			FileStream out("testfiles/testenc1_enc", O_WRONLY | O_CREAT | O_EXCL);
-			BackupStoreFilenameClear name("testfiles/testenc1");
+			FileStream out("testfiles" DIRECTORY_SEPARATOR 
+				"testenc1_enc", O_WRONLY | O_CREAT | O_EXCL);
+			BackupStoreFilenameClear name("testfiles"
+				DIRECTORY_SEPARATOR "testenc1");
 
-			std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/testenc1", 32, name));
+			std::auto_ptr<IOStream> encoded(
+				BackupStoreFile::EncodeFile(
+					"testfiles" DIRECTORY_SEPARATOR
+					"testenc1", 32, name));
 			encoded->CopyStreamTo(out);
 		}
 		
 		// Verify it
 		{
-			FileStream enc("testfiles/testenc1_enc");
+			FileStream enc("testfiles" DIRECTORY_SEPARATOR 
+				"testenc1_enc");
 			TEST_THAT(BackupStoreFile::VerifyEncodedFileFormat(enc) == true);
 		}
 		
 		// Decode it
 		{
-			FileStream enc("testfiles/testenc1_enc");
-			BackupStoreFile::DecodeFile(enc, "testfiles/testenc1_orig", IOStream::TimeOutInfinite);
+			FileStream enc("testfiles" DIRECTORY_SEPARATOR 
+				"testenc1_enc");
+			BackupStoreFile::DecodeFile(enc, "testfiles"
+				DIRECTORY_SEPARATOR "testenc1_orig", 
+				IOStream::TimeOutInfinite);
 		}
 		
 		// Read in rebuilt original, and compare contents
 		{
-			TEST_THAT(TestGetFileSize("testfiles/testenc1_orig") == sizeof(encfile));
-			FileStream in("testfiles/testenc1_orig");
+			TEST_THAT(TestGetFileSize("testfiles" 
+				DIRECTORY_SEPARATOR "testenc1_orig") 
+				== sizeof(encfile));
+			FileStream in("testfiles" DIRECTORY_SEPARATOR 
+				"testenc1_orig");
 			int encfile_i[ENCFILE_SIZE];
 			in.Read(encfile_i, sizeof(encfile_i));
 			TEST_THAT(memcmp(encfile, encfile_i, sizeof(encfile)) == 0);
@@ -1556,7 +1569,8 @@
 		
 		// Check how many blocks it had, and test the stream based interface
 		{
-			FileStream enc("testfiles/testenc1_enc");
+			FileStream enc("testfiles" DIRECTORY_SEPARATOR 
+				"testenc1_enc");
 			std::auto_ptr<BackupStoreFile::DecodedStream> decoded(BackupStoreFile::DecodeFileStream(enc, IOStream::TimeOutInfinite));
 			CollectInBufferStream d;
 			decoded->CopyStreamTo(d, IOStream::TimeOutInfinite, 971 /* buffer block size */);
@@ -1570,10 +1584,14 @@
 		// Test that the last block in a file, if less than 256 bytes, gets put into the last block
 		{
 			#define FILE_SIZE_JUST_OVER	((4096*2)+58)
-			FileStream f("testfiles/testenc2", O_WRONLY | O_CREAT | O_EXCL);
+			FileStream f("testfiles" DIRECTORY_SEPARATOR 
+				"testenc2", O_WRONLY | O_CREAT | O_EXCL);
 			f.Write(encfile + 2, FILE_SIZE_JUST_OVER);
 			BackupStoreFilenameClear name("testenc2");
-			std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/testenc2", 32, name));
+			std::auto_ptr<IOStream> encoded(
+				BackupStoreFile::EncodeFile(
+					"testfiles" DIRECTORY_SEPARATOR
+					"testenc2", 32, name));
 			CollectInBufferStream e;
 			encoded->CopyStreamTo(e);
 			e.SetForReading();
@@ -1589,7 +1607,8 @@
 		
 		// Test that reordered streams work too
 		{
-			FileStream enc("testfiles/testenc1_enc");
+			FileStream enc("testfiles" DIRECTORY_SEPARATOR 
+				"testenc1_enc");
 			std::auto_ptr<IOStream> reordered(BackupStoreFile::ReorderFileToStreamOrder(&enc, false));
 			std::auto_ptr<BackupStoreFile::DecodedStream> decoded(BackupStoreFile::DecodeFileStream(*reordered, IOStream::TimeOutInfinite));
 			CollectInBufferStream d;
@@ -1600,7 +1619,8 @@
 
 			TEST_THAT(decoded->GetNumBlocks() == 3);
 		}
-		
+
+#ifndef WIN32		
 		// Try out doing this on a symlink
 		{
 			TEST_THAT(::symlink("does/not/exist", "testfiles/testsymlink") == 0);
@@ -1614,6 +1634,7 @@
 			// Decode it
 			BackupStoreFile::DecodeFile(b, "testfiles/testsymlink_2", IOStream::TimeOutInfinite);
 		}
+#endif
 	}
 
 	// Store info
@@ -1666,9 +1687,9 @@
 	// Context
 	TLSContext context;
 	context.Initialise(false /* client */,
-			"testfiles/clientCerts.pem",
-			"testfiles/clientPrivKey.pem",
-			"testfiles/clientTrustedCAs.pem");
+			"testfiles" DIRECTORY_SEPARATOR "clientCerts.pem",
+			"testfiles" DIRECTORY_SEPARATOR "clientPrivKey.pem",
+			"testfiles" DIRECTORY_SEPARATOR "clientTrustedCAs.pem");
 
 	// First, try logging in without an account having been created... just make sure login fails.
 	int pid = LaunchServer("../../bin/bbstored/bbstored testfiles/bbstored.conf", "testfiles/bbstored.pid");
@@ -1865,7 +1886,11 @@
 
 	// Use the setup crypto command to set up all these keys, so that the bbackupquery command can be used
 	// for seeing what's going on.
+#ifdef WIN32
+	BackupClientCryptoKeys_Setup("testfiles\\bbackupd.keys");	
+#else
 	BackupClientCryptoKeys_Setup("testfiles/bbackupd.keys");	
+#endif
 	
 	// encode in some filenames -- can't do static initialisation because the key won't be set up when these are initialised
 	for(unsigned int l = 0; l < sizeof(ens_filenames) / sizeof(ens_filenames[0]); ++l)

Modified: box/chris/general/test/backupstore/testfiles/bbstored.conf
===================================================================
--- box/chris/general/test/backupstore/testfiles/bbstored.conf	2006-05-23 00:31:58 UTC (rev 582)
+++ box/chris/general/test/backupstore/testfiles/bbstored.conf	2006-05-23 01:24:17 UTC (rev 583)
@@ -1,6 +1,6 @@
 
-RaidFileConf = testfiles/raidfile.conf
-AccountDatabase = testfiles/accounts.txt
+RaidFileConf = testfiles\raidfile.conf
+AccountDatabase = testfiles\accounts.txt
 
 ExtendedLogging = yes
 
@@ -8,10 +8,10 @@
 
 Server
 {
-	PidFile = testfiles/bbstored.pid
+	PidFile = testfiles\bbstored.pid
 	ListenAddresses = inet:localhost
-	CertificateFile = testfiles/serverCerts.pem
-	PrivateKeyFile = testfiles/serverPrivKey.pem
-	TrustedCAsFile = testfiles/serverTrustedCAs.pem
+	CertificateFile = testfiles\serverCerts.pem
+	PrivateKeyFile = testfiles\serverPrivKey.pem
+	TrustedCAsFile = testfiles\serverTrustedCAs.pem
 }
 

Modified: box/chris/general/test/backupstore/testfiles/bbstored_multi.conf
===================================================================
--- box/chris/general/test/backupstore/testfiles/bbstored_multi.conf	2006-05-23 00:31:58 UTC (rev 582)
+++ box/chris/general/test/backupstore/testfiles/bbstored_multi.conf	2006-05-23 01:24:17 UTC (rev 583)
@@ -1,16 +1,16 @@
 
-RaidFileConf = testfiles/raidfile.conf
-AccountDatabase = testfiles/accounts.txt
+RaidFileConf = testfiles\raidfile.conf
+AccountDatabase = testfiles\accounts.txt
 
 TimeBetweenHousekeeping = 5
 
 Server
 {
-	PidFile = testfiles/bbstored.pid
+	PidFile = testfiles\bbstored.pid
 	# 0.0.0.0 is the 'any' address, allowing connections from things other than localhost
 	ListenAddresses = inet:0.0.0.0
-	CertificateFile = testfiles/serverCerts.pem
-	PrivateKeyFile = testfiles/serverPrivKey.pem
-	TrustedCAsFile = testfiles/serverTrustedCAs.pem
+	CertificateFile = testfiles\serverCerts.pem
+	PrivateKeyFile = testfiles\serverPrivKey.pem
+	TrustedCAsFile = testfiles\serverTrustedCAs.pem
 }
 

Modified: box/chris/general/test/backupstore/testfiles/query.conf
===================================================================
--- box/chris/general/test/backupstore/testfiles/query.conf	2006-05-23 00:31:58 UTC (rev 582)
+++ box/chris/general/test/backupstore/testfiles/query.conf	2006-05-23 01:24:17 UTC (rev 583)
@@ -2,13 +2,13 @@
 # this is a dummy config file so that bbackupquery can be used
 
 
-CertificateFile = testfiles/clientCerts.pem
-PrivateKeyFile = testfiles/clientPrivKey.pem
-TrustedCAsFile = testfiles/clientTrustedCAs.pem
+CertificateFile = testfiles\clientCerts.pem
+PrivateKeyFile = testfiles\clientPrivKey.pem
+TrustedCAsFile = testfiles\clientTrustedCAs.pem
 
-KeysFile = testfiles/bbackupd.keys
+KeysFile = testfiles\bbackupd.keys
 
-DataDirectory = testfiles/bbackupd-data
+DataDirectory = testfiles\bbackupd-data
 
 StoreHostname = localhost
 AccountNumber = 0x01234567
@@ -20,7 +20,7 @@
 
 Server
 {
-	PidFile = testfiles/bbackupd.pid
+	PidFile = testfiles\bbackupd.pid
 }
 
 # this is just a dummy entry
@@ -28,7 +28,7 @@
 {
 	test_delete
 	{
-		Path = testfiles/test_delete
+		Path = testfiles\test_delete
 	}
 }
 

Modified: box/chris/general/test/backupstore/testfiles/raidfile.conf
===================================================================
--- box/chris/general/test/backupstore/testfiles/raidfile.conf	2006-05-23 00:31:58 UTC (rev 582)
+++ box/chris/general/test/backupstore/testfiles/raidfile.conf	2006-05-23 01:24:17 UTC (rev 583)
@@ -3,8 +3,8 @@
 {
 	SetNumber = 0
 	BlockSize = 2048
-	Dir0 = testfiles/0_0
-	Dir1 = testfiles/0_1
-	Dir2 = testfiles/0_2
+	Dir0 = testfiles\0_0
+	Dir1 = testfiles\0_1
+	Dir2 = testfiles\0_2
 }
 


From boxbackup-dev@fluffy.co.uk  Tue May 23 10:16:56 2006
From: boxbackup-dev@fluffy.co.uk (Ben Summers)
Date: Tue, 23 May 2006 10:16:56 +0100
Subject: [Box Backup-dev] COMMIT r582 - in box/chris/general: lib/server lib/win32 test/basicserver test/basicserver/testfiles
In-Reply-To: <20060523003243.D108C96@s0g0.pems.testserver.co.uk>
References: <20060523003243.D108C96@s0g0.pems.testserver.co.uk>
Message-ID: <2F95E18B-3583-4103-B060-F21AD0DBA558@fluffy.co.uk>

>
> Modified: box/chris/general/test/basicserver/testfiles/srv3.conf
> ===================================================================
> --- box/chris/general/test/basicserver/testfiles/srv3.conf	 
> 2006-05-22 13:03:59 UTC (rev 581)
> +++ box/chris/general/test/basicserver/testfiles/srv3.conf	 
> 2006-05-23 00:31:58 UTC (rev 582)
> @@ -1,9 +1,9 @@
>  Server
>  {
> -	PidFile = testfiles/srv3.pid
> -	ListenAddresses = inet:localhost,unix:testfiles/srv3.sock
> -	CertificateFile = testfiles/serverCerts.pem
> -	PrivateKeyFile = testfiles/serverPrivKey.pem
> -	TrustedCAsFile = testfiles/serverTrustedCAs.pem
> +	PidFile = testfiles\srv3.pid
> +	ListenAddresses = inet:localhost
> +	CertificateFile = testfiles\serverCerts.pem
> +	PrivateKeyFile = testfiles\serverPrivKey.pem
> +	TrustedCAsFile = testfiles\serverTrustedCAs.pem
>  }
>

I thought the clib on win32 translated path separators automatically?

Ben





From boxbackup-dev@fluffy.co.uk  Tue May 23 18:49:21 2006
From: boxbackup-dev@fluffy.co.uk (Chris Wilson)
Date: Tue, 23 May 2006 17:49:21 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r582 - in box/chris/general: lib/server
 lib/win32 test/basicserver test/basicserver/testfiles
In-Reply-To: <2F95E18B-3583-4103-B060-F21AD0DBA558@fluffy.co.uk>
References: <20060523003243.D108C96@s0g0.pems.testserver.co.uk>
 <2F95E18B-3583-4103-B060-F21AD0DBA558@fluffy.co.uk>
Message-ID: <Pine.LNX.4.64.0605231747250.5176@localhost>

Hi Ben,

> I thought the clib on win32 translated path separators automatically?

Unfortunately not. We are using openfile() from emu.cpp instead of 
open(), but I get error 123 (ERROR_INVALID_NAME) when opening a filename 
containing a forward slash.

We could rewrite these to backslashes in openfile(). It would save a lot 
of conditional code in the unit tests, and solve the problem of supplying 
different config files for win32. I will try it and see how it works.

Cheers, Chris.
-- 
_ ___ __     _
  / __/ / ,__(_)_  | Chris Wilson <0000 at qwirx.com> - Cambs UK |
/ (_/ ,\/ _/ /_ \ | Security/C/C++/Java/Perl/SQL/HTML Developer |
\ _/_/_/_//_/___/ | We are GNU-free your mind-and your software |

From boxbackup-dev@fluffy.co.uk  Thu May 25 20:51:23 2006
From: boxbackup-dev@fluffy.co.uk (Pascal Lalonde)
Date: Thu, 25 May 2006 15:51:23 -0400
Subject: [Box Backup-dev] CreateNamedPipeW()'s return value on error (Win32)
Message-ID: <44760ABB.5060601@overnet.qc.ca>

Are you sure that CreateNamedPipeW() returns NULL on error?

I had this:
ConnectNamedPipe failed: 6
CloseHandle failed: 6

According to
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/system_error_codes__0-499_.asp,
error 6 would be ERROR_INVALID_HANDLE. I'd expect to get a error from 
CreateNamedPipeW(), but I get none.

In lib/win32/WinNamedPipeStream.cpp at line 128, mSocketHandle is 
compared against NULL for errors.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/base/createnamedpipe.asp 
states that CreateNamedPipe() returns INVALID_HANDLE_VALUE on error, not 
NULL, which would explain this behavior.

I don't know if this is true for every flavor of Windows though. I 
experienced this on Windows XP Pro SP2. Using r568.

Pascal

From boxbackup-dev@fluffy.co.uk  Thu May 25 21:15:18 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Thu, 25 May 2006 20:15:18 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r584 - box/chris/general/lib/win32
Message-ID: <20060525201518.1266096@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-25 20:15:09 +0000 (Thu, 25 May 2006)
New Revision: 584

Modified:
   box/chris/general/lib/win32/WinNamedPipeStream.cpp
Log:
* WinNamedPipeStream.cpp
- Compare handle against INVALID_HANDLE_VALUE rather than NULL
  (thanks to Pascal Lalonde for spotting this)


Modified: box/chris/general/lib/win32/WinNamedPipeStream.cpp
===================================================================
--- box/chris/general/lib/win32/WinNamedPipeStream.cpp	2006-05-23 01:24:17 UTC (rev 583)
+++ box/chris/general/lib/win32/WinNamedPipeStream.cpp	2006-05-25 20:15:09 UTC (rev 584)
@@ -35,7 +35,7 @@
 //
 // --------------------------------------------------------------------------
 WinNamedPipeStream::WinNamedPipeStream()
-	: mSocketHandle(NULL),
+	: mSocketHandle(INVALID_HANDLE_VALUE),
 	  mReadableEvent(INVALID_HANDLE_VALUE),
 	  mBytesInBuffer(0),
 	  mReadClosed(false),
@@ -55,7 +55,7 @@
 // --------------------------------------------------------------------------
 WinNamedPipeStream::~WinNamedPipeStream()
 {
-	if (mSocketHandle != NULL)
+	if (mSocketHandle != INVALID_HANDLE_VALUE)
 	{
 		Close();
 	}
@@ -72,7 +72,7 @@
 // --------------------------------------------------------------------------
 void WinNamedPipeStream::Accept(const wchar_t* pName)
 {
-	if (mSocketHandle != NULL || mIsConnected) 
+	if (mSocketHandle != INVALID_HANDLE_VALUE || mIsConnected) 
 	{
 		THROW_EXCEPTION(ServerException, SocketAlreadyOpen)
 	}
@@ -90,7 +90,7 @@
 		NMPWAIT_USE_DEFAULT_WAIT,  // client time-out 
 		NULL);                     // default security attribute 
 
-	if (mSocketHandle == NULL)
+	if (mSocketHandle == INVALID_HANDLE_VALUE)
 	{
 		::syslog(LOG_ERR, "CreateNamedPipeW failed: %d", 
 			GetLastError());
@@ -154,7 +154,7 @@
 // --------------------------------------------------------------------------
 void WinNamedPipeStream::Connect(const wchar_t* pName)
 {
-	if (mSocketHandle != NULL || mIsConnected) 
+	if (mSocketHandle != INVALID_HANDLE_VALUE || mIsConnected) 
 	{
 		THROW_EXCEPTION(ServerException, SocketAlreadyOpen)
 	}
@@ -198,7 +198,7 @@
 		THROW_EXCEPTION(CommonException, AssertFailed)
 	}
 	
-	if (mSocketHandle == NULL || !mIsConnected) 
+	if (mSocketHandle == INVALID_HANDLE_VALUE || !mIsConnected) 
 	{
 		THROW_EXCEPTION(ServerException, BadSocketHandle)
 	}
@@ -306,7 +306,7 @@
 // --------------------------------------------------------------------------
 void WinNamedPipeStream::Write(const void *pBuffer, int NBytes)
 {
-	if (mSocketHandle == NULL || !mIsConnected) 
+	if (mSocketHandle == INVALID_HANDLE_VALUE || !mIsConnected) 
 	{
 		THROW_EXCEPTION(ServerException, BadSocketHandle)
 	}
@@ -349,14 +349,14 @@
 // --------------------------------------------------------------------------
 void WinNamedPipeStream::Close()
 {
-	if (mSocketHandle == NULL && mIsConnected)
+	if (mSocketHandle == INVALID_HANDLE_VALUE && mIsConnected)
 	{
 		fprintf(stderr, "Inconsistent connected state\n");
 		::syslog(LOG_ERR, "Inconsistent connected state");
 		mIsConnected = false;
 	}
 
-	if (mSocketHandle == NULL) 
+	if (mSocketHandle == INVALID_HANDLE_VALUE) 
 	{
 		THROW_EXCEPTION(ServerException, BadSocketHandle)
 	}
@@ -399,7 +399,7 @@
 
 	bool result = CloseHandle(mSocketHandle);
 
-	mSocketHandle = NULL;
+	mSocketHandle = INVALID_HANDLE_VALUE;
 	mIsConnected = false;
 	mReadClosed  = true;
 	mWriteClosed = true;
@@ -447,7 +447,7 @@
 // --------------------------------------------------------------------------
 void WinNamedPipeStream::WriteAllBuffered()
 {
-	if (mSocketHandle == NULL || !mIsConnected) 
+	if (mSocketHandle == INVALID_HANDLE_VALUE || !mIsConnected) 
 	{
 		THROW_EXCEPTION(ServerException, BadSocketHandle)
 	}


From boxbackup-dev@fluffy.co.uk  Thu May 25 21:16:59 2006
From: boxbackup-dev@fluffy.co.uk (Chris Wilson)
Date: Thu, 25 May 2006 20:16:59 +0000 (GMT)
Subject: [Box Backup-dev] CreateNamedPipeW()'s return value on error
 (Win32)
In-Reply-To: <44760ABB.5060601@overnet.qc.ca>
References: <44760ABB.5060601@overnet.qc.ca>
Message-ID: <Pine.LNX.4.64.0605252015060.5176@localhost>

Hi Pascal,

> According to 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/system_error_codes__0-499_.asp, 
> error 6 would be ERROR_INVALID_HANDLE. I'd expect to get a error from 
> CreateNamedPipeW(), but I get none.
>
> In lib/win32/WinNamedPipeStream.cpp at line 128, mSocketHandle is 
> compared against NULL for errors.
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/base/createnamedpipe.asp 
> states that CreateNamedPipe() returns INVALID_HANDLE_VALUE on error, not 
> NULL, which would explain this behavior.

You are absolutely right. I guess I had assumed that INVALID_HANDLE_VALUE 
was the same as NULL. I've just checked in a fix to my tree.

> I had this:
> ConnectNamedPipe failed: 6
> CloseHandle failed: 6

How did this happen? Were you running more than one copy of bbackupd.exe?

> I don't know if this is true for every flavor of Windows though. I 
> experienced this on Windows XP Pro SP2. Using r568.

Better safe than sorry. INVALID_HANDLE_VALUE it is, and shall be forever 
more.

Cheers, Chris.
-- 
_ ___ __     _
  / __/ / ,__(_)_  | Chris Wilson <0000 at qwirx.com> - Cambs UK |
/ (_/ ,\/ _/ /_ \ | Security/C/C++/Java/Perl/SQL/HTML Developer |
\ _/_/_/_//_/___/ | We are GNU-free your mind-and your software |

From boxbackup-dev@fluffy.co.uk  Thu May 25 22:24:11 2006
From: boxbackup-dev@fluffy.co.uk (Pascal Lalonde)
Date: Thu, 25 May 2006 17:24:11 -0400
Subject: [Box Backup-dev] CreateNamedPipeW()'s return value on error (Win32)
In-Reply-To: <Pine.LNX.4.64.0605252015060.5176@localhost>
References: <44760ABB.5060601@overnet.qc.ca>
 <Pine.LNX.4.64.0605252015060.5176@localhost>
Message-ID: <4476207B.5070901@overnet.qc.ca>

Chris Wilson wrote:
> 
> How did this happen? Were you running more than one copy of bbackupd.exe?
> 

I think the person was trying to start bbackupd too soon after it had 
stopped (less than 1 second). What really tickled me is the way the 
error was reported. I found it strange that CreateNamedPipeW() 
succeeded, while the following calls failed.

From boxbackup-dev@fluffy.co.uk  Sat May 27 10:42:40 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 27 May 2006 09:42:40 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r585 - box/chris/general/test/backupstore
Message-ID: <20060527094240.F07C296@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-27 09:42:31 +0000 (Sat, 27 May 2006)
New Revision: 585

Modified:
   box/chris/general/test/backupstore/testbackupstore.cpp
Log:
* testbackupstore.cpp
- Fixed some files left open, prevents unlink on Win32
- Disabled some test code that doesn't work on Win32 (e.g. multiple
  connections to store, memory leak tests)
- Fixed directory separators and process launching
- Added a test for opening the same file twice (used to fail) on Win32
- Initialise WinSock on Win32


Modified: box/chris/general/test/backupstore/testbackupstore.cpp
===================================================================
--- box/chris/general/test/backupstore/testbackupstore.cpp	2006-05-25 20:15:09 UTC (rev 584)
+++ box/chris/general/test/backupstore/testbackupstore.cpp	2006-05-27 09:42:31 UTC (rev 585)
@@ -425,7 +425,8 @@
 	}
 	
 	free(data);
-	unlink("testfiles/test_download");
+	in.Close();
+	TEST_THAT(unlink("testfiles/test_download") == 0);
 }
 
 void test_everything_deleted(BackupProtocolClient &protocol, int64_t DirID)
@@ -930,6 +931,7 @@
 		// Check marker is 0
 		TEST_THAT(loginConf->GetClientStoreMarker() == 0);
 
+#ifndef WIN32
 		// Check that we can't open a new connection which requests write permissions
 		{
 			SocketStreamTLS conn;
@@ -941,10 +943,12 @@
 				ConnectionException, Conn_Protocol_UnexpectedReply);
 			protocol.QueryFinished();
 		}
+#endif
 		
 		// Set the client store marker
 		protocol.QuerySetClientStoreMarker(0x8732523ab23aLL);
 
+#ifndef WIN32
 		// Open a new connection which is read only
 		SocketStreamTLS connReadOnly;
 		connReadOnly.Open(context, Socket::TypeINET, hostname, BOX_PORT_BBSTORED);
@@ -963,10 +967,11 @@
 			// Check client store marker
 			TEST_THAT(loginConf->GetClientStoreMarker() == 0x8732523ab23aLL);
 		}
+#else // WIN32
+		BackupProtocolClient& protocolReadOnly(protocol);
+#endif
 
 		test_server_1(protocol, protocolReadOnly);
-
-
 		// Create and upload some test files
 		int64_t maxID = 0;
 		for(int t = 0; t < UPLOAD_NUM; ++t)
@@ -1438,11 +1443,15 @@
 		}
 			
 		// Finish the connections
+#ifndef WIN32
 		protocolReadOnly.QueryFinished();
+#endif
 		protocol.QueryFinished();
 		
 		// Close logs
+#ifndef WIN32
 		::fclose(protocolReadOnlyLog);
+#endif
 		::fclose(protocolLog);
 	}
 	
@@ -1587,6 +1596,7 @@
 			FileStream f("testfiles" DIRECTORY_SEPARATOR 
 				"testenc2", O_WRONLY | O_CREAT | O_EXCL);
 			f.Write(encfile + 2, FILE_SIZE_JUST_OVER);
+			f.Close();
 			BackupStoreFilenameClear name("testenc2");
 			std::auto_ptr<IOStream> encoded(
 				BackupStoreFile::EncodeFile(
@@ -1640,9 +1650,14 @@
 	// Store info
 	{
 		RaidFileWrite::CreateDirectory(0, "test-info");
-		BackupStoreInfo::CreateNew(76, "test-info/", 0, 3461231233455433LL, 2934852487LL);
-		TEST_CHECK_THROWS(BackupStoreInfo::CreateNew(76, "test-info/", 0, 0, 0), RaidFileException, CannotOverwriteExistingFile);
-		std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(76, "test-info/", 0, true));
+		BackupStoreInfo::CreateNew(76, "test-info" DIRECTORY_SEPARATOR, 
+			0, 3461231233455433LL, 2934852487LL);
+		TEST_CHECK_THROWS(BackupStoreInfo::CreateNew(76, 
+			"test-info" DIRECTORY_SEPARATOR, 0, 0, 0), 
+			RaidFileException, CannotOverwriteExistingFile);
+		std::auto_ptr<BackupStoreInfo> info(
+			BackupStoreInfo::Load(76, 
+				"test-info" DIRECTORY_SEPARATOR, 0, true));
 		TEST_CHECK_THROWS(info->Save(), BackupStoreException, StoreInfoIsReadOnly);
 		TEST_CHECK_THROWS(info->ChangeBlocksUsed(1), BackupStoreException, StoreInfoIsReadOnly);
 		TEST_CHECK_THROWS(info->ChangeBlocksInOldFiles(1), BackupStoreException, StoreInfoIsReadOnly);
@@ -1651,7 +1666,8 @@
 		TEST_CHECK_THROWS(info->AddDeletedDirectory(2), BackupStoreException, StoreInfoIsReadOnly);
 	}
 	{
-		std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(76, "test-info/", 0, false));
+		std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(76, 
+			"test-info" DIRECTORY_SEPARATOR, 0, false));
 		info->ChangeBlocksUsed(8);
 		info->ChangeBlocksInOldFiles(9);
 		info->ChangeBlocksInDeletedFiles(10);
@@ -1669,7 +1685,8 @@
 		info->Save();
 	}
 	{
-		std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(76, "test-info/", 0, true));
+		std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(76, 
+			"test-info" DIRECTORY_SEPARATOR, 0, true));
 		TEST_THAT(info->GetBlocksUsed() == 7);
 		TEST_THAT(info->GetBlocksInOldFiles() == 5);
 		TEST_THAT(info->GetBlocksInDeletedFiles() == 1);
@@ -1692,7 +1709,13 @@
 			"testfiles" DIRECTORY_SEPARATOR "clientTrustedCAs.pem");
 
 	// First, try logging in without an account having been created... just make sure login fails.
+
+#ifdef WIN32
+	int pid = LaunchServer("..\\..\\bin\\bbstored\\bbstored testfiles/bbstored.conf", "testfiles/bbstored.pid");
+#else
 	int pid = LaunchServer("../../bin/bbstored/bbstored testfiles/bbstored.conf", "testfiles/bbstored.pid");
+#endif
+
 	TEST_THAT(pid != -1 && pid != 0);
 	if(pid > 0)
 	{
@@ -1721,8 +1744,13 @@
 		}
 
 		// Create an account for the test client
+#ifdef WIN32
+		TEST_THAT_ABORTONFAIL(::system("..\\..\\bin\\bbstoreaccounts\\bbstoreaccounts -c testfiles/bbstored.conf create 01234567 0 10000B 20000B") == 0);
+#else
 		TEST_THAT_ABORTONFAIL(::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf create 01234567 0 10000B 20000B") == 0);
 		TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
+#endif
+
 		TEST_THAT(TestDirExists("testfiles/0_0/backup/01234567"));
 		TEST_THAT(TestDirExists("testfiles/0_1/backup/01234567"));
 		TEST_THAT(TestDirExists("testfiles/0_2/backup/01234567"));
@@ -1746,15 +1774,27 @@
 		TEST_THAT(KillServer(pid));
 		::sleep(1);
 		TEST_THAT(!ServerIsAlive(pid));
+#ifndef WIN32
 		TestRemoteProcessMemLeaks("bbstored.memleaks");
+#endif
 		
 		// Set a new limit on the account -- leave the hard limit high to make sure the target for
 		// freeing space is the soft limit.
+
+#ifdef WIN32
+		TEST_THAT_ABORTONFAIL(::system("..\\..\\bin\\bbstoreaccounts\\bbstoreaccounts -c testfiles/bbstored.conf setlimit 01234567 10B 20000B") == 0);
+#else
 		TEST_THAT_ABORTONFAIL(::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf setlimit 01234567 10B 20000B") == 0);
 		TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
+#endif
 
 		// Start things up
+#ifdef WIN32
+		pid = LaunchServer("..\\..\\bin\\bbstored\\bbstored testfiles/bbstored.conf", "testfiles/bbstored.pid");
+#else
 		pid = LaunchServer("../../bin/bbstored/bbstored testfiles/bbstored.conf", "testfiles/bbstored.pid");
+#endif
+
 		::sleep(1);
 		TEST_THAT(ServerIsAlive(pid));
 		
@@ -1779,8 +1819,12 @@
 		TEST_THAT(after.old == 0);
 		
 		// Set a really small hard limit
+#ifdef WIN32
+		TEST_THAT_ABORTONFAIL(::system("..\\..\\bin\\bbstoreaccounts\\bbstoreaccounts -c testfiles/bbstored.conf setlimit 01234567 10B 20B") == 0);
+#else
 		TEST_THAT_ABORTONFAIL(::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf setlimit 01234567 10B 20B") == 0);
 		TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
+#endif
 
 		// Try to upload a file and create a directory, and check an error is generated
 		{
@@ -1829,7 +1873,10 @@
 		TEST_THAT(KillServer(pid));
 		::sleep(1);
 		TEST_THAT(!ServerIsAlive(pid));
+
+#ifndef WIN32
 		TestRemoteProcessMemLeaks("bbstored.memleaks");
+#endif
 	}
 
 	return 0;
@@ -1841,10 +1888,19 @@
 
 	// Create an account for the test client
 	TEST_THAT_ABORTONFAIL(::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf create 01234567 0 30000B 40000B") == 0);
+
+#ifndef WIN32
 	TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
+#endif
 
 	// First, try logging in without an account having been created... just make sure login fails.
+
+#ifdef WIN32
+	int pid = LaunchServer("..\\..\\bin\\bbstored\\bbstored testfiles/bbstored_multi.conf", "testfiles/bbstored.pid");
+#else
 	int pid = LaunchServer("../../bin/bbstored/bbstored testfiles/bbstored_multi.conf", "testfiles/bbstored.pid");
+#endif
+
 	TEST_THAT(pid != -1 && pid != 0);
 	if(pid > 0)
 	{
@@ -1861,15 +1917,63 @@
 		TEST_THAT(KillServer(pid));
 		::sleep(1);
 		TEST_THAT(!ServerIsAlive(pid));
+#ifndef WIN32
 		TestRemoteProcessMemLeaks("bbstored.memleaks");
+#endif
 	}
 
 
 	return 0;
 }
 
+WCHAR* ConvertUtf8ToWideString(const char* pString);
+std::string ConvertPathToAbsoluteUnicode(const char *pFileName);
+
 int test(int argc, const char *argv[])
 {
+#ifdef WIN32
+	// Under win32 we must initialise the Winsock library
+	// before using sockets
+
+	WSADATA info;
+	TEST_THAT(WSAStartup(0x0101, &info) != SOCKET_ERROR)
+
+	// this had better work, or bbstored will die when combining diffs
+	char* file = "foo";
+	std::string abs = ConvertPathToAbsoluteUnicode(file);
+	WCHAR* wfile = ConvertUtf8ToWideString(abs.c_str());
+
+	DWORD accessRights = FILE_READ_ATTRIBUTES | 
+		FILE_LIST_DIRECTORY | FILE_READ_EA | FILE_WRITE_ATTRIBUTES |
+		FILE_WRITE_DATA | FILE_WRITE_EA /*| FILE_ALL_ACCESS*/;
+	DWORD shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
+
+	HANDLE h1 = CreateFileW(wfile, accessRights, shareMode,
+		NULL, OPEN_ALWAYS, FILE_FLAG_BACKUP_SEMANTICS, NULL);
+	assert(h1 != INVALID_HANDLE_VALUE);
+	TEST_THAT(h1 != INVALID_HANDLE_VALUE);
+
+	accessRights = FILE_READ_ATTRIBUTES | 
+		FILE_LIST_DIRECTORY | FILE_READ_EA;
+
+	HANDLE h2 = CreateFileW(wfile, accessRights, shareMode,
+		NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
+	assert(h2 != INVALID_HANDLE_VALUE);
+	TEST_THAT(h2 != INVALID_HANDLE_VALUE);
+
+	CloseHandle(h2);
+	CloseHandle(h1);
+
+	h1 = openfile("foo", O_CREAT | O_RDWR, 0);
+	assert(h1);
+	TEST_THAT(h1);
+	h2 = openfile("foo", O_RDWR, 0);
+	assert(h2);
+	TEST_THAT(h2);
+	CloseHandle(h2);
+	CloseHandle(h1);
+#endif
+
 	// SSL library
 	SSLLib::Initialise();
 	


From boxbackup-dev@fluffy.co.uk  Sat May 27 10:43:52 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 27 May 2006 09:43:52 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r586 - box/chris/general/infrastructure
Message-ID: <20060527094352.DA42596@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-27 09:43:43 +0000 (Sat, 27 May 2006)
New Revision: 586

Modified:
   box/chris/general/infrastructure/BoxPlatform.pm.in
   box/chris/general/infrastructure/makebuildenv.pl
Log:
* infrastructure/makebuildenv.pl
* infrastructure/BoxPlatform.pm.in
- Added a simple variable to check whether building under Win32


Modified: box/chris/general/infrastructure/BoxPlatform.pm.in
===================================================================
--- box/chris/general/infrastructure/BoxPlatform.pm.in	2006-05-27 09:42:31 UTC (rev 585)
+++ box/chris/general/infrastructure/BoxPlatform.pm.in	2006-05-27 09:43:43 UTC (rev 586)
@@ -1,7 +1,7 @@
 package BoxPlatform;
 use Exporter;
 @ISA = qw/Exporter/;
-@EXPORT = qw/$build_os $build_cpu $target_os $make_command $bsd_make $platform_define $platform_cpu $gcc_v3 $product_version $product_name $install_into_dir $sub_make_options $platform_compile_line_extra $platform_link_line_extra $platform_lib_files $platform_exe_ext/;
+@EXPORT = qw/$build_os $build_cpu $target_os $make_command $bsd_make $platform_define $platform_cpu $gcc_v3 $product_version $product_name $install_into_dir $sub_make_options $platform_compile_line_extra $platform_link_line_extra $platform_lib_files $platform_exe_ext $target_windows/;
 
 BEGIN
 {
@@ -27,6 +27,10 @@
 	$target_os = '@target_os@';
 	$platform_exe_ext = '@EXEEXT@';
 
+	$target_windows = 0;
+	$target_windows = 1 if $target_os =~ m'^mingw32' 
+		or $target_os eq "winnt";
+
 	# get version
 	open VERSION,"VERSION.txt" or die "VERSION.txt: $!";
 	$product_version = <VERSION>;

Modified: box/chris/general/infrastructure/makebuildenv.pl
===================================================================
--- box/chris/general/infrastructure/makebuildenv.pl	2006-05-27 09:42:31 UTC (rev 585)
+++ box/chris/general/infrastructure/makebuildenv.pl	2006-05-27 09:43:43 UTC (rev 586)
@@ -39,7 +39,7 @@
 my %env_flags;
 
 my $windows_include_path = "-I../../lib/win32 ";
-if ($target_os !~ m'^mingw32' && $target_os ne "winnt")
+if (not $target_windows)
 {
 	$windows_include_path = "";
 	$env_flags{'IGNORE_lib/win32'} = 1;
@@ -484,7 +484,7 @@
 	my $debug_link_extra = ($target_is_library)?'':'../../debug/lib/debug/debug.a';
 
 	my $release_flags = "-O2";
-	if ($target_os =~ m'^mingw32')
+	if ($target_windows)
 	{
 		$release_flags = "-O0 -g";
 	}
@@ -572,7 +572,7 @@
 		my $is_rc  = $file =~ m/\A(.+)\.rc\Z/i;
 		my $base = $1;
 
-		if ($target_os =~ m'^mingw32')
+		if ($target_windows)
 		{
 			next if not $is_cpp and not $is_rc;
 		}
@@ -683,7 +683,7 @@
 	print MAKE " ",$lib_files unless $target_is_library;
 	print MAKE "\n";
 	
-	if ($target_os =~ m'^mingw32')
+	if ($target_windows)
 	{
 		foreach my $dep (@all_deps_for_module)
 		{


From boxbackup-dev@fluffy.co.uk  Sat May 27 10:44:31 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 27 May 2006 09:44:31 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r587 - box/chris/general/lib/raidfile
Message-ID: <20060527094431.298E796@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-27 09:44:17 +0000 (Sat, 27 May 2006)
New Revision: 587

Modified:
   box/chris/general/lib/raidfile/RaidFileWrite.cpp
Log:
* RaidFileWrite.cpp
- Unlink files before renaming over them on Win32


Modified: box/chris/general/lib/raidfile/RaidFileWrite.cpp
===================================================================
--- box/chris/general/lib/raidfile/RaidFileWrite.cpp	2006-05-27 09:43:43 UTC (rev 586)
+++ box/chris/general/lib/raidfile/RaidFileWrite.cpp	2006-05-27 09:44:17 UTC (rev 587)
@@ -564,6 +564,13 @@
 		parity.Close();
 		stripe2.Close();
 		stripe1.Close();
+
+#ifdef WIN32
+		// Must delete before renaming
+		::unlink(stripe1Filename.c_str());
+		::unlink(stripe2Filename.c_str());
+		::unlink(parityFilename.c_str());
+#endif
 		
 		// Rename them into place
 		if(::rename(stripe1FilenameW.c_str(), stripe1Filename.c_str()) != 0


From boxbackup-dev@fluffy.co.uk  Sat May 27 10:45:17 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 27 May 2006 09:45:17 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r588 - box/chris/general/lib/backupstore
Message-ID: <20060527094517.1A89B96@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-27 09:44:56 +0000 (Sat, 27 May 2006)
New Revision: 588

Modified:
   box/chris/general/lib/backupstore/BackupStoreAccounts.cpp
Log:
* BackupStoreAccounts.cpp
- Use directory separator in account root dir


Modified: box/chris/general/lib/backupstore/BackupStoreAccounts.cpp
===================================================================
--- box/chris/general/lib/backupstore/BackupStoreAccounts.cpp	2006-05-27 09:44:17 UTC (rev 587)
+++ box/chris/general/lib/backupstore/BackupStoreAccounts.cpp	2006-05-27 09:44:56 UTC (rev 588)
@@ -141,8 +141,9 @@
 std::string BackupStoreAccounts::MakeAccountRootDir(int32_t ID, int DiscSet) const
 {
 	char accid[64];	// big enough!
-	::sprintf(accid, "%08x/", ID);
-	return std::string(std::string(BOX_RAIDFILE_ROOT_BBSTORED DIRECTORY_SEPARATOR) + accid);
+	::sprintf(accid, "%08x" DIRECTORY_SEPARATOR, ID);
+	return std::string(std::string(BOX_RAIDFILE_ROOT_BBSTORED 
+		DIRECTORY_SEPARATOR) + accid);
 }
 
 


From boxbackup-dev@fluffy.co.uk  Sat May 27 10:48:22 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 27 May 2006 09:48:22 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r589 - box/chris/general/lib/win32
Message-ID: <20060527094822.A565B96@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-27 09:48:12 +0000 (Sat, 27 May 2006)
New Revision: 589

Modified:
   box/chris/general/lib/win32/emu.cpp
Log:
* emu.cpp
- Simplified code by using ConvertUtf8ToWideString where possible
- Automatically convert paths from Unix to Windows format (/ to \)
- openfile with O_CREAT doesn't request FILE_ALL_ACCESS, prevents sharing
- Check whether syslog handle is NULL before printing to it, to avoid
  segfault
- Support Unicode in emu_chdir, emu_mkdir, emu_unlink


Modified: box/chris/general/lib/win32/emu.cpp
===================================================================
--- box/chris/general/lib/win32/emu.cpp	2006-05-27 09:44:56 UTC (rev 588)
+++ box/chris/general/lib/win32/emu.cpp	2006-05-27 09:48:12 UTC (rev 589)
@@ -371,7 +371,7 @@
 // --------------------------------------------------------------------------
 bool ConvertUtf8ToConsole(const char* pString, std::string& rDest)
 {
-	WCHAR* pWide = ConvertToWideString(pString, CP_UTF8);
+	WCHAR* pWide = ConvertUtf8ToWideString(pString);
 	if (pWide == NULL)
 	{
 		return false;
@@ -435,13 +435,26 @@
 // --------------------------------------------------------------------------
 std::string ConvertPathToAbsoluteUnicode(const char *pFileName)
 {
+	std::string filename;
+	for (int i = 0; pFileName[i] != 0; i++)
+	{
+		if (pFileName[i] == '/')
+		{
+			filename += '\\';
+		}
+		else
+		{
+			filename += pFileName[i];
+		}
+	}
+
 	std::string tmpStr("\\\\?\\");
 	
 	// Is the path relative or absolute?
 	// Absolute paths on Windows are always a drive letter
 	// followed by ':'
 	
-	if (pFileName[1] != ':')
+	if (filename[1] != ':')
 	{
 		// Must be relative. We need to get the 
 		// current directory to make it absolute.
@@ -464,7 +477,7 @@
 		}
 	}
 	
-	tmpStr += pFileName;
+	tmpStr += filename;
 	return tmpStr;
 }
 
@@ -478,7 +491,8 @@
 // --------------------------------------------------------------------------
 HANDLE openfile(const char *pFileName, int flags, int mode)
 {
-	std::string AbsPathWithUnicode = ConvertPathToAbsoluteUnicode(pFileName);
+	std::string AbsPathWithUnicode = 
+		ConvertPathToAbsoluteUnicode(pFileName);
 	
 	if (AbsPathWithUnicode.size() == 0)
 	{
@@ -514,7 +528,7 @@
 		shareMode |= FILE_SHARE_WRITE;
 		accessRights |= FILE_WRITE_ATTRIBUTES 
 			| FILE_WRITE_DATA | FILE_WRITE_EA 
-			| FILE_ALL_ACCESS;
+			/*| FILE_ALL_ACCESS */;
 	}
 	if (flags & O_TRUNC)
 	{
@@ -658,7 +672,8 @@
 // --------------------------------------------------------------------------
 HANDLE OpenFileByNameUtf8(const char* pFileName)
 {
-	std::string AbsPathWithUnicode = ConvertPathToAbsoluteUnicode(pFileName);
+	std::string AbsPathWithUnicode = 
+		ConvertPathToAbsoluteUnicode(pFileName);
 	
 	if (AbsPathWithUnicode.size() == 0)
 	{
@@ -1219,6 +1234,12 @@
 
 	LPCSTR strings[] = { buffer, NULL };
 
+	if (gSyslogH == 0)
+	{
+		printf("%s\r\n", buffer);
+		return;
+	}
+
 	if (!ReportEvent(gSyslogH, // event log handle 
 		errinfo,               // event type 
 		0,                     // category zero 
@@ -1257,7 +1278,16 @@
 
 int emu_chdir(const char* pDirName)
 {
-	WCHAR* pBuffer = ConvertUtf8ToWideString(pDirName);
+	std::string AbsPathWithUnicode = 
+		ConvertPathToAbsoluteUnicode(pDirName);
+
+	if (AbsPathWithUnicode.size() == 0)
+	{
+		// error already logged by ConvertPathToAbsoluteUnicode()
+		return -1;
+	}
+
+	WCHAR* pBuffer = ConvertUtf8ToWideString(AbsPathWithUnicode.c_str());
 	if (!pBuffer) return -1;
 	int result = SetCurrentDirectoryW(pBuffer);
 	delete [] pBuffer;
@@ -1312,7 +1342,16 @@
 
 int emu_mkdir(const char* pPathName)
 {
-	WCHAR* pBuffer = ConvertToWideString(pPathName, CP_UTF8);
+	std::string AbsPathWithUnicode = 
+		ConvertPathToAbsoluteUnicode(pPathName);
+
+	if (AbsPathWithUnicode.size() == 0)
+	{
+		// error already logged by ConvertPathToAbsoluteUnicode()
+		return -1;
+	}
+
+	WCHAR* pBuffer = ConvertUtf8ToWideString(AbsPathWithUnicode.c_str());
 	if (!pBuffer)
 	{
 		return -1;
@@ -1332,7 +1371,16 @@
 
 int emu_unlink(const char* pFileName)
 {
-	WCHAR* pBuffer = ConvertToWideString(pFileName, CP_UTF8);
+	std::string AbsPathWithUnicode = 
+		ConvertPathToAbsoluteUnicode(pFileName);
+
+	if (AbsPathWithUnicode.size() == 0)
+	{
+		// error already logged by ConvertPathToAbsoluteUnicode()
+		return -1;
+	}
+
+	WCHAR* pBuffer = ConvertUtf8ToWideString(AbsPathWithUnicode.c_str());
 	if (!pBuffer)
 	{
 		return -1;


From boxbackup-dev@fluffy.co.uk  Sat May 27 10:49:50 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 27 May 2006 09:49:50 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r590 - box/chris/general/lib/server
Message-ID: <20060527094950.BB99A96@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-27 09:49:39 +0000 (Sat, 27 May 2006)
New Revision: 590

Modified:
   box/chris/general/lib/server/SocketStream.cpp
   box/chris/general/lib/server/SocketStream.h
Log:
* SocketStream.cpp, SocketStream.h
- Use INVALID_SOCKET_HANDLE instead of static member mInvalidHandle


Modified: box/chris/general/lib/server/SocketStream.cpp
===================================================================
--- box/chris/general/lib/server/SocketStream.cpp	2006-05-27 09:48:12 UTC (rev 589)
+++ box/chris/general/lib/server/SocketStream.cpp	2006-05-27 09:49:39 UTC (rev 590)
@@ -36,7 +36,7 @@
 //
 // --------------------------------------------------------------------------
 SocketStream::SocketStream()
-	: mSocketHandle(mInvalidHandle),
+	: mSocketHandle(INVALID_SOCKET_VALUE),
 	  mReadClosed(false),
 	  mWriteClosed(false),
 	  mBytesRead(0),
@@ -85,7 +85,7 @@
 	{
 		THROW_EXCEPTION(ServerException, BadSocketHandle);
 	}
-	if(mSocketHandle == mInvalidHandle)
+	if(mSocketHandle == INVALID_SOCKET_VALUE)
 	{
 		THROW_EXCEPTION(ServerException, DupError);
 	}
@@ -101,7 +101,7 @@
 // --------------------------------------------------------------------------
 SocketStream::~SocketStream()
 {
-	if(mSocketHandle != mInvalidHandle)
+	if(mSocketHandle != INVALID_SOCKET_VALUE)
 	{
 		Close();
 	}
@@ -117,7 +117,7 @@
 // --------------------------------------------------------------------------
 void SocketStream::Attach(int socket)
 {
-	if(mSocketHandle != mInvalidHandle) 
+	if(mSocketHandle != INVALID_SOCKET_VALUE) 
 	{
 		THROW_EXCEPTION(ServerException, SocketAlreadyOpen)
 	}
@@ -137,7 +137,7 @@
 // --------------------------------------------------------------------------
 void SocketStream::Open(int Type, const char *Name, int Port)
 {
-	if(mSocketHandle != mInvalidHandle) 
+	if(mSocketHandle != INVALID_SOCKET_VALUE) 
 	{
 		THROW_EXCEPTION(ServerException, SocketAlreadyOpen)
 	}
@@ -150,7 +150,7 @@
 
 	// Create the socket
 	mSocketHandle = ::socket(sockDomain, SOCK_STREAM, 0 /* let OS choose protocol */);
-	if(mSocketHandle == mInvalidHandle)
+	if(mSocketHandle == INVALID_SOCKET_VALUE)
 	{
 		THROW_EXCEPTION(ServerException, SocketOpenError)
 	}
@@ -164,7 +164,7 @@
 #else
 		::close(mSocketHandle);
 #endif
-		mSocketHandle = mInvalidHandle;
+		mSocketHandle = INVALID_SOCKET_VALUE;
 		THROW_EXCEPTION(ConnectionException, Conn_SocketConnectError)
 	}
 	ResetCounters();
@@ -180,7 +180,7 @@
 // --------------------------------------------------------------------------
 int SocketStream::Read(void *pBuffer, int NBytes, int Timeout)
 {
-	if(mSocketHandle == mInvalidHandle) 
+	if(mSocketHandle == INVALID_SOCKET_VALUE) 
 	{
 		THROW_EXCEPTION(ServerException, BadSocketHandle)
 	}
@@ -256,7 +256,7 @@
 // --------------------------------------------------------------------------
 void SocketStream::Write(const void *pBuffer, int NBytes)
 {
-	if(mSocketHandle == mInvalidHandle) 
+	if(mSocketHandle == INVALID_SOCKET_VALUE) 
 	{
 		THROW_EXCEPTION(ServerException, BadSocketHandle)
 	}
@@ -323,7 +323,7 @@
 // --------------------------------------------------------------------------
 void SocketStream::Close()
 {
-	if(mSocketHandle == mInvalidHandle) 
+	if(mSocketHandle == INVALID_SOCKET_VALUE) 
 	{
 		THROW_EXCEPTION(ServerException, BadSocketHandle)
 	}
@@ -335,7 +335,7 @@
 	{
 		THROW_EXCEPTION(ServerException, SocketCloseError)
 	}
-	mSocketHandle = -1;
+	mSocketHandle = INVALID_SOCKET_VALUE;
 }
 
 // --------------------------------------------------------------------------
@@ -348,7 +348,7 @@
 // --------------------------------------------------------------------------
 void SocketStream::Shutdown(bool Read, bool Write)
 {
-	if(mSocketHandle == mInvalidHandle) 
+	if(mSocketHandle == INVALID_SOCKET_VALUE) 
 	{
 		THROW_EXCEPTION(ServerException, BadSocketHandle)
 	}
@@ -406,7 +406,7 @@
 // --------------------------------------------------------------------------
 tOSSocketHandle SocketStream::GetSocketHandle()
 {
-	if(mSocketHandle == mInvalidHandle) 
+	if(mSocketHandle == INVALID_SOCKET_VALUE) 
 	{
 		THROW_EXCEPTION(ServerException, BadSocketHandle)
 	}

Modified: box/chris/general/lib/server/SocketStream.h
===================================================================
--- box/chris/general/lib/server/SocketStream.h	2006-05-27 09:48:12 UTC (rev 589)
+++ box/chris/general/lib/server/SocketStream.h	2006-05-27 09:49:39 UTC (rev 590)
@@ -14,8 +14,10 @@
 
 #ifdef WIN32
 	typedef SOCKET tOSSocketHandle;
+	#define INVALID_SOCKET_VALUE (tOSSocketHandle)(-1)
 #else
 	typedef int tOSSocketHandle;
+	#define INVALID_SOCKET_VALUE -1
 #endif
 
 // --------------------------------------------------------------------------
@@ -56,7 +58,6 @@
 	tOSSocketHandle mSocketHandle;
 	bool mReadClosed;
 	bool mWriteClosed;
-	static const tOSSocketHandle mInvalidHandle = -1;
 
 protected:
 	off_t mBytesRead;


From boxbackup-dev@fluffy.co.uk  Sat May 27 10:51:23 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 27 May 2006 09:51:23 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r591 - box/chris/general/lib/server
Message-ID: <20060527095123.715DC96@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-27 09:51:13 +0000 (Sat, 27 May 2006)
New Revision: 591

Modified:
   box/chris/general/lib/server/ServerStream.h
Log:
* ServerStream.h
- Added an OnIdle() method on Win32, called when listen for new 
  connections times out, used to call housekeeping process in bbstored
  on Win32


Modified: box/chris/general/lib/server/ServerStream.h
===================================================================
--- box/chris/general/lib/server/ServerStream.h	2006-05-27 09:49:39 UTC (rev 590)
+++ box/chris/general/lib/server/ServerStream.h	2006-05-27 09:51:13 UTC (rev 591)
@@ -56,6 +56,8 @@
 		return "generic-stream-server";
 	}
 
+	virtual void OnIdle() { }
+
 	virtual void Run()
 	{
 		// Set process title as appropraite
@@ -267,7 +269,9 @@
 					}
 				}
 
-#ifndef WIN32				
+#ifdef WIN32
+				OnIdle();
+#else // !WIN32
 				// Clean up child processes (if forking daemon)
 				if(ForkToHandleRequests)
 				{


From boxbackup-dev@fluffy.co.uk  Sat May 27 10:52:07 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 27 May 2006 09:52:07 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r592 - box/chris/general/lib/server
Message-ID: <20060527095207.70D8696@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-27 09:51:58 +0000 (Sat, 27 May 2006)
New Revision: 592

Modified:
   box/chris/general/lib/server/makeprotocol.pl
Log:
* makeprotocol.pl
- Fixed format on Win32 (causes segfaults)


Modified: box/chris/general/lib/server/makeprotocol.pl
===================================================================
--- box/chris/general/lib/server/makeprotocol.pl	2006-05-27 09:51:13 UTC (rev 591)
+++ box/chris/general/lib/server/makeprotocol.pl	2006-05-27 09:51:58 UTC (rev 592)
@@ -1,6 +1,9 @@
 #!/usr/bin/perl
 use strict;
 
+use lib "../../infrastructure";
+use BoxPlatform;
+
 # Make protocol C++ classes from a protocol description file
 
 # built in type info (values are is basic type, C++ typename)
@@ -981,8 +984,15 @@
 		{
 			# need to translate it
 			my ($format,$arg) = @{$log_display_types{$ty}};
+			$arg =~ s/VAR/m$nm/g;
+
+			if ($format eq "0x%llx" and $target_windows)
+			{
+				$format = "0x%I64x";
+				$arg = "(uint64_t)$arg";
+			}
+
 			push @str,$format;
-			$arg =~ s/VAR/m$nm/g;
 			push @arg,$arg;
 		}
 		else


From boxbackup-dev@fluffy.co.uk  Sat May 27 10:52:43 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 27 May 2006 09:52:43 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r593 - box/chris/general/lib/common
Message-ID: <20060527095243.9248796@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-27 09:52:32 +0000 (Sat, 27 May 2006)
New Revision: 593

Modified:
   box/chris/general/lib/common/Test.h
Log:
* Test.h
- Record the file and line where first failure occurred, helps with
  debugging


Modified: box/chris/general/lib/common/Test.h
===================================================================
--- box/chris/general/lib/common/Test.h	2006-05-27 09:51:58 UTC (rev 592)
+++ box/chris/general/lib/common/Test.h	2006-05-27 09:52:32 UTC (rev 593)
@@ -22,14 +22,26 @@
 #include <stdio.h>
  
 extern int failures;
+extern int first_fail_line;
+extern std::string first_fail_file;
 
-#define TEST_FAIL_WITH_MESSAGE(msg) {failures++; printf("FAILURE: " msg " at " __FILE__ "(%d)\n", __LINE__);}
-#define TEST_ABORT_WITH_MESSAGE(msg) {failures++; printf("FAILURE: " msg " at " __FILE__ "(%d)\n", __LINE__); return 1;}
+#define TEST_FAIL_WITH_MESSAGE(msg) \
+{ \
+	if (failures == 0) \
+	{ \
+		first_fail_file = __FILE__; \
+		first_fail_line = __LINE__; \
+	} \
+	failures++; \
+	printf("FAILURE: " msg " at " __FILE__ "(%d)\n", __LINE__); \
+}
 
+#define TEST_ABORT_WITH_MESSAGE(msg) {TEST_FAIL_WITH_MESSAGE(msg); return 1;}
+
 #define TEST_THAT(condition) {if(!(condition)) TEST_FAIL_WITH_MESSAGE("Condition [" #condition "] failed")}
 #define TEST_THAT_ABORTONFAIL(condition) {if(!(condition)) TEST_ABORT_WITH_MESSAGE("Condition [" #condition "] failed")}
 
-// NOTE: The 0- bit it to allow this to work with stuff which has negative constants for flags (eg ConnectionException)
+// NOTE: The 0- bit is to allow this to work with stuff which has negative constants for flags (eg ConnectionException)
 #define TEST_CHECK_THROWS(statement, excepttype, subtype)									\
 	{																						\
 		bool didthrow = false;																\


From boxbackup-dev@fluffy.co.uk  Sat May 27 10:52:59 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 27 May 2006 09:52:59 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r594 - box/chris/general/bin/bbstored
Message-ID: <20060527095259.AFFF296@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-27 09:52:52 +0000 (Sat, 27 May 2006)
New Revision: 594

Modified:
   box/chris/general/bin/bbstored/HousekeepStoreAccount.cpp
Log:
* HousekeepStoreAccount.cpp
- Skip interprocess messaging on Win32, there is only one process


Modified: box/chris/general/bin/bbstored/HousekeepStoreAccount.cpp
===================================================================
--- box/chris/general/bin/bbstored/HousekeepStoreAccount.cpp	2006-05-27 09:52:32 UTC (rev 593)
+++ box/chris/general/bin/bbstored/HousekeepStoreAccount.cpp	2006-05-27 09:52:52 UTC (rev 594)
@@ -225,6 +225,7 @@
 // --------------------------------------------------------------------------
 bool HousekeepStoreAccount::ScanDirectory(int64_t ObjectID)
 {
+#ifndef WIN32
 	if((--mCountUntilNextInterprocessMsgCheck) <= 0)
 	{
 		mCountUntilNextInterprocessMsgCheck = POLL_INTERPROCESS_MSG_CHECK_FREQUENCY;
@@ -235,6 +236,7 @@
 			return false;
 		}
 	}
+#endif
 
 	// Get the filename
 	std::string objectFilename;
@@ -485,6 +487,7 @@
 	// (there is likely to be more in the set than should be actually deleted).
 	for(std::set<DelEn, DelEnCompare>::iterator i(mPotentialDeletions.begin()); i != mPotentialDeletions.end(); ++i)
 	{
+#ifndef WIN32
 		if((--mCountUntilNextInterprocessMsgCheck) <= 0)
 		{
 			mCountUntilNextInterprocessMsgCheck = POLL_INTERPROCESS_MSG_CHECK_FREQUENCY;
@@ -495,6 +498,7 @@
 				return true;
 			}
 		}
+#endif
 
 		// Load up the directory it's in
 		// Get the filename
@@ -729,6 +733,7 @@
 		// Go through list
 		for(std::vector<int64_t>::const_iterator i(mEmptyDirectories.begin()); i != mEmptyDirectories.end(); ++i)
 		{
+#ifndef WIN32
 			if((--mCountUntilNextInterprocessMsgCheck) <= 0)
 			{
 				mCountUntilNextInterprocessMsgCheck = POLL_INTERPROCESS_MSG_CHECK_FREQUENCY;
@@ -739,6 +744,7 @@
 					return true;
 				}
 			}
+#endif
 
 			// Do not delete the root directory
 			if(*i == BACKUPSTORE_ROOT_DIRECTORY_ID)


From boxbackup-dev@fluffy.co.uk  Sat May 27 10:54:45 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 27 May 2006 09:54:45 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r595 - box/chris/general/bin/bbstored
Message-ID: <20060527095445.492AB96@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-27 09:54:37 +0000 (Sat, 27 May 2006)
New Revision: 595

Modified:
   box/chris/general/bin/bbstored/BackupStoreDaemon.cpp
Log:
* BackupStoreDaemon.cpp
- Disable interprocess comms on Win32
- Fixed formatting of connection statistics on Win32


Modified: box/chris/general/bin/bbstored/BackupStoreDaemon.cpp
===================================================================
--- box/chris/general/bin/bbstored/BackupStoreDaemon.cpp	2006-05-27 09:52:52 UTC (rev 594)
+++ box/chris/general/bin/bbstored/BackupStoreDaemon.cpp	2006-05-27 09:54:37 UTC (rev 595)
@@ -42,7 +42,10 @@
 	  mExtendedLogging(false),
 	  mHaveForkedHousekeeping(false),
 	  mIsHousekeepingProcess(false),
-	  mInterProcessComms(mInterProcessCommsSocket)
+#ifndef WIN32
+	  mInterProcessComms(mInterProcessCommsSocket),
+#endif
+	  mHousekeepingInited(false)
 {
 }
 
@@ -215,7 +218,6 @@
 			THROW_EXCEPTION(ServerException, SocketCloseError)
 		}
 	}
-#endif // !WIN32
 
 	if(mIsHousekeepingProcess)
 	{
@@ -224,9 +226,11 @@
 	}
 	else
 	{
+#endif // !WIN32
 		// In server process -- use the base class to do the magic
 		ServerTLS<BOX_PORT_BBSTORED>::Run();
-		
+	
+#ifndef WIN32	
 		// Why did it stop? Tell the housekeeping process to do the same
 		if(IsReloadConfigWanted())
 		{
@@ -237,6 +241,7 @@
 			mInterProcessCommsSocket.Write("t\n", 2);
 		}
 	}
+#endif
 }
 
 
@@ -302,6 +307,8 @@
 	// Log the amount of data transferred
 	::syslog(LOG_INFO, "Connection statistics for %s: "
 			"IN=%lld OUT=%lld TOTAL=%lld\n", commonName,
-			s.GetBytesRead(), s.GetBytesWritten(),
-			s.GetBytesRead() + s.GetBytesWritten());
+			(long long)s.GetBytesRead(), 
+			(long long)s.GetBytesWritten(),
+			(long long)s.GetBytesRead() + 
+			(long long)s.GetBytesWritten());
 }


From boxbackup-dev@fluffy.co.uk  Sat May 27 10:57:01 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 27 May 2006 09:57:01 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r596 - box/chris/general/bin/bbstored
Message-ID: <20060527095701.B5C9896@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-27 09:56:46 +0000 (Sat, 27 May 2006)
New Revision: 596

Modified:
   box/chris/general/bin/bbstored/BackupContext.cpp
Log:
* BackupContext.cpp
- Disabled interprocess comms on Win32
- Don't try to open a read-only second handle on Win32, this would fail
  because openfile() only allows other readers, not writers (maybe fix
  openfile() instead?)
- Don't unlink file while it's still open, but just after closing it


Modified: box/chris/general/bin/bbstored/BackupContext.cpp
===================================================================
--- box/chris/general/bin/bbstored/BackupContext.cpp	2006-05-27 09:54:37 UTC (rev 595)
+++ box/chris/general/bin/bbstored/BackupContext.cpp	2006-05-27 09:56:46 UTC (rev 596)
@@ -132,6 +132,7 @@
 	// Request the lock
 	bool gotLock = mWriteLock.TryAndGetLock(writeLockFile.c_str(), 0600 /* restrictive file permissions */);
 	
+#ifndef WIN32
 	if(!gotLock)
 	{
 		// The housekeeping process might have the thing open -- ask it to stop
@@ -150,6 +151,7 @@
 			
 		} while(!gotLock && tries > 0);
 	}
+#endif
 	
 	if(gotLock)
 	{
@@ -453,13 +455,19 @@
 			try
 			{
 				// Open it twice
+#ifdef WIN32
+				FileStream diff(tempFn.c_str(), O_RDWR | O_CREAT);
+				FileStream diff2(tempFn.c_str(), O_RDWR);
+#else
 				FileStream diff(tempFn.c_str(), O_RDWR | O_CREAT | O_EXCL);
 				FileStream diff2(tempFn.c_str(), O_RDONLY);
+
 				// Unlink it immediately, so it definately goes away
 				if(::unlink(tempFn.c_str()) != 0)
 				{
 					THROW_EXCEPTION(CommonException, OSFileError);
 				}
+#endif
 				
 				// Stream the incoming diff to this temporary file
 				if(!rFile.CopyStreamTo(diff, BACKUP_STORE_TIMEOUT))
@@ -508,8 +516,16 @@
 				::unlink(tempFn.c_str());
 				throw;
 			}
+
+#ifdef WIN32
+			// we can't delete the file while it's open, above
+			if(::unlink(tempFn.c_str()) != 0)
+			{
+				THROW_EXCEPTION(CommonException, OSFileError);
+			}
+#endif
 		}
-		
+
 		// Get the blocks used
 		blocksUsed = storeFile.GetDiscUsageInBlocks();
 		


From boxbackup-dev@fluffy.co.uk  Sat May 27 10:59:16 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 27 May 2006 09:59:16 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r597 - box/chris/general/bin/bbstored
Message-ID: <20060527095916.A520F96@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-27 09:58:43 +0000 (Sat, 27 May 2006)
New Revision: 597

Modified:
   box/chris/general/bin/bbstored/BBStoreDHousekeeping.cpp
Log:
* BBStoreDHousekeeping.cpp
- Broke up housekeeping code so that we can call it synchronously on Win32
- Run housekeeping in OnIdle() on Win32
- Disabled inter-process messaging on Win32


Modified: box/chris/general/bin/bbstored/BBStoreDHousekeeping.cpp
===================================================================
--- box/chris/general/bin/bbstored/BBStoreDHousekeeping.cpp	2006-05-27 09:56:46 UTC (rev 596)
+++ box/chris/general/bin/bbstored/BBStoreDHousekeeping.cpp	2006-05-27 09:58:43 UTC (rev 597)
@@ -32,96 +32,129 @@
 //		Created: 11/12/03
 //
 // --------------------------------------------------------------------------
+void BackupStoreDaemon::HousekeepingInit()
+{
+
+	mLastHousekeepingRun = 0;
+}
+
+#ifndef WIN32
 void BackupStoreDaemon::HousekeepingProcess()
 {
+	HousekeepingInit();
+
 	// Get the time between housekeeping runs
 	const Configuration &rconfig(GetConfiguration());
 	int64_t housekeepingInterval = SecondsToBoxTime(rconfig.GetKeyValueInt("TimeBetweenHousekeeping"));
-	
-	int64_t lastHousekeepingRun = 0;
 
 	while(!StopRun())
 	{
-		// Time now
+		RunHousekeepingIfNeeded();
+
+		// Calculate how long should wait before doing the next housekeeping run
 		int64_t timeNow = GetCurrentBoxTime();
-		// Do housekeeping if the time interval has elapsed since the last check
-		if((timeNow - lastHousekeepingRun) >= housekeepingInterval)
-		{
-			// Store the time
-			lastHousekeepingRun = timeNow;
-			::syslog(LOG_INFO, "Starting housekeeping");
+		time_t secondsToGo = BoxTimeToSeconds((mLastHousekeepingRun + housekeepingInterval) - timeNow);
+		if(secondsToGo < 1) secondsToGo = 1;
+		if(secondsToGo > 60) secondsToGo = 60;
+		int32_t millisecondsToGo = ((int)secondsToGo) * 1000;
+	
+		// Check to see if there's any message pending
+		CheckForInterProcessMsg(0 /* no account */, millisecondsToGo);
+	}
+}
+#endif
 
-			// Get the list of accounts
-			std::vector<int32_t> accounts;
-			if(mpAccountDatabase)
-			{
-				mpAccountDatabase->GetAllAccountIDs(accounts);
-			}
+void BackupStoreDaemon::RunHousekeepingIfNeeded()
+{
+	// Get the time between housekeeping runs
+	const Configuration &rconfig(GetConfiguration());
+	int64_t housekeepingInterval = SecondsToBoxTime(rconfig.GetKeyValueInt("TimeBetweenHousekeeping"));
+
+	// Time now
+	int64_t timeNow = GetCurrentBoxTime();
+	// Do housekeeping if the time interval has elapsed since the last check
+	if((timeNow - mLastHousekeepingRun) < housekeepingInterval)
+	{
+		return;
+	}
+
+	// Store the time
+	mLastHousekeepingRun = timeNow;
+	::syslog(LOG_INFO, "Starting housekeeping");
+
+	// Get the list of accounts
+	std::vector<int32_t> accounts;
+	if(mpAccountDatabase)
+	{
+		mpAccountDatabase->GetAllAccountIDs(accounts);
+	}
 			
-			SetProcessTitle("housekeeping, active");
+	SetProcessTitle("housekeeping, active");
 			
-			// Check them all
-			for(std::vector<int32_t>::const_iterator i = accounts.begin(); i != accounts.end(); ++i)
+	// Check them all
+	for(std::vector<int32_t>::const_iterator i = accounts.begin(); i != accounts.end(); ++i)
+	{
+		try
+		{
+			if(mpAccounts)
 			{
-				try
-				{
-					if(mpAccounts)
-					{
-						// Get the account root
-						std::string rootDir;
-						int discSet = 0;
-						mpAccounts->GetAccountRoot(*i, rootDir, discSet);
-						
-						// Do housekeeping on this account
-						HousekeepStoreAccount housekeeping(*i, rootDir, discSet, *this);
-						housekeeping.DoHousekeeping();
-					}
-				}
-				catch(BoxException &e)
-				{
-					::syslog(LOG_ERR, "while housekeeping account %08X, exception %s (%d/%d) -- aborting housekeeping run for this account",
-						*i, e.what(), e.GetType(), e.GetSubType());
-				}
-				catch(std::exception &e)
-				{
-					::syslog(LOG_ERR, "while housekeeping account %08X, exception %s -- aborting housekeeping run for this account",
-						*i, e.what());
-				}
-				catch(...)
-				{
-					::syslog(LOG_ERR, "while housekeeping account %08X, unknown exception -- aborting housekeeping run for this account",
-						*i);
-				}
+				// Get the account root
+				std::string rootDir;
+				int discSet = 0;
+				mpAccounts->GetAccountRoot(*i, rootDir, discSet);
 				
-				// Check to see if there's any message pending
-				CheckForInterProcessMsg(0 /* no account */);
-		
-				// Stop early?
-				if(StopRun())
-				{
-					break;
-				}
+				// Do housekeeping on this account
+				HousekeepStoreAccount housekeeping(*i, rootDir, discSet, *this);
+				housekeeping.DoHousekeeping();
 			}
-			
-			::syslog(LOG_INFO, "Finished housekeeping");
 		}
-
-		// Placed here for accuracy, if StopRun() is true, for example.
-		SetProcessTitle("housekeeping, idle");
-		
-		// Calculate how long should wait before doing the next housekeeping run
-		timeNow = GetCurrentBoxTime();
-		time_t secondsToGo = BoxTimeToSeconds((lastHousekeepingRun + housekeepingInterval) - timeNow);
-		if(secondsToGo < 1) secondsToGo = 1;
-		if(secondsToGo > 60) secondsToGo = 60;
-		int32_t millisecondsToGo = ((int)secondsToGo) * 1000;
+		catch(BoxException &e)
+		{
+			::syslog(LOG_ERR, "while housekeeping account %08X, exception %s (%d/%d) -- aborting housekeeping run for this account",
+				*i, e.what(), e.GetType(), e.GetSubType());
+		}
+		catch(std::exception &e)
+		{
+			::syslog(LOG_ERR, "while housekeeping account %08X, exception %s -- aborting housekeeping run for this account",
+				*i, e.what());
+		}
+		catch(...)
+		{
+			::syslog(LOG_ERR, "while housekeeping account %08X, unknown exception -- aborting housekeeping run for this account",
+				*i);
+		}
 	
+#ifndef WIN32	
 		// Check to see if there's any message pending
-		CheckForInterProcessMsg(0 /* no account */, millisecondsToGo);
+		CheckForInterProcessMsg(0 /* no account */);
+#endif
+
+		// Stop early?
+		if(StopRun())
+		{
+			break;
+		}
 	}
+		
+	::syslog(LOG_INFO, "Finished housekeeping");
+
+	// Placed here for accuracy, if StopRun() is true, for example.
+	SetProcessTitle("housekeeping, idle");
 }
 
+#ifdef WIN32
+void BackupStoreDaemon::OnIdle()
+{
+	if (!mHousekeepingInited)
+	{
+		HousekeepingInit();
+		mHousekeepingInited = true;
+	}
 
+	RunHousekeepingIfNeeded();
+}
+#endif
+
 // --------------------------------------------------------------------------
 //
 // Function
@@ -131,6 +164,7 @@
 //		Created: 11/12/03
 //
 // --------------------------------------------------------------------------
+#ifndef WIN32
 bool BackupStoreDaemon::CheckForInterProcessMsg(int AccountNum, int MaximumWaitTime)
 {
 	// First, check to see if it's EOF -- this means something has gone wrong, and the housekeeping should terminate.
@@ -174,5 +208,6 @@
 	
 	return false;
 }
+#endif
 
 


From boxbackup-dev@fluffy.co.uk  Sat May 27 22:11:47 2006
From: boxbackup-dev@fluffy.co.uk (Dave Bamford)
Date: Sat, 27 May 2006 22:11:47 +0100
Subject: [Box Backup-dev] bbackupquery command line interface
Message-ID: <4478C093.4000506@logical-progress.com>

I am thinking of writing a PHP interface to bbackupquery so it can be 
used from
a web browser. I have got simple queries to work by submitting the command
in the following syntax

echo exec('bbackupquery "list -t MyDocuments" exit');

but to burrow down the tree its fine until I hit a directory name with a 
space ie

echo exec('bbackupquery "list -t MyDocuments/dave/My Documents" exit');

The list command is truncated at the space and no combination of single or
double quotes seem to work.

The command can also be done from the command prompt with the same results.


Dave Bamford.



From boxbackup-dev@fluffy.co.uk  Sat May 27 22:51:41 2006
From: boxbackup-dev@fluffy.co.uk (Dave Bamford)
Date: Sat, 27 May 2006 22:51:41 +0100
Subject: [Box Backup-dev] bbackupquery command line interface
In-Reply-To: <4478C093.4000506@logical-progress.com>
References: <4478C093.4000506@logical-progress.com>
Message-ID: <4478C9ED.3030804@logical-progress.com>

Dave Bamford wrote:

> I am thinking of writing a PHP interface to bbackupquery so it can be 
> used from
> a web browser. I have got simple queries to work by submitting the 
> command
> in the following syntax
>
> echo exec('bbackupquery "list -t MyDocuments" exit');
>
> but to burrow down the tree its fine until I hit a directory name with 
> a space ie
>
> echo exec('bbackupquery "list -t MyDocuments/dave/My Documents" exit');
>
> The list command is truncated at the space and no combination of 
> single or
> double quotes seem to work.

I managed to solve the problem by escaping the inner quotes

bbackupquery "list -t \"MyDocuments/dave/My Documents\"" exit

Dave Bamford


From boxbackup-dev@fluffy.co.uk  Sun May 28 02:18:21 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun, 28 May 2006 01:18:21 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r598 - box/chris/general/bin/bbstored
Message-ID: <20060528011821.76DE096@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-28 01:18:13 +0000 (Sun, 28 May 2006)
New Revision: 598

Modified:
   box/chris/general/bin/bbstored/BackupStoreDaemon.h
Log:
* BackupStoreDaemon.h
- Disabled interprocess comms on Win32


Modified: box/chris/general/bin/bbstored/BackupStoreDaemon.h
===================================================================
--- box/chris/general/bin/bbstored/BackupStoreDaemon.h	2006-05-27 09:58:43 UTC (rev 597)
+++ box/chris/general/bin/bbstored/BackupStoreDaemon.h	2006-05-28 01:18:13 UTC (rev 598)
@@ -38,11 +38,13 @@
 	BackupStoreDaemon(const BackupStoreDaemon &rToCopy);
 public:
 
+#ifndef WIN32
 	// For BackupContext to comminicate with housekeeping process
 	void SendMessageToHousekeepingProcess(const void *Msg, int MsgLen)
 	{
 		mInterProcessCommsSocket.Write(Msg, MsgLen);
 	}
+#endif
 
 protected:
 	
@@ -56,22 +58,36 @@
 	virtual const char *DaemonBanner() const;
 
 	const ConfigurationVerify *GetConfigVerify() const;
-	
+
+#ifndef WIN32	
 	// Housekeeping functions
 	void HousekeepingProcess();
 	bool CheckForInterProcessMsg(int AccountNum = 0, int MaximumWaitTime = 0);
+#endif
 
 	void LogConnectionStats(const char *commonName, const SocketStreamTLS &s);
 
+
 private:
 	BackupStoreAccountDatabase *mpAccountDatabase;
 	BackupStoreAccounts *mpAccounts;
 	bool mExtendedLogging;
 	bool mHaveForkedHousekeeping;
 	bool mIsHousekeepingProcess;
-	
+
+#ifndef WIN32	
 	SocketStream mInterProcessCommsSocket;
 	IOStreamGetLine mInterProcessComms;
+#endif
+
+#ifdef WIN32
+	virtual void OnIdle();
+	bool mHousekeepingInited;
+#endif
+
+	void HousekeepingInit();
+	void RunHousekeepingIfNeeded();
+	int64_t mLastHousekeepingRun;
 };
 
 


From boxbackup-dev@fluffy.co.uk  Sun May 28 12:36:02 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun, 28 May 2006 11:36:02 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r599 - box/chris/general/infrastructure
Message-ID: <20060528113602.71DF296@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-28 11:35:52 +0000 (Sun, 28 May 2006)
New Revision: 599

Modified:
   box/chris/general/infrastructure/BoxPlatform.pm.in
Log:
* BoxPlatform.pm.in
- Properly find VERSION.txt in parent directories (makeprotocol.pl)


Modified: box/chris/general/infrastructure/BoxPlatform.pm.in
===================================================================
--- box/chris/general/infrastructure/BoxPlatform.pm.in	2006-05-28 01:18:13 UTC (rev 598)
+++ box/chris/general/infrastructure/BoxPlatform.pm.in	2006-05-28 11:35:52 UTC (rev 599)
@@ -32,7 +32,15 @@
 		or $target_os eq "winnt";
 
 	# get version
-	open VERSION,"VERSION.txt" or die "VERSION.txt: $!";
+	if (! -r "VERSION.txt" and -r "../../VERSION.txt")
+	{
+		open VERSION,"../../VERSION.txt" or die "../../VERSION.txt: $!";
+	}
+	else
+	{
+		open VERSION,"VERSION.txt" or die "VERSION.txt: $!";
+	}
+
 	$product_version = <VERSION>;
 	chomp $product_version;
 	$product_name = <VERSION>;


From boxbackup-dev@fluffy.co.uk  Sun May 28 12:38:13 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun, 28 May 2006 11:38:13 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r600 - box/chris/general/infrastructure
Message-ID: <20060528113813.1BB4096@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-28 11:38:01 +0000 (Sun, 28 May 2006)
New Revision: 600

Modified:
   box/chris/general/infrastructure/buildenv-testmain-template.cpp
Log:
* buildenv-testmain-template.cpp
- Report file and line of first failing test (useful when it's scrolled
  off screen)


Modified: box/chris/general/infrastructure/buildenv-testmain-template.cpp
===================================================================
--- box/chris/general/infrastructure/buildenv-testmain-template.cpp	2006-05-28 11:35:52 UTC (rev 599)
+++ box/chris/general/infrastructure/buildenv-testmain-template.cpp	2006-05-28 11:38:01 UTC (rev 600)
@@ -41,6 +41,8 @@
 #endif
 
 int failures = 0;
+int first_fail_line;
+std::string first_fail_file;
 
 int filedes_open_at_beginning = -1;
 
@@ -128,7 +130,10 @@
 			}
 			if(failures > 0)
 			{
-				printf("FAILED: %d tests failed\n", failures);
+				printf("FAILED: %d tests failed (first at "
+					"%s:%d)\n", failures, 
+					first_fail_file.c_str(),
+					first_fail_line);
 			}
 			else
 			{


From boxbackup-dev@fluffy.co.uk  Tue May 30 20:20:23 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue, 30 May 2006 19:20:23 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r601 - box/chris/general/test/backupstorefix/testfiles
Message-ID: <20060530192023.B550E96@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-30 19:20:18 +0000 (Tue, 30 May 2006)
New Revision: 601

Modified:
   box/chris/general/test/backupstorefix/testfiles/testbackupstorefix.pl
Log:
* testbackupstorefix.pl
- Remove CR characters from bbackupquery output to fix display issues


Modified: box/chris/general/test/backupstorefix/testfiles/testbackupstorefix.pl
===================================================================
--- box/chris/general/test/backupstorefix/testfiles/testbackupstorefix.pl	2006-05-28 11:38:01 UTC (rev 600)
+++ box/chris/general/test/backupstorefix/testfiles/testbackupstorefix.pl	2006-05-30 19:20:18 UTC (rev 601)
@@ -54,7 +54,7 @@
 	open INITIAL,'testfiles/initial-listing.txt' or die "Can't open original listing";
 	while(<INITIAL>)
 	{
-		chomp;
+		chomp; s/\r//;
 		$expected{$_} = 1;
 		m/\A(.+?) .+? (.+)\Z/;
 		$filenames{$2} = $_;
@@ -99,7 +99,7 @@
 	while(<LISTING>)
 	{
 		print LISTING_COPY;
-		chomp;
+		chomp; s/\r//;
 		s/\[FILENAME NOT ENCRYPTED\]//;
 		if(exists $expected{$_})
 		{


From boxbackup-dev@fluffy.co.uk  Tue May 30 20:23:22 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue, 30 May 2006 19:23:22 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r602 - box/chris/general/test/backupstorefix
Message-ID: <20060530192322.ED32896@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-30 19:23:03 +0000 (Tue, 30 May 2006)
New Revision: 602

Modified:
   box/chris/general/test/backupstorefix/testbackupstorefix.cpp
Log:
* testbackupstorefix.cpp
- Fixed paths on Win32
- Fixed files left open while trying to delete them
- Disabled memory leak checks on Win32
- Reduced wait for bbackupd since it has plenty of time 
- Fixed some spelling errors


Modified: box/chris/general/test/backupstorefix/testbackupstorefix.cpp
===================================================================
--- box/chris/general/test/backupstorefix/testbackupstorefix.cpp	2006-05-30 19:20:18 UTC (rev 601)
+++ box/chris/general/test/backupstorefix/testbackupstorefix.cpp	2006-05-30 19:23:03 UTC (rev 602)
@@ -64,9 +64,15 @@
 std::map<std::string, int32_t> nameToID;
 std::map<int32_t, bool> objectIsDir;
 
+#ifdef WIN32
 #define RUN_CHECK	\
+	::system("..\\..\\bin\\bbstoreaccounts\\bbstoreaccounts -c testfiles/bbstored.conf check 01234567"); \
+	::system("..\\..\\bin\\bbstoreaccounts\\bbstoreaccounts -c testfiles/bbstored.conf check 01234567 fix");
+#else
+#define RUN_CHECK	\
 	::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf check 01234567"); \
 	::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf check 01234567 fix");
+#endif
 
 // Wait a given number of seconds for something to complete
 void wait_for_operation(int seconds)
@@ -138,6 +144,7 @@
 	w.Write(rubbish, rubbish_len);
 	// Copy rest of file
 	r->CopyStreamTo(w);
+	r->Close();
 	// Commit
 	w.Commit(true /* convert now */);
 }
@@ -300,11 +307,20 @@
 	rcontroller.Initialise("testfiles/raidfile.conf");
 
 	// Create an account
+#ifdef WIN32
+	TEST_THAT_ABORTONFAIL(::system("..\\..\\bin\\bbstoreaccounts\\bbstoreaccounts -c testfiles/bbstored.conf create 01234567 0 10000B 20000B") == 0);
+#else
 	TEST_THAT_ABORTONFAIL(::system("../../bin/bbstoreaccounts/bbstoreaccounts -c testfiles/bbstored.conf create 01234567 0 10000B 20000B") == 0);
 	TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
+#endif
 
 	// Start the bbstored server
+#ifdef WIN32
+	int pid = LaunchServer("..\\..\\bin\\bbstored\\bbstored testfiles/bbstored.conf", "testfiles/bbstored.pid");
+#else
 	int pid = LaunchServer("../../bin/bbstored/bbstored testfiles/bbstored.conf", "testfiles/bbstored.pid");
+#endif
+
 	TEST_THAT(pid != -1 && pid != 0);
 	if(pid > 0)
 	{
@@ -314,7 +330,12 @@
 		// Run the perl script to create the initial directories
 		TEST_THAT_ABORTONFAIL(::system("perl testfiles/testbackupstorefix.pl init") == 0);
 
+#ifdef WIN32
+		int bbackupd_pid = LaunchServer("..\\..\\bin\\bbackupd\\bbackupd testfiles/bbackupd.conf", "testfiles/bbackupd.pid");
+#else
 		int bbackupd_pid = LaunchServer("../../bin/bbackupd/bbackupd testfiles/bbackupd.conf", "testfiles/bbackupd.pid");
+#endif
+
 		TEST_THAT(bbackupd_pid != -1 && bbackupd_pid != 0);
 		if(bbackupd_pid > 0)
 		{
@@ -322,15 +343,22 @@
 			TEST_THAT(ServerIsAlive(bbackupd_pid));
 	
 			// Create a nice store directory
-			wait_for_operation(30);
+			wait_for_operation(14);
 
 			// That'll do nicely, stop the server	
 			TEST_THAT(KillServer(bbackupd_pid));
+#ifndef WIN32
 			TestRemoteProcessMemLeaks("bbackupd.memleaks");
+#endif
 		}
 		
 		// Generate a list of all the object IDs
+#ifdef WIN32
+		TEST_THAT_ABORTONFAIL(::system("..\\..\\bin\\bbackupquery\\bbackupquery -q -c testfiles/bbackupd.conf \"list -r\" quit > testfiles/initial-listing.txt") == 0);
+#else
 		TEST_THAT_ABORTONFAIL(::system("../../bin/bbackupquery/bbackupquery -q -c testfiles/bbackupd.conf \"list -r\" quit > testfiles/initial-listing.txt") == 0);
+#endif
+
 		// And load it in
 		{
 			FILE *f = ::fopen("testfiles/initial-listing.txt", "r");
@@ -358,7 +386,7 @@
 			del.Delete();
 		}
 		{
-			// Add a suprious file
+			// Add a spurious file
 			RaidFileWrite random(discSetNum, storeRoot + "randomfile");
 			random.Open();
 			random.Write("test", 4);
@@ -367,6 +395,7 @@
 		// Fix it
 		RUN_CHECK
 		// Check everything is as it was
+
 		TEST_THAT(::system("perl testfiles/testbackupstorefix.pl check 0") == 0);
 		// Check the random file doesn't exist
 		{
@@ -410,6 +439,8 @@
 					file_BlockIndexEntry e[2];
 				} h;
 				TEST_THAT(file->Read(&h, sizeof(h)) == sizeof(h));
+				file->Close();
+
 				// Modify
 				TEST_THAT(box_ntoh64(h.hdr.mOtherFileID) == 0);
 				TEST_THAT(box_ntoh64(h.hdr.mNumBlocks) >= 2);
@@ -432,7 +463,7 @@
 		}
 		
 		// ------------------------------------------------------------------------------------------------		
-		::printf("  === Delete directory, change container ID of another, duplicate entry in dir, supurious file size, delete file\n");
+		::printf("  === Delete directory, change container ID of another, duplicate entry in dir, spurious file size, delete file\n");
 		{
 			BackupStoreDirectory dir;
 			LoadDirectory("Test1/foreomizes/stemptinevidate/ict", dir);
@@ -440,7 +471,7 @@
 			SaveDirectory("Test1/foreomizes/stemptinevidate/ict", dir);
 		}
 		int64_t duplicatedID = 0;
-		int64_t notSupriousFileSize = 0;
+		int64_t notSpuriousFileSize = 0;
 		{
 			BackupStoreDirectory dir;
 			LoadDirectory("Test1/cannes/ict/peep", dir);
@@ -458,7 +489,7 @@
 				BackupStoreDirectory::Iterator i(dir);
 				BackupStoreDirectory::Entry *en = i.Next(BackupStoreDirectory::Entry::Flags_File);
 				TEST_THAT(en != 0);
-				notSupriousFileSize = en->GetSizeInBlocks();
+				notSpuriousFileSize = en->GetSizeInBlocks();
 				en->SetSizeInBlocks(3473874);
 				TEST_THAT(en->GetSizeInBlocks() == 3473874);
 			}
@@ -497,7 +528,7 @@
 				BackupStoreDirectory::Iterator i(dir);
 				BackupStoreDirectory::Entry *en = i.Next(BackupStoreDirectory::Entry::Flags_File);
 				TEST_THAT(en != 0);
-				TEST_THAT(en->GetSizeInBlocks() == notSupriousFileSize);
+				TEST_THAT(en->GetSizeInBlocks() == notSpuriousFileSize);
 			}
 		}
 
@@ -572,7 +603,9 @@
 		// ------------------------------------------------------------------------------------------------		
 		// Stop server
 		TEST_THAT(KillServer(pid));
+#ifndef WIN32
 		TestRemoteProcessMemLeaks("bbstored.memleaks");
+#endif
 	}
 
 	return 0;


From boxbackup-dev@fluffy.co.uk  Tue May 30 20:24:16 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue, 30 May 2006 19:24:16 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r603 - box/chris/general
Message-ID: <20060530192416.D0FFB96@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-30 19:24:03 +0000 (Tue, 30 May 2006)
New Revision: 603

Modified:
   box/chris/general/modules.txt
Log:
* modules.txt
- Enabled building bbackupdobjdump on Win32
- Enabled backupstorefix tests on Win32


Modified: box/chris/general/modules.txt
===================================================================
--- box/chris/general/modules.txt	2006-05-30 19:23:03 UTC (rev 602)
+++ box/chris/general/modules.txt	2006-05-30 19:24:03 UTC (rev 603)
@@ -27,8 +27,6 @@
 lib/backupclient	lib/server	lib/crypto	lib/compress
 lib/backupstore		lib/server	lib/raidfile	lib/backupclient
 
-OMIT:mingw32
-OMIT:mingw32msvc
 OMIT:CYGWIN
 bin/bbackupobjdump	lib/backupclient lib/backupstore	lib/win32
 END-OMIT
@@ -40,11 +38,11 @@
 bin/bbackupctl		lib/server	lib/backupclient	lib/win32
 
 test/backupstore	bin/bbstored	bin/bbstoreaccounts lib/server lib/backupstore lib/backupclient lib/raidfile
+test/backupstorefix	bin/bbstored	bin/bbstoreaccounts	lib/backupstore	lib/raidfile	bin/bbackupquery	bin/bbackupd
 
 OMIT:mingw32
 OMIT:mingw32msvc
 OMIT:CYGWIN
-test/backupstorefix	bin/bbstored	bin/bbstoreaccounts	lib/backupstore	lib/raidfile	bin/bbackupquery	bin/bbackupd
 test/backupstorepatch	bin/bbstored	bin/bbstoreaccounts	lib/backupstore	lib/raidfile
 test/backupdiff		lib/backupclient
 test/bbackupd		bin/bbackupd	bin/bbstored bin/bbstoreaccounts bin/bbackupquery bin/bbackupctl lib/server lib/backupstore lib/backupclient


From boxbackup-dev@fluffy.co.uk  Tue May 30 20:24:56 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue, 30 May 2006 19:24:56 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r604 - box/chris/general
Message-ID: <20060530192456.4DB3396@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-30 19:24:51 +0000 (Tue, 30 May 2006)
New Revision: 604

Modified:
   box/chris/general/configure.ac
Log:
* configure.ac
- Fixed missing define for presence of regex.h
- Display status of regex support at end of configure


Modified: box/chris/general/configure.ac
===================================================================
--- box/chris/general/configure.ac	2006-05-30 19:24:03 UTC (rev 603)
+++ box/chris/general/configure.ac	2006-05-30 19:24:51 UTC (rev 604)
@@ -97,6 +97,7 @@
 AC_CHECK_HEADER([regex.h], [have_regex_h=yes])
 
 if test "$have_regex_h" = "yes"; then
+  AC_DEFINE([HAVE_REGEX_H], [1], [Define to 1 if regex.h is available])
   AC_SEARCH_LIBS([regcomp], [pcreposix])
 fi
 
@@ -238,6 +239,7 @@
 without these features, but will work better where they are present. Refer
 to the documentation for more information on each feature.
 
+Regular expressions: $have_regex_h
 Large files:         $have_large_file_support
 Berkeley DB:         $ax_path_bdb_ok
 Readline:            $have_libreadline


From boxbackup-dev@fluffy.co.uk  Tue May 30 20:25:35 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue, 30 May 2006 19:25:35 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r605 - box/chris/general/lib/raidfile
Message-ID: <20060530192535.642A896@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-30 19:25:31 +0000 (Tue, 30 May 2006)
New Revision: 605

Modified:
   box/chris/general/lib/raidfile/RaidFileWrite.cpp
Log:
* RaidFileWrite.cpp
- Unlink files before renaming over them on Win32


Modified: box/chris/general/lib/raidfile/RaidFileWrite.cpp
===================================================================
--- box/chris/general/lib/raidfile/RaidFileWrite.cpp	2006-05-30 19:24:51 UTC (rev 604)
+++ box/chris/general/lib/raidfile/RaidFileWrite.cpp	2006-05-30 19:25:31 UTC (rev 605)
@@ -567,9 +567,17 @@
 
 #ifdef WIN32
 		// Must delete before renaming
-		::unlink(stripe1Filename.c_str());
-		::unlink(stripe2Filename.c_str());
-		::unlink(parityFilename.c_str());
+		#define CHECK_UNLINK(file) \
+		{ \
+			if (::unlink(file) != 0 && errno != ENOENT) \
+			{ \
+				THROW_EXCEPTION(RaidFileException, OSError); \
+			} \
+		}
+		CHECK_UNLINK(stripe1Filename.c_str());
+		CHECK_UNLINK(stripe2Filename.c_str());
+		CHECK_UNLINK(parityFilename.c_str());
+		#undef CHECK_UNLINK
 #endif
 		
 		// Rename them into place


From boxbackup-dev@fluffy.co.uk  Tue May 30 20:26:16 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue, 30 May 2006 19:26:16 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r606 - box/chris/general/lib/backupstore
Message-ID: <20060530192616.47DEF96@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-30 19:26:11 +0000 (Tue, 30 May 2006)
New Revision: 606

Modified:
   box/chris/general/lib/backupstore/BackupStoreCheck.cpp
Log:
* BackupStoreCheck.cpp
- Fixed use of wrong directory separators on Win32


Modified: box/chris/general/lib/backupstore/BackupStoreCheck.cpp
===================================================================
--- box/chris/general/lib/backupstore/BackupStoreCheck.cpp	2006-05-30 19:25:31 UTC (rev 605)
+++ box/chris/general/lib/backupstore/BackupStoreCheck.cpp	2006-05-30 19:26:11 UTC (rev 606)
@@ -328,7 +328,8 @@
 	std::string dirName;
 	StoreStructure::MakeObjectFilename(StartID, mStoreRoot, mDiscSetNumber, dirName, false /* don't make sure the dir exists */);
 	// Check expectations
-	ASSERT(dirName.size() > 4 && dirName[dirName.size() - 4] == '/');
+	ASSERT(dirName.size() > 4 && 
+		dirName[dirName.size() - 4] == DIRECTORY_SEPARATOR_ASCHAR);
 	// Remove the filename from it
 	dirName.resize(dirName.size() - 4); // four chars for "/o00"
 	
@@ -377,7 +378,9 @@
 		if(!fileOK)
 		{
 			// Unexpected or bad file, delete it
-			::printf("Spurious file %s/%s found%s\n", dirName.c_str(), (*i).c_str(), mFixErrors?", deleting":"");
+			::printf("Spurious file %s" DIRECTORY_SEPARATOR "%s "
+				"found%s\n", dirName.c_str(), (*i).c_str(), 
+				mFixErrors?", deleting":"");
 			++mNumberErrorsFound;
 			if(mFixErrors)
 			{


From boxbackup-dev@fluffy.co.uk  Tue May 30 21:01:12 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue, 30 May 2006 20:01:12 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r607 - box/chris/general/lib/win32
Message-ID: <20060530200112.DA1BB96@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-30 20:01:08 +0000 (Tue, 30 May 2006)
New Revision: 607

Modified:
   box/chris/general/lib/win32/emu.cpp
Log:
* emu.cpp
- Improved error return values from emu_unlink()
- Fixed reading from console in debug-compiled code


Modified: box/chris/general/lib/win32/emu.cpp
===================================================================
--- box/chris/general/lib/win32/emu.cpp	2006-05-30 19:26:11 UTC (rev 606)
+++ box/chris/general/lib/win32/emu.cpp	2006-05-30 20:01:08 UTC (rev 607)
@@ -485,7 +485,8 @@
 //
 // Function
 //		Name:    openfile
-//		Purpose: replacement for any open calls - handles unicode filenames - supplied in utf8
+//		Purpose: replacement for any open calls - handles unicode 
+//			filenames - supplied in utf8
 //		Created: 25th October 2004
 //
 // --------------------------------------------------------------------------
@@ -1387,11 +1388,29 @@
 	}
 
 	BOOL result = DeleteFileW(pBuffer);
+	DWORD err = GetLastError();
 	delete [] pBuffer;
 
 	if (!result)
 	{
-		errno = EACCES;
+		if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND)
+		{
+			errno = ENOENT;
+		}
+		else if (err == ERROR_SHARING_VIOLATION)
+		{
+			errno = EBUSY;
+		}
+		else if (err == ERROR_ACCESS_DENIED)
+		{
+			errno = EACCES;
+		}
+		else
+		{
+			::syslog(LOG_WARNING, "Failed to delete file "
+				"'%s': error %d", pFileName, (int)err);
+			errno = ENOSYS;
+		}
 		return -1;
 	}
 
@@ -1423,7 +1442,7 @@
 	if (!ReadConsoleW(
 			hConsole,
 			pWideBuffer,
-			WideSize - 1,
+			WideSize, // will not be null terminated by ReadConsole
 			&numCharsRead,
 			NULL // reserved
 		)) 


From boxbackup-dev@fluffy.co.uk  Tue May 30 21:03:56 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue, 30 May 2006 20:03:56 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r608 - box/chris/general/bin/bbackupd
Message-ID: <20060530200356.2A4EB96@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-30 20:03:47 +0000 (Tue, 30 May 2006)
New Revision: 608

Modified:
   box/chris/general/bin/bbackupd/BackupDaemon.cpp
   box/chris/general/bin/bbackupd/BackupDaemon.h
Log:
* BackupDaemon.cpp, BackupDaemon.h
- Changed to use an Event instead of Sleep+Poll to detect command socket
  activity in the main thread. May also solve inaccurate sleep after error.


Modified: box/chris/general/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/chris/general/bin/bbackupd/BackupDaemon.cpp	2006-05-30 20:01:08 UTC (rev 607)
+++ box/chris/general/bin/bbackupd/BackupDaemon.cpp	2006-05-30 20:03:47 UTC (rev 608)
@@ -125,8 +125,8 @@
 	}
 
 #ifdef WIN32
-	// Create the event object to signal when new messages are
-	// queued to be sent.
+	// Create the event object to signal from main thread to worker
+	// when new messages are queued to be sent to the command socket.
 	mhMessageToSendEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
 	if (mhMessageToSendEvent == INVALID_HANDLE_VALUE)
 	{
@@ -135,6 +135,16 @@
 		exit(1);
 	}
 
+	// Create the event object to signal from worker to main thread
+	// when a command has been received on the command socket.
+	mhCommandReceivedEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+	if (mhCommandReceivedEvent == INVALID_HANDLE_VALUE)
+	{
+		syslog(LOG_ERR, "Failed to create event object: error %d",
+			GetLastError);
+		exit(1);
+	}
+
 	// Create the critical section to protect the message queue
 	InitializeCriticalSection(&mMessageQueueLock);
 
@@ -276,7 +286,7 @@
 void BackupDaemon::RunHelperThread(void)
 {
 	mpCommandSocketInfo = new CommandSocketInfo;
-	this->mReceivedCommandConn = false;
+	// this->mReceivedCommandConn = false;
 	WinNamedPipeStream& rSocket(mpCommandSocketInfo->mListeningSocket);
 
 	// loop until the parent process exits
@@ -426,7 +436,7 @@
 					break;
 				}
 
-				this->mReceivedCommandConn = true;
+				// this->mReceivedCommandConn = true;
 			}
 
 			rSocket.Close();
@@ -985,25 +995,27 @@
 void BackupDaemon::WaitOnCommandSocket(box_time_t RequiredDelay, bool &DoSyncFlagOut, bool &SyncIsForcedOut)
 {
 #ifdef WIN32
-	// Really could use some interprocess protection, mutex etc
-	// any side effect should be too bad???? :)
-	DWORD timeout = (DWORD)BoxTimeToMilliSeconds(RequiredDelay);
+	DWORD requiredDelayMs = BoxTimeToMilliSeconds(RequiredDelay);
 
-	while ( this->mReceivedCommandConn == false )
+	DWORD result = WaitForSingleObject(mhCommandReceivedEvent, 
+		(DWORD)requiredDelayMs);
+
+	if (result == WAIT_OBJECT_0)
 	{
-		Sleep(1);
-
-		if ( timeout == 0 )
-		{
-			DoSyncFlagOut = false;
-			SyncIsForcedOut = false;
-			return;
-		}
-		timeout--;
+		DoSyncFlagOut = this->mDoSyncFlagOut;
+		SyncIsForcedOut = this->mSyncIsForcedOut;
+		ResetEvent(mhCommandReceivedEvent);
 	}
-	this->mReceivedCommandConn = false;
-	DoSyncFlagOut = this->mDoSyncFlagOut;
-	SyncIsForcedOut = this->mSyncIsForcedOut;
+	else if (result == WAIT_TIMEOUT)
+	{
+		DoSyncFlagOut = false;
+		SyncIsForcedOut = false;
+	}
+	else
+	{
+		::syslog(LOG_ERR, "Unexpected result from "
+			"WaitForSingleObject: error %d", GetLastError());
+	}
 
 	return;
 #else // ! WIN32
@@ -1106,8 +1118,10 @@
 		while(mpCommandSocketInfo->mpGetLine != 0 && !mpCommandSocketInfo->mpGetLine->IsEOF()
 			&& mpCommandSocketInfo->mpGetLine->GetLine(command, false /* no preprocessing */, timeout))
 		{
-			TRACE1("Receiving command '%s' over command socket\n", command.c_str());
-			
+			TRACE1("Receiving command '%s' over command socket\n", 
+				command.c_str());
+			SetEvent(mhCommandReceivedEvent);
+
 			bool sendOK = false;
 			bool sendResponse = true;
 		

Modified: box/chris/general/bin/bbackupd/BackupDaemon.h
===================================================================
--- box/chris/general/bin/bbackupd/BackupDaemon.h	2006-05-30 20:01:08 UTC (rev 607)
+++ box/chris/general/bin/bbackupd/BackupDaemon.h	2006-05-30 20:03:47 UTC (rev 608)
@@ -185,8 +185,8 @@
 	void RunHelperThread(void);
 
 	private:
-	bool mDoSyncFlagOut, mSyncIsForcedOut, mReceivedCommandConn;
-	HANDLE mhMessageToSendEvent;
+	bool mDoSyncFlagOut, mSyncIsForcedOut;
+	HANDLE mhMessageToSendEvent, mhCommandReceivedEvent;
 	CRITICAL_SECTION mMessageQueueLock;
 	std::vector<std::string> mMessageList;
 #endif


From boxbackup-dev@fluffy.co.uk  Tue May 30 21:05:49 2006
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue, 30 May 2006 20:05:49 +0000 (GMT)
Subject: [Box Backup-dev] COMMIT r609 - box/chris/general/bin/bbackupd
Message-ID: <20060530200549.672D696@s0g0.pems.testserver.co.uk>

Author: chris
Date: 2006-05-30 20:05:44 +0000 (Tue, 30 May 2006)
New Revision: 609

Modified:
   box/chris/general/bin/bbackupd/BackupClientDirectoryRecord.cpp
Log:
* BackupClientDirectoryRecord.cpp
- Restructured upload decision logic, should be easier to read and
  implement same semantics


Modified: box/chris/general/bin/bbackupd/BackupClientDirectoryRecord.cpp
===================================================================
--- box/chris/general/bin/bbackupd/BackupClientDirectoryRecord.cpp	2006-05-30 20:03:47 UTC (rev 608)
+++ box/chris/general/bin/bbackupd/BackupClientDirectoryRecord.cpp	2006-05-30 20:05:44 UTC (rev 609)
@@ -645,35 +645,76 @@
 		// Need to update?
 		//
 		// Condition for upload:
-		//    modifiction time within sync period
+		//    modification time within sync period
 		//    if it's been seen before but not uploaded, is the time from this first sight longer than the MaxUploadWait
 		//	  and if we know about it from a directory listing, that it hasn't got the same upload time as on the store
-		if(
-			(
-				// Check the file modified within the acceptable time period we're checking
-				// If the file isn't on the server, the acceptable time starts at zero.
-				// Check pDirOnStore and en, because if we didn't download a directory listing,
-				// pDirOnStore will be zero, but we know it's on the server.
-				( ((pDirOnStore != 0 && en == 0) || (modTime >= rParams.mSyncPeriodStart)) && modTime < rParams.mSyncPeriodEnd)
 
-				// However, just in case things are continually modified, we check the first seen time.
-				// The two compares of syncPeriodEnd and pendingFirstSeenTime are because the values are unsigned.
-				|| (pendingFirstSeenTime != 0 &&
-					(rParams.mSyncPeriodEnd > pendingFirstSeenTime)
-						&& ((rParams.mSyncPeriodEnd - pendingFirstSeenTime) > rParams.mMaxUploadWait))
+		bool doUpload = false;
 
-				// Then make sure that if files are added with a time less than the sync period start
-				// (which can easily happen on file server), it gets uploaded. The directory contents checksum
-				// will pick up the fact it has been added, so the store listing will be available when this happens.
-				|| ((modTime <= rParams.mSyncPeriodStart) && (en != 0) && (en->GetModificationTime() != modTime))
-				
-				// And just to catch really badly off clocks in the future for file server clients,
-				// just upload the file if it's madly in the future.
-				|| (modTime > rParams.mUploadAfterThisTimeInTheFuture)
-			)			
-			// But even then, only upload it if the mod time locally is different to that on the server.
-			&& (en == 0 || en->GetModificationTime() != modTime))
+		// Only upload a file if the mod time locally is 
+		// different to that on the server.
+
+		if (en == 0 || en->GetModificationTime() != modTime)
 		{
+			// Check the file modified within the acceptable time period we're checking
+			// If the file isn't on the server, the acceptable time starts at zero.
+			// Check pDirOnStore and en, because if we didn't download a directory listing,
+			// pDirOnStore will be zero, but we know it's on the server.
+			if (modTime < rParams.mSyncPeriodEnd)
+			{
+				if (pDirOnStore != 0 && en == 0)
+				{
+					doUpload = true;
+				}
+				else if (modTime >= rParams.mSyncPeriodStart)
+				{
+					doUpload = true;
+				}
+			}
+
+			// However, just in case things are continually 
+			// modified, we check the first seen time.
+			// The two compares of syncPeriodEnd and 
+			// pendingFirstSeenTime are because the values 
+			// are unsigned.
+
+			if (!doUpload && 
+				pendingFirstSeenTime != 0 &&
+				rParams.mSyncPeriodEnd > pendingFirstSeenTime &&
+				(rParams.mSyncPeriodEnd - pendingFirstSeenTime) 
+				> rParams.mMaxUploadWait)
+			{
+				doUpload = true;
+			}
+
+			// Then make sure that if files are added with a 
+			// time less than the sync period start
+			// (which can easily happen on file server), it 
+			// gets uploaded. The directory contents checksum
+			// will pick up the fact it has been added, so the 
+			// store listing will be available when this happens.
+
+			if (!doUpload &&
+				modTime <= rParams.mSyncPeriodStart && 
+				en != 0 && 
+				en->GetModificationTime() != modTime)
+			{
+				doUpload = true;
+			}
+
+			// And just to catch really badly off clocks in 
+			// the future for file server clients,
+			// just upload the file if it's madly in the future.
+
+			if (!doUpload && modTime > 
+				rParams.mUploadAfterThisTimeInTheFuture)
+			{
+				doUpload = true;
+			}
+		}
+
+		if (doUpload)
+		{
 			// Make sure we're connected -- must connect here so we know whether
 			// the storage limit has been exceeded, and hence whether or not
 			// to actually upload the file.


