[Box Backup-commit] COMMIT r2460 - in box/trunk: bin/bbackupd bin/bbackupquery lib/backupclient lib/backupstore lib/common lib/raidfile lib/server lib/win32 test/bbackupd

boxbackup-dev at boxbackup.org boxbackup-dev at boxbackup.org
Sat Mar 21 18:48:20 GMT 2009


Author: chris
Date: 2009-03-21 18:48:19 +0000 (Sat, 21 Mar 2009)
New Revision: 2460

Modified:
   box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp
   box/trunk/bin/bbackupd/Win32ServiceFunctions.cpp
   box/trunk/bin/bbackupquery/BackupQueries.cpp
   box/trunk/lib/backupclient/BackupClientFileAttributes.cpp
   box/trunk/lib/backupclient/BackupClientFileAttributes.h
   box/trunk/lib/backupclient/BackupStoreFile.cpp
   box/trunk/lib/backupclient/BackupStoreFileDiff.cpp
   box/trunk/lib/backupstore/BackupStoreAccountDatabase.cpp
   box/trunk/lib/common/BoxPlatform.h
   box/trunk/lib/common/FileModificationTime.h
   box/trunk/lib/common/FileStream.cpp
   box/trunk/lib/common/Test.cpp
   box/trunk/lib/common/Utils.cpp
   box/trunk/lib/raidfile/RaidFileUtil.cpp
   box/trunk/lib/server/Daemon.cpp
   box/trunk/lib/win32/emu.cpp
   box/trunk/lib/win32/emu.h
   box/trunk/test/bbackupd/testbbackupd.cpp
Log:
Fix tests (hopefully) on Win32 for struct stat ino_t change from 16 to
64 bits.


Modified: box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp
===================================================================
--- box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp	2009-03-21 18:48:19 UTC (rev 2460)
@@ -149,12 +149,12 @@
 	// so byte order isn't considered.
 	MD5Digest currentStateChecksum;
 	
-	struct stat dest_st;
+	EMU_STRUCT_STAT dest_st;
 	// Stat the directory, to get attribute info
 	// If it's a symbolic link, we want the link target here
 	// (as we're about to back up the contents of the directory)
 	{
-		if(::stat(rLocalPath.c_str(), &dest_st) != 0)
+		if(EMU_STAT(rLocalPath.c_str(), &dest_st) != 0)
 		{
 			// The directory has probably been deleted, so
 			// just ignore this error. In a future scan, this
@@ -199,8 +199,8 @@
 	std::vector<std::string> files;
 	bool downloadDirectoryRecordBecauseOfFutureFiles = false;
 
-	struct stat link_st;
-	if(::lstat(rLocalPath.c_str(), &link_st) != 0)
+	EMU_STRUCT_STAT link_st;
+	if(EMU_LSTAT(rLocalPath.c_str(), &link_st) != 0)
 	{
 		// Report the error (logs and 
 		// eventual email to administrator)
@@ -258,7 +258,7 @@
 			::memset(&checksum_info, 0, sizeof(checksum_info));
 	
 			struct dirent *en = 0;
-			struct stat file_st;
+			EMU_STRUCT_STAT file_st;
 			std::string filename;
 			while((en = ::readdir(dirHandle)) != 0)
 			{
@@ -292,7 +292,7 @@
 				// prefer S_IFREG, S_IFDIR...
 				int type = en->d_type;
 				#else
-				if(::lstat(filename.c_str(), &file_st) != 0)
+				if(EMU_LSTAT(filename.c_str(), &file_st) != 0)
 				{
 					// Report the error (logs and 
 					// eventual email to administrator)
@@ -387,7 +387,7 @@
 				#ifdef WIN32
 				// We didn't stat the file before,
 				// but now we need the information.
-				if(::lstat(filename.c_str(), &file_st) != 0)
+				if(emu_stat(filename.c_str(), &file_st) != 0)
 				{
  					rNotifier.NotifyFileStatFailed(this, 
  							filename, 
@@ -687,8 +687,8 @@
 		// BLOCK
 		{
 			// Stat the file
-			struct stat st;
-			if(::lstat(filename.c_str(), &st) != 0)
+			EMU_STRUCT_STAT st;
+			if(EMU_LSTAT(filename.c_str(), &st) != 0)
 			{
 				rNotifier.NotifyFileStatFailed(this, 
 					filename, strerror(errno));
@@ -757,8 +757,8 @@
 					if(!isDir && isCurrentVersion)
 					{
 						// Check that the object we found in the ID map doesn't exist on disc
-						struct stat st;
-						if(::stat(localPotentialOldName.c_str(), &st) != 0 && errno == ENOENT)
+						EMU_STRUCT_STAT st;
+						if(EMU_STAT(localPotentialOldName.c_str(), &st) != 0 && errno == ENOENT)
 						{
 							// Doesn't exist locally, but does exist on the server.
 							// Therefore we can safely rename it to this new file.
@@ -1278,8 +1278,8 @@
 						if(isDir && isCurrentVersion)
 						{
 							// Check that the object doesn't exist already
-							struct stat st;
-							if(::stat(localPotentialOldName.c_str(), &st) != 0 && errno == ENOENT)
+							EMU_STRUCT_STAT st;
+							if(EMU_STAT(localPotentialOldName.c_str(), &st) != 0 && errno == ENOENT)
 							{
 								// Doesn't exist locally, but does exist on the server.
 								// Therefore we can safely rename it.

Modified: box/trunk/bin/bbackupd/Win32ServiceFunctions.cpp
===================================================================
--- box/trunk/bin/bbackupd/Win32ServiceFunctions.cpp	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/bin/bbackupd/Win32ServiceFunctions.cpp	2009-03-21 18:48:19 UTC (rev 2460)
@@ -203,7 +203,7 @@
 {
 	if (pConfigFileName != NULL)
 	{
-		struct stat st;
+		EMU_STRUCT_STAT st;
 
 		if (emu_stat(pConfigFileName, &st) != 0)
 		{

Modified: box/trunk/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/trunk/bin/bbackupquery/BackupQueries.cpp	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/bin/bbackupquery/BackupQueries.cpp	2009-03-21 18:48:19 UTC (rev 2460)
@@ -914,8 +914,8 @@
 	}
 	
 	// Does file exist?
-	struct stat st;
-	if(::stat(args[1].c_str(), &st) == 0 || errno != ENOENT)
+	EMU_STRUCT_STAT st;
+	if(EMU_STAT(args[1].c_str(), &st) == 0 || errno != ENOENT)
 	{
 		BOX_ERROR("The local file '" << args[1] << " already exists.");
 		return;
@@ -1146,8 +1146,8 @@
 	}
 	
 	// Does local file already exist? (don't want to overwrite)
-	struct stat st;
-	if(::stat(localName.c_str(), &st) == 0 || errno != ENOENT)
+	EMU_STRUCT_STAT st;
+	if(EMU_STAT(localName.c_str(), &st) == 0 || errno != ENOENT)
 	{
 		BOX_ERROR("The local file " << localName << " already exists, "
 			"will not overwrite it.");
@@ -1227,8 +1227,8 @@
 		std::string syncTimeFilename(mrConfiguration.GetKeyValue("DataDirectory") + DIRECTORY_SEPARATOR_ASCHAR);
 		syncTimeFilename += "last_sync_start";
 		// Stat it to get file time
-		struct stat st;
-		if(::stat(syncTimeFilename.c_str(), &st) == 0)
+		EMU_STRUCT_STAT st;
+		if(EMU_STAT(syncTimeFilename.c_str(), &st) == 0)
 		{
 			// Files modified after this time shouldn't be on the server, so report errors slightly differently
 			LatestFileUploadTime = FileModificationTime(st) -
@@ -1404,8 +1404,8 @@
 	{
 		bool modifiedAfterLastSync = false;
 		
-		struct stat st;
-		if(::stat(rLocalDir.c_str(), &st) == 0)
+		EMU_STRUCT_STAT st;
+		if(EMU_STAT(rLocalDir.c_str(), &st) == 0)
 		{
 			if(FileAttrModificationTime(st) >
 				rParams.LatestFileUploadTime())
@@ -1439,8 +1439,8 @@
 	rParams.NotifyDirComparing(rLocalDir, rStoreDir);
 
 	// Get info on the local directory
-	struct stat st;
-	if(::lstat(rLocalDir.c_str(), &st) != 0)
+	EMU_STRUCT_STAT st;
+	if(EMU_LSTAT(rLocalDir.c_str(), &st) != 0)
 	{
 		// What kind of error?
 		if(errno == ENOTDIR || errno == ENOENT)
@@ -1494,8 +1494,8 @@
 		{
 			bool modifiedAfterLastSync = false;
 			
-			struct stat st;
-			if(::stat(rLocalDir.c_str(), &st) == 0)
+			EMU_STRUCT_STAT st;
+			if(EMU_STAT(rLocalDir.c_str(), &st) == 0)
 			{
 				if(FileAttrModificationTime(st) >
 					rParams.LatestFileUploadTime())
@@ -1547,8 +1547,8 @@
 #ifndef HAVE_VALID_DIRENT_D_TYPE
 			std::string fn(MakeFullPath
 				(rLocalDir, localDirEn->d_name));
-			struct stat st;
-			if(::lstat(fn.c_str(), &st) != 0)
+			EMU_STRUCT_STAT st;
+			if(EMU_LSTAT(fn.c_str(), &st) != 0)
 			{
 			    THROW_EXCEPTION(CommonException, OSFileError)
 			}
@@ -1638,8 +1638,8 @@
 			{				
 				int64_t fileSize = 0;
 
-				struct stat st;
-				if(::stat(localPath.c_str(), &st) == 0)
+				EMU_STRUCT_STAT st;
+				if(EMU_STAT(localPath.c_str(), &st) == 0)
 				{
 					fileSize = st.st_size;
 				}
@@ -1771,8 +1771,8 @@
 			{
 				bool modifiedAfterLastSync = false;
 				
-				struct stat st;
-				if(::stat(localPath.c_str(), &st) == 0)
+				EMU_STRUCT_STAT st;
+				if(EMU_STAT(localPath.c_str(), &st) == 0)
 				{
 					if(FileModificationTime(st) >
 						rParams.LatestFileUploadTime())
@@ -1845,8 +1845,8 @@
 				bool modifiedAfterLastSync = false;
 				
 				// Check the dir modification time
-				struct stat st;
-				if(::stat(localPath.c_str(), &st) == 0 &&
+				EMU_STRUCT_STAT st;
+				if(EMU_STAT(localPath.c_str(), &st) == 0 &&
 					FileModificationTime(st) >
 					rParams.LatestFileUploadTime())
 				{

Modified: box/trunk/lib/backupclient/BackupClientFileAttributes.cpp
===================================================================
--- box/trunk/lib/backupclient/BackupClientFileAttributes.cpp	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/lib/backupclient/BackupClientFileAttributes.cpp	2009-03-21 18:48:19 UTC (rev 2460)
@@ -302,8 +302,8 @@
 	StreamableMemBlock *pnewAttr = 0;
 	try
 	{
-		struct stat st;
-		if(::lstat(Filename, &st) != 0)
+		EMU_STRUCT_STAT st;
+		if(EMU_LSTAT(Filename, &st) != 0)
 		{
 			BOX_LOG_SYS_ERROR("Failed to stat file: '" <<
 				Filename << "'");
@@ -395,7 +395,7 @@
 //		Created: 2003/10/07
 //
 // --------------------------------------------------------------------------
-void BackupClientFileAttributes::FillAttributes(StreamableMemBlock &outputBlock, const char *Filename, struct stat &st, bool ZeroModificationTimes)
+void BackupClientFileAttributes::FillAttributes(StreamableMemBlock &outputBlock, const char *Filename, EMU_STRUCT_STAT &st, bool ZeroModificationTimes)
 {
 	outputBlock.ResizeBlock(sizeof(attr_StreamFormat));
 	attr_StreamFormat *pattr = (attr_StreamFormat*)outputBlock.GetBuffer();
@@ -1037,7 +1037,7 @@
 //		Created: 25/4/04
 //
 // --------------------------------------------------------------------------
-uint64_t BackupClientFileAttributes::GenerateAttributeHash(struct stat &st, const std::string &filename, const std::string &leafname)
+uint64_t BackupClientFileAttributes::GenerateAttributeHash(EMU_STRUCT_STAT &st, const std::string &filename, const std::string &leafname)
 {
 	if(sAttributeHashSecretLength == 0)
 	{

Modified: box/trunk/lib/backupclient/BackupClientFileAttributes.h
===================================================================
--- box/trunk/lib/backupclient/BackupClientFileAttributes.h	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/lib/backupclient/BackupClientFileAttributes.h	2009-03-21 18:48:19 UTC (rev 2460)
@@ -15,7 +15,7 @@
 #include "StreamableMemBlock.h"
 #include "BoxTime.h"
 
-struct stat;
+EMU_STRUCT_STAT; // declaration
 
 // --------------------------------------------------------------------------
 //
@@ -53,11 +53,13 @@
 	static void SetBlowfishKey(const void *pKey, int KeyLength);
 	static void SetAttributeHashSecret(const void *pSecret, int SecretLength);
 	
-	static uint64_t GenerateAttributeHash(struct stat &st, const std::string &filename, const std::string &leafname);
+	static uint64_t GenerateAttributeHash(EMU_STRUCT_STAT &st, const std::string &filename, const std::string &leafname);
 	static void FillExtendedAttr(StreamableMemBlock &outputBlock, const char *Filename);
 
 private:
-	static void FillAttributes(StreamableMemBlock &outputBlock, const char *Filename, struct stat &st, bool ZeroModificationTimes);
+	static void FillAttributes(StreamableMemBlock &outputBlock,
+		const char *Filename, EMU_STRUCT_STAT &st,
+		bool ZeroModificationTimes);
 	static void FillAttributesLink(StreamableMemBlock &outputBlock, const char *Filename, struct stat &st);
 	void WriteExtendedAttr(const char *Filename, int xattrOffset) const;
 

Modified: box/trunk/lib/backupclient/BackupStoreFile.cpp
===================================================================
--- box/trunk/lib/backupclient/BackupStoreFile.cpp	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/lib/backupclient/BackupStoreFile.cpp	2009-03-21 18:48:19 UTC (rev 2460)
@@ -272,8 +272,8 @@
 void BackupStoreFile::DecodeFile(IOStream &rEncodedFile, const char *DecodedFilename, int Timeout, const BackupClientFileAttributes *pAlterativeAttr)
 {
 	// Does file exist?
-	struct stat st;
-	if(::stat(DecodedFilename, &st) == 0)
+	EMU_STRUCT_STAT st;
+	if(EMU_STAT(DecodedFilename, &st) == 0)
 	{
 		THROW_EXCEPTION(BackupStoreException, OutputFileAlreadyExists)
 	}
@@ -1260,8 +1260,8 @@
 	// is it a symlink?
 	bool sourceIsSymlink = false;
 	{
-		struct stat st;
-		if(::lstat(Filename, &st) == -1)
+		EMU_STRUCT_STAT st;
+		if(EMU_LSTAT(Filename, &st) == -1)
 		{
 			THROW_EXCEPTION(CommonException, OSFileError)
 		}

Modified: box/trunk/lib/backupclient/BackupStoreFileDiff.cpp
===================================================================
--- box/trunk/lib/backupclient/BackupStoreFileDiff.cpp	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/lib/backupclient/BackupStoreFileDiff.cpp	2009-03-21 18:48:19 UTC (rev 2460)
@@ -130,8 +130,8 @@
 {
 	// Is it a symlink?
 	{
-		struct stat st;
-		if(::lstat(Filename, &st) != 0)
+		EMU_STRUCT_STAT st;
+		if(EMU_LSTAT(Filename, &st) != 0)
 		{
 			THROW_EXCEPTION(CommonException, OSFileError)
 		}

Modified: box/trunk/lib/backupstore/BackupStoreAccountDatabase.cpp
===================================================================
--- box/trunk/lib/backupstore/BackupStoreAccountDatabase.cpp	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/lib/backupstore/BackupStoreAccountDatabase.cpp	2009-03-21 18:48:19 UTC (rev 2460)
@@ -208,8 +208,8 @@
 // --------------------------------------------------------------------------
 box_time_t BackupStoreAccountDatabase::GetDBFileModificationTime() const
 {
-	struct stat st;
-	if(::stat(pImpl->mFilename.c_str(), &st) == -1)
+	EMU_STRUCT_STAT st;
+	if(EMU_STAT(pImpl->mFilename.c_str(), &st) == -1)
 	{
 		THROW_EXCEPTION(CommonException, OSFileError)
 	}

Modified: box/trunk/lib/common/BoxPlatform.h
===================================================================
--- box/trunk/lib/common/BoxPlatform.h	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/lib/common/BoxPlatform.h	2009-03-21 18:48:19 UTC (rev 2460)
@@ -38,10 +38,6 @@
 		// must define this before importing <sys/types.h>
 		#define __MSVCRT_VERSION__ 0x0601
 	#endif
-
-	// stop sys/types.h from defining its own ino_t as short,
-	// because we want a bigger one :)
-	#define _INO_T_
 #endif
 
 #ifdef HAVE_SYS_TYPES_H

Modified: box/trunk/lib/common/FileModificationTime.h
===================================================================
--- box/trunk/lib/common/FileModificationTime.h	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/lib/common/FileModificationTime.h	2009-03-21 18:48:19 UTC (rev 2460)
@@ -14,7 +14,7 @@
 
 #include "BoxTime.h"
 
-inline box_time_t FileModificationTime(struct stat &st)
+inline box_time_t FileModificationTime(EMU_STRUCT_STAT &st)
 {
 #ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC
 	box_time_t datamodified = ((int64_t)st.st_mtime) * (MICRO_SEC_IN_SEC_LL);
@@ -26,7 +26,7 @@
 	return datamodified;
 }
 
-inline box_time_t FileAttrModificationTime(struct stat &st)
+inline box_time_t FileAttrModificationTime(EMU_STRUCT_STAT &st)
 {
 	box_time_t statusmodified =
 #ifdef HAVE_STRUCT_STAT_ST_MTIMESPEC
@@ -45,7 +45,7 @@
 	return statusmodified;
 }
 
-inline box_time_t FileModificationTimeMaxModAndAttr(struct stat &st)
+inline box_time_t FileModificationTimeMaxModAndAttr(EMU_STRUCT_STAT &st)
 {
 #ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC
 	box_time_t datamodified = ((int64_t)st.st_mtime) * (MICRO_SEC_IN_SEC_LL);

Modified: box/trunk/lib/common/FileStream.cpp
===================================================================
--- box/trunk/lib/common/FileStream.cpp	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/lib/common/FileStream.cpp	2009-03-21 18:48:19 UTC (rev 2460)
@@ -224,8 +224,8 @@
 // --------------------------------------------------------------------------
 IOStream::pos_type FileStream::BytesLeftToRead()
 {
-	struct stat st;
-	if(::fstat(mOSFileHandle, &st) != 0)
+	EMU_STRUCT_STAT st;
+	if(EMU_FSTAT(mOSFileHandle, &st) != 0)
 	{
 		THROW_EXCEPTION(CommonException, OSFileError)
 	}

Modified: box/trunk/lib/common/Test.cpp
===================================================================
--- box/trunk/lib/common/Test.cpp	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/lib/common/Test.cpp	2009-03-21 18:48:19 UTC (rev 2460)
@@ -25,28 +25,28 @@
 
 bool TestFileExists(const char *Filename)
 {
-	struct stat st;
-	return ::stat(Filename, &st) == 0 && (st.st_mode & S_IFDIR) == 0;
+	EMU_STRUCT_STAT st;
+	return EMU_STAT(Filename, &st) == 0 && (st.st_mode & S_IFDIR) == 0;
 }
 
 bool TestFileNotEmpty(const char *Filename)
 {
-	struct stat st;
-	return ::stat(Filename, &st) == 0 && (st.st_mode & S_IFDIR) == 0 &&
+	EMU_STRUCT_STAT st;
+	return EMU_STAT(Filename, &st) == 0 && (st.st_mode & S_IFDIR) == 0 &&
 		st.st_size > 0;
 }
 
 bool TestDirExists(const char *Filename)
 {
-	struct stat st;
-	return ::stat(Filename, &st) == 0 && (st.st_mode & S_IFDIR) == S_IFDIR;
+	EMU_STRUCT_STAT st;
+	return EMU_STAT(Filename, &st) == 0 && (st.st_mode & S_IFDIR) == S_IFDIR;
 }
 
 // -1 if doesn't exist
 int TestGetFileSize(const char *Filename)
 {
-	struct stat st;
-	if(::stat(Filename, &st) == 0)
+	EMU_STRUCT_STAT st;
+	if(EMU_STAT(Filename, &st) == 0)
 	{
 		return st.st_size;
 	}

Modified: box/trunk/lib/common/Utils.cpp
===================================================================
--- box/trunk/lib/common/Utils.cpp	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/lib/common/Utils.cpp	2009-03-21 18:48:19 UTC (rev 2460)
@@ -163,8 +163,8 @@
 // --------------------------------------------------------------------------
 bool FileExists(const char *Filename, int64_t *pFileSize, bool TreatLinksAsNotExisting)
 {
-	struct stat st;
-	if(::lstat(Filename, &st) != 0)
+	EMU_STRUCT_STAT st;
+	if(EMU_LSTAT(Filename, &st) != 0)
 	{
 		if(errno == ENOENT)
 		{
@@ -208,8 +208,8 @@
 // --------------------------------------------------------------------------
 int ObjectExists(const std::string& rFilename)
 {
-	struct stat st;
-	if(::stat(rFilename.c_str(), &st) != 0)
+	EMU_STRUCT_STAT st;
+	if(EMU_STAT(rFilename.c_str(), &st) != 0)
 	{
 		if(errno == ENOENT)
 		{

Modified: box/trunk/lib/raidfile/RaidFileUtil.cpp
===================================================================
--- box/trunk/lib/raidfile/RaidFileUtil.cpp	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/lib/raidfile/RaidFileUtil.cpp	2009-03-21 18:48:19 UTC (rev 2460)
@@ -57,7 +57,12 @@
 			// Get unique ID
 			if(pRevisionID != 0)
 			{
-				(*pRevisionID) = FileModificationTime(st);
+				#ifdef WIN32
+					*pRevisionID = st.st_mtime;
+				#else
+					*pRevisionID = FileModificationTime(st);
+				#endif
+
 #ifdef BOX_RELEASE_BUILD
 				// The resolution of timestamps may be very
 				// low, e.g. 1 second. So add the size to it
@@ -98,7 +103,12 @@
 			// Revision ID
 			if(pRevisionID != 0)
 			{
-				int64_t rid = FileModificationTime(st);
+				#ifdef WIN32
+					int64_t rid = st.st_mtime;
+				#else
+					int64_t rid = FileModificationTime(st);
+				#endif
+
 				if(rid > revisionID) revisionID = rid;
 				revisionIDplus += st.st_size;
 			}

Modified: box/trunk/lib/server/Daemon.cpp
===================================================================
--- box/trunk/lib/server/Daemon.cpp	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/lib/server/Daemon.cpp	2009-03-21 18:48:19 UTC (rev 2460)
@@ -962,9 +962,9 @@
 
 box_time_t Daemon::GetConfigFileModifiedTime() const
 {
-	struct stat st;
+	EMU_STRUCT_STAT st;
 
-	if(::stat(GetConfigFileName().c_str(), &st) != 0)
+	if(EMU_STAT(GetConfigFileName().c_str(), &st) != 0)
 	{
 		if (errno == ENOENT)
 		{

Modified: box/trunk/lib/win32/emu.cpp
===================================================================
--- box/trunk/lib/win32/emu.cpp	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/lib/win32/emu.cpp	2009-03-21 18:48:19 UTC (rev 2460)
@@ -21,149 +21,9 @@
 #include <sstream>
 
 // message resource definitions for syslog()
-
 #include "messages.h"
 
-// our implementation for a timer, based on a 
-// simple thread which sleeps for a period of time
-
-static bool gTimerInitialised = false;
-static bool gFinishTimer;
-static CRITICAL_SECTION gLock;
-
 DWORD winerrno;
-
-typedef struct 
-{
-	int countDown;
-	int interval;
-}
-Timer_t;
-
-std::list<Timer_t> gTimerList;
-static void (__cdecl *gTimerFunc) (int) = NULL;
-
-int setitimer(int type, struct itimerval *timeout, void *arg)
-{
-	assert(gTimerInitialised);
-	
-	if (ITIMER_REAL != type)
-	{
-		errno = ENOSYS;
-		return -1;
-	}
-
-	EnterCriticalSection(&gLock);
-
-	// we only need seconds for the mo!
-	if (timeout->it_value.tv_sec  == 0 && 
-	    timeout->it_value.tv_usec == 0)
-	{
-		gTimerList.clear();
-	}
-	else
-	{
-		Timer_t ourTimer;
-		ourTimer.countDown = timeout->it_value.tv_sec;
-		ourTimer.interval  = timeout->it_interval.tv_sec;
-		gTimerList.push_back(ourTimer);
-	}
-
-	LeaveCriticalSection(&gLock);
-	
-	// indicate success
-	return 0;
-}
-
-static unsigned int WINAPI RunTimer(LPVOID lpParameter)
-{
-	gFinishTimer = false;
-
-	while (!gFinishTimer)
-	{
-		std::list<Timer_t>::iterator it;
-		EnterCriticalSection(&gLock);
-
-		for (it = gTimerList.begin(); it != gTimerList.end(); it++)
-		{
-			Timer_t& rTimer(*it);
-
-			rTimer.countDown --;
-			if (rTimer.countDown == 0)
-			{
-				if (gTimerFunc != NULL)
-				{
-					gTimerFunc(0);
-				}
-				if (rTimer.interval)
-				{
-					rTimer.countDown = rTimer.interval;
-				}
-				else
-				{
-					// mark for deletion
-					rTimer.countDown = -1;
-				}
-			}
-		}
-
-		for (it = gTimerList.begin(); it != gTimerList.end(); it++)
-		{
-			Timer_t& rTimer(*it);
-
-			if (rTimer.countDown == -1)
-			{
-				gTimerList.erase(it);
-				
-				// the iterator is now invalid, so restart search
-				it = gTimerList.begin();
-
-				// if the list is now empty, don't try to increment 
-				// the iterator again
-				if (it == gTimerList.end()) break;
-			}
-		}
-
-		LeaveCriticalSection(&gLock);
-		// we only need to have a 1 second resolution
-		Sleep(1000);
-	}
-
-	return 0;
-}
-
-int SetTimerHandler(void (__cdecl *func ) (int))
-{
-	gTimerFunc = func;
-	return 0;
-}
-
-void InitTimer(void)
-{
-	assert(!gTimerInitialised);
-
-	InitializeCriticalSection(&gLock);
-	
-	// create our thread
-	HANDLE ourThread = (HANDLE)_beginthreadex(NULL, 0, RunTimer, 0, 
-		CREATE_SUSPENDED, NULL);
-	SetThreadPriority(ourThread, THREAD_PRIORITY_LOWEST);
-	ResumeThread(ourThread);
-
-	gTimerInitialised = true;
-}
-
-void FiniTimer(void)
-{
-	assert(gTimerInitialised);
-	gFinishTimer = true;
-	EnterCriticalSection(&gLock);
-	DeleteCriticalSection(&gLock);
-	gTimerInitialised = false;
-}
-
-//Our constants we need to keep track of
-//globals
 struct passwd gTempPasswd;
 
 bool EnableBackupRights()
@@ -715,11 +575,13 @@
 //
 // Function
 //		Name:    emu_fstat
-//		Purpose: replacement for fstat supply a windows handle
+//		Purpose: replacement for fstat. Supply a windows handle.
+//			 Returns a struct emu_stat to have room for 64-bit
+//			 file identifier in st_ino (mingw allows only 16!)
 //		Created: 25th October 2004
 //
 // --------------------------------------------------------------------------
-int emu_fstat(HANDLE hdir, struct stat * st)
+int emu_fstat(HANDLE hdir, struct emu_stat * st)
 {
 	if (hdir == INVALID_HANDLE_VALUE)
 	{
@@ -751,7 +613,7 @@
 	ULARGE_INTEGER conv;
 	conv.HighPart = fi.nFileIndexHigh;
 	conv.LowPart  = fi.nFileIndexLow;
-	st->st_ino = (_ino_t)conv.QuadPart;
+	st->st_ino = conv.QuadPart;
 
 	// get the time information
 	st->st_ctime = ConvertFileTimeToTime_t(&fi.ftCreationTime);
@@ -898,12 +760,14 @@
 //
 // Function
 //		Name:    emu_stat 
-//		Purpose: replacement for the lstat and stat functions, 
-//			works with unicode filenames supplied in utf8 format
+//		Purpose: replacement for the lstat and stat functions. 
+//			 Works with unicode filenames supplied in utf8.
+//			 Returns a struct emu_stat to have room for 64-bit
+//			 file identifier in st_ino (mingw allows only 16!)
 //		Created: 25th October 2004
 //
 // --------------------------------------------------------------------------
-int emu_stat(const char * pName, struct stat * st)
+int emu_stat(const char * pName, struct emu_stat * st)
 {
 	HANDLE handle = OpenFileByNameUtf8(pName, 
 		FILE_READ_ATTRIBUTES | FILE_READ_EA);

Modified: box/trunk/lib/win32/emu.h
===================================================================
--- box/trunk/lib/win32/emu.h	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/lib/win32/emu.h	2009-03-21 18:48:19 UTC (rev 2460)
@@ -1,5 +1,17 @@
 // emulates unix syscalls to win32 functions
 
+#ifdef WIN32
+	#define EMU_STRUCT_STAT struct emu_stat
+	#define EMU_STAT  emu_stat
+	#define EMU_FSTAT emu_fstat
+	#define EMU_LSTAT emu_stat
+#else
+	#define EMU_STRUCT_STAT struct stat
+	#define EMU_STAT  ::stat
+	#define EMU_FSTAT ::fstat
+	#define EMU_LSTAT ::lstat
+#endif
+
 #if ! defined EMU_INCLUDE && defined WIN32
 #define EMU_INCLUDE
 
@@ -25,17 +37,9 @@
 
 #ifdef __MINGW32__
 	typedef uint32_t u_int32_t;
-	typedef uint64_t _ino_t;
-	typedef _ino_t ino_t;
-	#define _INO_T_
 #else
 	typedef unsigned int mode_t;
 	typedef unsigned int pid_t;
-
-	// must define _INO_T_DEFINED before including <sys/types.h>
-	// to replace it with our own.
-	typedef u_int64_t _ino_t;
-	#define _INO_T_DEFINED
 #endif
 
 // set up to include the necessary parts of Windows headers
@@ -81,11 +85,6 @@
 #define fileno(struct_file)   _fileno(struct_file)
 #endif
 
-int SetTimerHandler(void (__cdecl *func ) (int));
-int setitimer(int type, struct itimerval *timeout, void *arg);
-void InitTimer(void);
-void FiniTimer(void);
-
 struct passwd {
 	char *pw_name;
 	char *pw_passwd;
@@ -187,13 +186,6 @@
 
 #define timespec timeval
 
-//not available in win32
-struct itimerval
-{
-	timeval 	it_interval;
-	timeval 	it_value;
-};
-
 //win32 deals in usec not nsec - so need to ensure this follows through
 #define tv_nsec tv_usec 
 
@@ -313,27 +305,19 @@
 	TCHAR f_mntonname[MAX_PATH];
 };
 
-#if 0
-// I think this should get us going
-// Although there is a warning about 
-// mount points in win32 can now exists - which means inode number can be 
-// duplicated, so potential of a problem - perhaps this needs to be 
-// implemented with a little more thought... TODO
-
-struct stat {
-	//_dev_t st_dev;
-	u_int64_t st_ino;
+struct emu_stat {
+	int st_dev;
+	uint64_t st_ino;
 	DWORD st_mode;
 	short st_nlink;
 	short st_uid;
 	short st_gid;
 	//_dev_t st_rdev;
-	u_int64_t st_size;
+	uint64_t st_size;
 	time_t st_atime;
 	time_t st_mtime;
 	time_t st_ctime;
 };
-#endif // 0
 
 // need this for conversions
 time_t ConvertFileTimeToTime_t(FILETIME *fileTime);
@@ -342,8 +326,8 @@
 int   emu_chdir  (const char* pDirName);
 int   emu_mkdir  (const char* pPathName);
 int   emu_unlink (const char* pFileName);
-int   emu_fstat  (HANDLE file,       struct stat* st);
-int   emu_stat   (const char* pName, struct stat* st);
+int   emu_fstat  (HANDLE file,       struct emu_stat* st);
+int   emu_stat   (const char* pName, struct emu_stat* st);
 int   emu_utimes (const char* pName, const struct timeval[]);
 int   emu_chmod  (const char* pName, mode_t mode);
 char* emu_getcwd (char* pBuffer,     int BufSize);
@@ -352,14 +336,22 @@
 #define chdir(directory)        emu_chdir  (directory)
 #define mkdir(path,     mode)   emu_mkdir  (path)
 #define unlink(file)            emu_unlink (file)
-#define stat(filename,  struct) emu_stat   (filename, struct)
-#define lstat(filename, struct) emu_stat   (filename, struct)
-#define fstat(handle,   struct) emu_fstat  (handle,   struct)
 #define utimes(buffer,  times)  emu_utimes (buffer,   times)
 #define chmod(file,     mode)   emu_chmod  (file,     mode)
 #define getcwd(buffer,  size)   emu_getcwd (buffer,   size)
 #define rename(oldname, newname) emu_rename (oldname, newname)
 
+// Not safe to replace stat/fstat/lstat on mingw at least, as struct stat
+// has a 16-bit st_ino and we need a 64-bit one.
+//
+// #define stat(filename,  struct) emu_stat   (filename, struct)
+// #define lstat(filename, struct) emu_stat   (filename, struct)
+// #define fstat(handle,   struct) emu_fstat  (handle,   struct)
+//
+// But lstat doesn't exist on Windows, so we have to provide something:
+
+#define lstat(filename, struct) stat(filename, struct)
+
 int statfs(const char * name, struct statfs * s);
 
 int poll(struct pollfd *ufds, unsigned long nfds, int timeout);

Modified: box/trunk/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/trunk/test/bbackupd/testbbackupd.cpp	2009-03-20 18:33:16 UTC (rev 2459)
+++ box/trunk/test/bbackupd/testbbackupd.cpp	2009-03-21 18:48:19 UTC (rev 2460)
@@ -258,9 +258,9 @@
 
 bool attrmatch(const char *f1, const char *f2)
 {
-	struct stat s1, s2;
-	TEST_THAT(::lstat(f1, &s1) == 0);
-	TEST_THAT(::lstat(f2, &s2) == 0);
+	EMU_STRUCT_STAT s1, s2;
+	TEST_THAT(EMU_LSTAT(f1, &s1) == 0);
+	TEST_THAT(EMU_LSTAT(f2, &s2) == 0);
 
 #ifdef HAVE_SYS_XATTR_H
 	{
@@ -2027,6 +2027,8 @@
 		printf("\n==== Check that read-only directories and "
 			"their contents can be restored.\n");
 
+		int compareReturnValue;
+
 		{
 			#ifdef WIN32
 				TEST_THAT(::system("chmod 0555 testfiles/"
@@ -2039,7 +2041,7 @@
 			wait_for_sync_end(); // too new
 			wait_for_sync_end(); // should be backed up now
 
-			int compareReturnValue = ::system(BBACKUPQUERY " "
+			compareReturnValue = ::system(BBACKUPQUERY " "
 				"-Wwarning "
 				"-c testfiles/bbackupd.conf "
 				"\"compare -cEQ Test1 testfiles/TestDir1\" " 
@@ -2083,8 +2085,6 @@
 
 		}
 
-		int compareReturnValue;
-
 #ifdef WIN32
 		printf("\n==== Check that filenames in UTF-8 "
 			"can be backed up\n");




More information about the Boxbackup-commit mailing list