diff options
-rw-r--r-- | bin/bbackupd/BackupClientDirectoryRecord.cpp | 26 | ||||
-rw-r--r-- | bin/bbackupd/Win32ServiceFunctions.cpp | 2 | ||||
-rw-r--r-- | bin/bbackupquery/BackupQueries.cpp | 40 | ||||
-rw-r--r-- | lib/backupclient/BackupClientFileAttributes.cpp | 8 | ||||
-rw-r--r-- | lib/backupclient/BackupClientFileAttributes.h | 8 | ||||
-rw-r--r-- | lib/backupclient/BackupStoreFile.cpp | 8 | ||||
-rw-r--r-- | lib/backupclient/BackupStoreFileDiff.cpp | 4 | ||||
-rw-r--r-- | lib/backupstore/BackupStoreAccountDatabase.cpp | 4 | ||||
-rw-r--r-- | lib/common/BoxPlatform.h | 4 | ||||
-rw-r--r-- | lib/common/FileModificationTime.h | 6 | ||||
-rw-r--r-- | lib/common/FileStream.cpp | 4 | ||||
-rw-r--r-- | lib/common/Test.cpp | 16 | ||||
-rw-r--r-- | lib/common/Utils.cpp | 8 | ||||
-rw-r--r-- | lib/raidfile/RaidFileUtil.cpp | 14 | ||||
-rw-r--r-- | lib/server/Daemon.cpp | 4 | ||||
-rw-r--r-- | lib/win32/emu.cpp | 156 | ||||
-rw-r--r-- | lib/win32/emu.h | 66 | ||||
-rw-r--r-- | test/bbackupd/testbbackupd.cpp | 12 |
18 files changed, 127 insertions, 263 deletions
diff --git a/bin/bbackupd/BackupClientDirectoryRecord.cpp b/bin/bbackupd/BackupClientDirectoryRecord.cpp index 10ffe604..4ecb81d9 100644 --- a/bin/bbackupd/BackupClientDirectoryRecord.cpp +++ b/bin/bbackupd/BackupClientDirectoryRecord.cpp @@ -149,12 +149,12 @@ void BackupClientDirectoryRecord::SyncDirectory( // 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 @@ void BackupClientDirectoryRecord::SyncDirectory( 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 @@ void BackupClientDirectoryRecord::SyncDirectory( ::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 @@ void BackupClientDirectoryRecord::SyncDirectory( // 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 @@ void BackupClientDirectoryRecord::SyncDirectory( #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 @@ bool BackupClientDirectoryRecord::UpdateItems( // 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 @@ bool BackupClientDirectoryRecord::UpdateItems( 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 @@ bool BackupClientDirectoryRecord::UpdateItems( 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. diff --git a/bin/bbackupd/Win32ServiceFunctions.cpp b/bin/bbackupd/Win32ServiceFunctions.cpp index 53be3bc7..2df914a7 100644 --- a/bin/bbackupd/Win32ServiceFunctions.cpp +++ b/bin/bbackupd/Win32ServiceFunctions.cpp @@ -203,7 +203,7 @@ int InstallService(const char* pConfigFileName, const std::string& rServiceName) { if (pConfigFileName != NULL) { - struct stat st; + EMU_STRUCT_STAT st; if (emu_stat(pConfigFileName, &st) != 0) { diff --git a/bin/bbackupquery/BackupQueries.cpp b/bin/bbackupquery/BackupQueries.cpp index 26e4da4a..9e6bc9a5 100644 --- a/bin/bbackupquery/BackupQueries.cpp +++ b/bin/bbackupquery/BackupQueries.cpp @@ -914,8 +914,8 @@ void BackupQueries::CommandGetObject(const std::vector<std::string> &args, const } // 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 @@ void BackupQueries::CommandGet(std::vector<std::string> args, const bool *opts) } // 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 @@ void BackupQueries::CommandCompare(const std::vector<std::string> &args, const b 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 @@ void BackupQueries::Compare(const std::string &rStoreDir, { 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 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, 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 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, { 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 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, #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 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, { 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 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, { 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 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, 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()) { diff --git a/lib/backupclient/BackupClientFileAttributes.cpp b/lib/backupclient/BackupClientFileAttributes.cpp index 446f132a..bb17d41f 100644 --- a/lib/backupclient/BackupClientFileAttributes.cpp +++ b/lib/backupclient/BackupClientFileAttributes.cpp @@ -302,8 +302,8 @@ void BackupClientFileAttributes::ReadAttributes(const char *Filename, bool ZeroM 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 @@ void BackupClientFileAttributes::ReadAttributes(const char *Filename, bool ZeroM // 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 @@ void BackupClientFileAttributes::SetAttributeHashSecret(const void *pSecret, int // 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) { diff --git a/lib/backupclient/BackupClientFileAttributes.h b/lib/backupclient/BackupClientFileAttributes.h index fa56ff65..b32c14dd 100644 --- a/lib/backupclient/BackupClientFileAttributes.h +++ b/lib/backupclient/BackupClientFileAttributes.h @@ -15,7 +15,7 @@ #include "StreamableMemBlock.h" #include "BoxTime.h" -struct stat; +EMU_STRUCT_STAT; // declaration // -------------------------------------------------------------------------- // @@ -53,11 +53,13 @@ public: 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; diff --git a/lib/backupclient/BackupStoreFile.cpp b/lib/backupclient/BackupStoreFile.cpp index 68040d29..27e12bc8 100644 --- a/lib/backupclient/BackupStoreFile.cpp +++ b/lib/backupclient/BackupStoreFile.cpp @@ -272,8 +272,8 @@ bool BackupStoreFile::VerifyEncodedFileFormat(IOStream &rFile, int64_t *pDiffFro 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 @@ bool BackupStoreFile::CompareFileContentsAgainstBlockIndex(const char *Filename, // 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) } diff --git a/lib/backupclient/BackupStoreFileDiff.cpp b/lib/backupclient/BackupStoreFileDiff.cpp index 87cf7cff..e9da1ee7 100644 --- a/lib/backupclient/BackupStoreFileDiff.cpp +++ b/lib/backupclient/BackupStoreFileDiff.cpp @@ -130,8 +130,8 @@ std::auto_ptr<IOStream> BackupStoreFile::EncodeFileDiff { // 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) } diff --git a/lib/backupstore/BackupStoreAccountDatabase.cpp b/lib/backupstore/BackupStoreAccountDatabase.cpp index 91a6b758..46cab68f 100644 --- a/lib/backupstore/BackupStoreAccountDatabase.cpp +++ b/lib/backupstore/BackupStoreAccountDatabase.cpp @@ -208,8 +208,8 @@ void BackupStoreAccountDatabase::CheckUpToDate() const // -------------------------------------------------------------------------- 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) } diff --git a/lib/common/BoxPlatform.h b/lib/common/BoxPlatform.h index 269ca85f..01bdbcf1 100644 --- a/lib/common/BoxPlatform.h +++ b/lib/common/BoxPlatform.h @@ -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 diff --git a/lib/common/FileModificationTime.h b/lib/common/FileModificationTime.h index c64ca848..5f13c015 100644 --- a/lib/common/FileModificationTime.h +++ b/lib/common/FileModificationTime.h @@ -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 @@ inline box_time_t FileModificationTime(struct stat &st) 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 @@ inline box_time_t FileAttrModificationTime(struct stat &st) 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); diff --git a/lib/common/FileStream.cpp b/lib/common/FileStream.cpp index 09296d79..d6a3c5da 100644 --- a/lib/common/FileStream.cpp +++ b/lib/common/FileStream.cpp @@ -224,8 +224,8 @@ int FileStream::Read(void *pBuffer, int NBytes, int Timeout) // -------------------------------------------------------------------------- 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) } diff --git a/lib/common/Test.cpp b/lib/common/Test.cpp index 7cf4859b..04d778c1 100644 --- a/lib/common/Test.cpp +++ b/lib/common/Test.cpp @@ -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; } diff --git a/lib/common/Utils.cpp b/lib/common/Utils.cpp index 408eaa57..f45ed26b 100644 --- a/lib/common/Utils.cpp +++ b/lib/common/Utils.cpp @@ -163,8 +163,8 @@ void DumpStackBacktrace() // -------------------------------------------------------------------------- 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 @@ bool FileExists(const char *Filename, int64_t *pFileSize, bool TreatLinksAsNotEx // -------------------------------------------------------------------------- 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) { diff --git a/lib/raidfile/RaidFileUtil.cpp b/lib/raidfile/RaidFileUtil.cpp index 079d14d0..7c6299ec 100644 --- a/lib/raidfile/RaidFileUtil.cpp +++ b/lib/raidfile/RaidFileUtil.cpp @@ -57,7 +57,12 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet, // 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 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet, // 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; } diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp index 3c21f6f9..f8082bad 100644 --- a/lib/server/Daemon.cpp +++ b/lib/server/Daemon.cpp @@ -962,9 +962,9 @@ void Daemon::SetProcessTitle(const char *format, ...) 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) { diff --git a/lib/win32/emu.cpp b/lib/win32/emu.cpp index 189bf587..ad8c3041 100644 --- a/lib/win32/emu.cpp +++ b/lib/win32/emu.cpp @@ -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 @@ HANDLE openfile(const char *pFileName, int flags, int mode) // // 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 @@ int emu_fstat(HANDLE hdir, struct stat * st) 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 @@ HANDLE OpenFileByNameUtf8(const char* pFileName, DWORD flags) // // 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); diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 67921264..b29c901c 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -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 @@ inline int geteuid(void) #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 @@ struct statfs 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 @@ bool ConvertTime_tToFileTime(const time_t from, FILETIME *pTo); 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 @@ int emu_rename (const char* pOldName, const char* pNewName); #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); diff --git a/test/bbackupd/testbbackupd.cpp b/test/bbackupd/testbbackupd.cpp index 2870da3e..9d82a11b 100644 --- a/test/bbackupd/testbbackupd.cpp +++ b/test/bbackupd/testbbackupd.cpp @@ -258,9 +258,9 @@ void finish_with_write_xattr_test() 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 @@ int test_bbackupd() 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 @@ int test_bbackupd() 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 test_bbackupd() } - int compareReturnValue; - #ifdef WIN32 printf("\n==== Check that filenames in UTF-8 " "can be backed up\n"); |