From 04a7a8e440fad476bf34315d622c818a7f7830e9 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 30 Oct 2016 19:57:39 +0000 Subject: [PATCH] Remove link and unlink macros on Windows. They provided source-code compatibility with the POSIX versions of these functions, but they conflict with Boost. Replace with EMU_LINK and EMU_UNLINK everywhere. --- lib/backupclient/BackupClientRestore.cpp | 6 +-- .../BackupClientFileAttributes.cpp | 2 +- lib/backupstore/BackupStoreFile.cpp | 2 +- .../BackupStoreRefCountDatabase.cpp | 6 +-- lib/bbackupd/BackupDaemon.cpp | 10 ++--- lib/bbackupquery/BackupQueries.cpp | 12 +++--- lib/common/InvisibleTempFileStream.cpp | 2 +- lib/common/NamedLock.cpp | 4 +- lib/common/Test.cpp | 4 +- lib/raidfile/RaidFileWrite.cpp | 30 +++++++------- lib/server/Daemon.cpp | 2 +- lib/server/ServerControl.cpp | 4 +- lib/server/ServerStream.h | 2 +- lib/win32/emu.h | 22 ++++++---- test/backupstore/testbackupstore.cpp | 8 ++-- test/backupstorefix/testbackupstorefix.cpp | 2 +- .../backupstorepatch/testbackupstorepatch.cpp | 2 +- test/basicserver/testbasicserver.cpp | 2 +- test/bbackupd/testbbackupd.cpp | 40 +++++++++---------- test/httpserver/testhttpserver.cpp | 4 +- test/raidfile/testraidfile.cpp | 10 ++--- 21 files changed, 91 insertions(+), 85 deletions(-) diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index d3300604d..295a4252a 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -277,7 +277,7 @@ static int BackupClientRestoreDir(BackupProtocolCallable &rConnection, "out of the way of restored directory. " "Use specific restore with ID to " "restore this object."); - if(::unlink(rLocalDirectoryName.c_str()) != 0) + if(EMU_UNLINK(rLocalDirectoryName.c_str()) != 0) { BOX_LOG_SYS_ERROR("Failed to delete " "file '" << @@ -513,7 +513,7 @@ static int BackupClientRestoreDir(BackupProtocolCallable &rConnection, // files already there. if(ObjectExists(localFilename) != ObjectExists_NoObject && - ::unlink(localFilename.c_str()) != 0) + EMU_UNLINK(localFilename.c_str()) != 0) { BOX_LOG_SYS_ERROR("Failed to delete " "file '" << localFilename << @@ -912,7 +912,7 @@ int BackupClientRestore(BackupProtocolCallable &rConnection, } // Delete the resume information file - ::unlink(params.mRestoreResumeInfoFilename.c_str()); + EMU_UNLINK(params.mRestoreResumeInfoFilename.c_str()); return params.ContinuedAfterError ? Restore_CompleteWithErrors : Restore_Complete; diff --git a/lib/backupstore/BackupClientFileAttributes.cpp b/lib/backupstore/BackupClientFileAttributes.cpp index 371403012..431e55877 100644 --- a/lib/backupstore/BackupClientFileAttributes.cpp +++ b/lib/backupstore/BackupClientFileAttributes.cpp @@ -814,7 +814,7 @@ void BackupClientFileAttributes::WriteAttributes(const std::string& Filename, Filename << "'"); #else // Make a symlink, first deleting anything in the way - ::unlink(Filename.c_str()); + EMU_UNLINK(Filename.c_str()); if(::symlink((char*)(pattr + 1), Filename.c_str()) != 0) { BOX_LOG_SYS_ERROR("Failed to symlink '" << Filename << diff --git a/lib/backupstore/BackupStoreFile.cpp b/lib/backupstore/BackupStoreFile.cpp index 49bf08cfc..2964ebdd7 100644 --- a/lib/backupstore/BackupStoreFile.cpp +++ b/lib/backupstore/BackupStoreFile.cpp @@ -671,7 +671,7 @@ void BackupStoreFile::DecodeFile(IOStream &rEncodedFile, const char *DecodedFile } catch(...) { - ::unlink(DecodedFilename); + EMU_UNLINK(DecodedFilename); throw; } } diff --git a/lib/backupstore/BackupStoreRefCountDatabase.cpp b/lib/backupstore/BackupStoreRefCountDatabase.cpp index 52d8b0e7d..d3fac52ac 100644 --- a/lib/backupstore/BackupStoreRefCountDatabase.cpp +++ b/lib/backupstore/BackupStoreRefCountDatabase.cpp @@ -68,7 +68,7 @@ void BackupStoreRefCountDatabase::Commit() std::string Final_Filename = GetFilename(mAccount, false); #ifdef WIN32 - if(FileExists(Final_Filename) && unlink(Final_Filename.c_str()) != 0) + if(FileExists(Final_Filename) && EMU_UNLINK(Final_Filename.c_str()) != 0) { THROW_EMU_FILE_ERROR("Failed to delete old permanent refcount " "database file", mFilename, CommonException, @@ -106,7 +106,7 @@ void BackupStoreRefCountDatabase::Discard() mapDatabaseFile.reset(); } - if(unlink(mFilename.c_str()) != 0) + if(EMU_UNLINK(mFilename.c_str()) != 0) { THROW_EMU_FILE_ERROR("Failed to delete temporary refcount " "database file", mFilename, CommonException, @@ -187,7 +187,7 @@ std::auto_ptr { BOX_WARNING(BOX_FILE_MESSAGE(Filename, "Overwriting existing " "temporary reference count database")); - if (unlink(Filename.c_str()) != 0) + if (EMU_UNLINK(Filename.c_str()) != 0) { THROW_SYS_FILE_ERROR("Failed to delete old temporary " "reference count database file", Filename, diff --git a/lib/bbackupd/BackupDaemon.cpp b/lib/bbackupd/BackupDaemon.cpp index 3427a7226..e9a518385 100644 --- a/lib/bbackupd/BackupDaemon.cpp +++ b/lib/bbackupd/BackupDaemon.cpp @@ -531,7 +531,7 @@ void BackupDaemon::Run() mapCommandSocketInfo->mListeningSocket.Listen( socketName); #else - ::unlink(socketName); + EMU_UNLINK(socketName); mapCommandSocketInfo->mListeningSocket.Listen( Socket::TypeUNIX, socketName); #endif @@ -2830,7 +2830,7 @@ void BackupDaemon::FillIDMapVector(std::vector &rVec BOX_NOTICE("Found an incomplete ID map " "database, deleting it to start " "afresh: " << filename); - if(unlink(filename.c_str()) != 0) + if(EMU_UNLINK(filename.c_str()) != 0) { BOX_LOG_NATIVE_ERROR(BOX_FILE_MESSAGE( filename, "Failed to delete " @@ -2879,14 +2879,14 @@ void BackupDaemon::DeleteCorruptBerkelyDbFiles() // Delete the file BOX_TRACE("Deleting " << filename); - ::unlink(filename.c_str()); + EMU_UNLINK(filename.c_str()); // Add a suffix for the new map filename += ".n"; // Delete that too BOX_TRACE("Deleting " << filename); - ::unlink(filename.c_str()); + EMU_UNLINK(filename.c_str()); } } @@ -3637,7 +3637,7 @@ bool BackupDaemon::DeleteStoreObjectInfo() const } // Actually delete it - if(::unlink(storeObjectInfoFile.c_str()) != 0) + if(EMU_UNLINK(storeObjectInfoFile.c_str()) != 0) { BOX_LOG_SYS_ERROR("Failed to delete the old " "StoreObjectInfoFile: " << storeObjectInfoFile); diff --git a/lib/bbackupquery/BackupQueries.cpp b/lib/bbackupquery/BackupQueries.cpp index bcb1827e7..f7a511c93 100644 --- a/lib/bbackupquery/BackupQueries.cpp +++ b/lib/bbackupquery/BackupQueries.cpp @@ -1003,17 +1003,17 @@ void BackupQueries::CommandGetObject(const std::vector &args, const { BOX_ERROR("Object ID " << BOX_FORMAT_OBJECTID(id) << " does not exist on store."); - ::unlink(args[1].c_str()); + EMU_UNLINK(args[1].c_str()); } else { BOX_ERROR("Error occured fetching object."); - ::unlink(args[1].c_str()); + EMU_UNLINK(args[1].c_str()); } } catch(...) { - ::unlink(args[1].c_str()); + EMU_UNLINK(args[1].c_str()); BOX_ERROR("Error occured fetching object."); } } @@ -1242,18 +1242,18 @@ void BackupQueries::CommandGet(std::vector args, const bool *opts) { BOX_ERROR("Failed to fetch file: " << e.what()); - ::unlink(localName.c_str()); + EMU_UNLINK(localName.c_str()); } catch(std::exception &e) { BOX_ERROR("Failed to fetch file: " << e.what()); - ::unlink(localName.c_str()); + EMU_UNLINK(localName.c_str()); } catch(...) { BOX_ERROR("Failed to fetch file: unknown error"); - ::unlink(localName.c_str()); + EMU_UNLINK(localName.c_str()); } } diff --git a/lib/common/InvisibleTempFileStream.cpp b/lib/common/InvisibleTempFileStream.cpp index 1a9d6d5a4..d6d044897 100644 --- a/lib/common/InvisibleTempFileStream.cpp +++ b/lib/common/InvisibleTempFileStream.cpp @@ -31,7 +31,7 @@ InvisibleTempFileStream::InvisibleTempFileStream(const std::string& Filename, #endif { #ifndef WIN32 - if(unlink(Filename.c_str()) != 0) + if(EMU_UNLINK(Filename.c_str()) != 0) { MEMLEAKFINDER_NOT_A_LEAK(this); THROW_EXCEPTION(CommonException, OSFileOpenError) diff --git a/lib/common/NamedLock.cpp b/lib/common/NamedLock.cpp index 8e672ff56..08d7c4619 100644 --- a/lib/common/NamedLock.cpp +++ b/lib/common/NamedLock.cpp @@ -256,7 +256,7 @@ void NamedLock::ReleaseLock() // Windows, and there we need to close the file before deleting it, // otherwise the system won't let us delete it. - if(::unlink(mFileName.c_str()) != 0) + if(EMU_UNLINK(mFileName.c_str()) != 0) { THROW_EMU_ERROR( BOX_FILE_MESSAGE(mFileName, "Failed to delete lockfile"), @@ -287,7 +287,7 @@ void NamedLock::ReleaseLock() // On Windows we need to close the file before deleting it, otherwise // the system won't let us delete it. - if(::unlink(mFileName.c_str()) != 0) + if(EMU_UNLINK(mFileName.c_str()) != 0) { THROW_EMU_ERROR( BOX_FILE_MESSAGE(mFileName, "Failed to delete lockfile"), diff --git a/lib/common/Test.cpp b/lib/common/Test.cpp index d1f6f9726..2eea0b03c 100644 --- a/lib/common/Test.cpp +++ b/lib/common/Test.cpp @@ -122,7 +122,7 @@ bool setUp(const char* function_name) int filetype = ObjectExists(filepath); if(filetype == ObjectExists_File) { - if(::unlink(filepath.c_str()) != 0) + if(EMU_UNLINK(filepath.c_str()) != 0) { TEST_FAIL_WITH_MESSAGE(BOX_SYS_ERROR_MESSAGE("Failed to delete " "test fixture file: unlink(\"" << filepath << "\")")); @@ -586,7 +586,7 @@ void TestRemoteProcessMemLeaksFunc(const char *filename, } // Delete it - ::unlink(filename); + EMU_UNLINK(filename); } #endif } diff --git a/lib/raidfile/RaidFileWrite.cpp b/lib/raidfile/RaidFileWrite.cpp index 8f95ba657..3d6619562 100644 --- a/lib/raidfile/RaidFileWrite.cpp +++ b/lib/raidfile/RaidFileWrite.cpp @@ -358,7 +358,7 @@ void RaidFileWrite::Commit(bool ConvertToRaidNow) #ifdef WIN32 // need to delete the target first - if(::unlink(renameTo.c_str()) != 0) + if(EMU_UNLINK(renameTo.c_str()) != 0) { DWORD errorNumber = GetLastError(); if (errorNumber != ERROR_FILE_NOT_FOUND) @@ -421,9 +421,9 @@ void RaidFileWrite::Discard() #ifdef WIN32 // On Win32 we must close it first if (::close(mOSFileHandle) != 0 || - ::unlink(writeFilename.c_str()) != 0) + EMU_UNLINK(writeFilename.c_str()) != 0) #else // !WIN32 - if (::unlink(writeFilename.c_str()) != 0 || + if (EMU_UNLINK(writeFilename.c_str()) != 0 || ::close(mOSFileHandle) != 0) #endif // !WIN32 { @@ -670,7 +670,7 @@ void RaidFileWrite::TransformToRaidStorage() // Must delete before renaming #define CHECK_UNLINK(file) \ { \ - if (::unlink(file) != 0 && errno != ENOENT) \ + if (EMU_UNLINK(file) != 0 && errno != ENOENT) \ { \ THROW_EMU_ERROR("Failed to unlink raidfile " \ "stripe: " << file, RaidFileException, \ @@ -695,7 +695,7 @@ void RaidFileWrite::TransformToRaidStorage() writeFile.Close(); // Finally delete the write file - if(::unlink(writeFilename.c_str()) != 0) + if(EMU_UNLINK(writeFilename.c_str()) != 0) { BOX_LOG_SYS_ERROR("Failed to delete file: " << writeFilename); @@ -705,12 +705,12 @@ void RaidFileWrite::TransformToRaidStorage() catch(...) { // Unlink all the dodgy files - ::unlink(stripe1Filename.c_str()); - ::unlink(stripe2Filename.c_str()); - ::unlink(parityFilename.c_str()); - ::unlink(stripe1FilenameW.c_str()); - ::unlink(stripe2FilenameW.c_str()); - ::unlink(parityFilenameW.c_str()); + EMU_UNLINK(stripe1Filename.c_str()); + EMU_UNLINK(stripe2Filename.c_str()); + EMU_UNLINK(parityFilename.c_str()); + EMU_UNLINK(stripe1FilenameW.c_str()); + EMU_UNLINK(stripe2FilenameW.c_str()); + EMU_UNLINK(parityFilenameW.c_str()); // and send the error on its way throw; @@ -754,7 +754,7 @@ void RaidFileWrite::Delete() // Attempt to delete it bool deletedSomething = false; - if(::unlink(writeFilename.c_str()) == 0) + if(EMU_UNLINK(writeFilename.c_str()) == 0) { deletedSomething = true; } @@ -769,15 +769,15 @@ void RaidFileWrite::Delete() std::string stripe1Filename(RaidFileUtil::MakeRaidComponentName(rdiscSet, mFilename, 0 % TRANSFORM_NUMBER_DISCS_REQUIRED)); std::string stripe2Filename(RaidFileUtil::MakeRaidComponentName(rdiscSet, mFilename, 1 % TRANSFORM_NUMBER_DISCS_REQUIRED)); std::string parityFilename(RaidFileUtil::MakeRaidComponentName(rdiscSet, mFilename, 2 % TRANSFORM_NUMBER_DISCS_REQUIRED)); - if(::unlink(stripe1Filename.c_str()) == 0) + if(EMU_UNLINK(stripe1Filename.c_str()) == 0) { deletedSomething = true; } - if(::unlink(stripe2Filename.c_str()) == 0) + if(EMU_UNLINK(stripe2Filename.c_str()) == 0) { deletedSomething = true; } - if(::unlink(parityFilename.c_str()) == 0) + if(EMU_UNLINK(parityFilename.c_str()) == 0) { deletedSomething = true; } diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp index a8803bd4f..02bd1183d 100644 --- a/lib/server/Daemon.cpp +++ b/lib/server/Daemon.cpp @@ -690,7 +690,7 @@ int Daemon::Main(const std::string &rConfigFileName) } // Delete the PID file - ::unlink(pidFileName.c_str()); + EMU_UNLINK(pidFileName.c_str()); // Log BOX_NOTICE("Terminating daemon"); diff --git a/lib/server/ServerControl.cpp b/lib/server/ServerControl.cpp index f1a718dff..b6074b9ed 100644 --- a/lib/server/ServerControl.cpp +++ b/lib/server/ServerControl.cpp @@ -239,7 +239,7 @@ bool KillServer(std::string pid_file, bool WaitForProcess) #ifdef WIN32 if(WaitForProcess) { - int unlink_result = unlink(pid_file.c_str()); + int unlink_result = EMU_UNLINK(pid_file.c_str()); TEST_EQUAL_LINE(0, unlink_result, std::string("unlink ") + pid_file); if(unlink_result != 0) { @@ -274,7 +274,7 @@ bool StopDaemon(int current_pid, const std::string& pid_file, TEST_THAT_OR(!ServerIsAlive(current_pid), return false); #ifdef WIN32 - int unlink_result = unlink(pid_file.c_str()); + int unlink_result = EMU_UNLINK(pid_file.c_str()); TEST_EQUAL_LINE(0, unlink_result, std::string("unlink ") + pid_file); if(unlink_result != 0) { diff --git a/lib/server/ServerStream.h b/lib/server/ServerStream.h index 814cb28b7..21fef413e 100644 --- a/lib/server/ServerStream.h +++ b/lib/server/ServerStream.h @@ -204,7 +204,7 @@ class ServerStream : public Daemon } // unlink anything there - ::unlink(c[1].c_str()); + EMU_UNLINK(c[1].c_str()); psocket->Listen(Socket::TypeUNIX, c[1].c_str()); #endif // WIN32 diff --git a/lib/win32/emu.h b/lib/win32/emu.h index b397438c9..b36045a28 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -10,14 +10,18 @@ #ifdef WIN32 #define EMU_STRUCT_STAT struct emu_stat - #define EMU_STAT emu_stat - #define EMU_FSTAT emu_fstat - #define EMU_LSTAT emu_stat + #define EMU_STAT emu_stat + #define EMU_FSTAT emu_fstat + #define EMU_LSTAT emu_stat + #define EMU_LINK emu_link + #define EMU_UNLINK emu_unlink #else #define EMU_STRUCT_STAT struct stat - #define EMU_STAT ::stat - #define EMU_FSTAT ::fstat - #define EMU_LSTAT ::lstat + #define EMU_STAT ::stat + #define EMU_FSTAT ::fstat + #define EMU_LSTAT ::lstat + #define EMU_LINK ::link + #define EMU_UNLINK ::unlink #endif #ifdef WIN32 @@ -369,13 +373,15 @@ int emu_rename (const char* pOldName, const char* pNewName); #define chdir(directory) emu_chdir (directory) #define mkdir(path, mode) emu_mkdir (path) -#define link(oldpath, newpath) emu_link (oldpath, newpath) -#define unlink(file) emu_unlink (file) #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) +// link() and unlink() conflict with Boost if implemented using macros like +// the others above, so I've removed the macros and you need to use EMU_LINK +// and EMU_UNLINK everywhere. + // 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. // diff --git a/test/backupstore/testbackupstore.cpp b/test/backupstore/testbackupstore.cpp index 6441d66cc..3a0f8df6d 100644 --- a/test/backupstore/testbackupstore.cpp +++ b/test/backupstore/testbackupstore.cpp @@ -139,7 +139,7 @@ static const char *uploads_filenames[] = {"49587fds", "cvhjhj324", "sdfcscs324", #define UPLOAD_FILE_TO_MOVE 8 #define UNLINK_IF_EXISTS(filename) \ - if (FileExists(filename)) { TEST_THAT(unlink(filename) == 0); } + if (FileExists(filename)) { TEST_THAT(EMU_UNLINK(filename) == 0); } //! Simplifies calling setUp() with the current function name in each test. #define SETUP_TEST_BACKUPSTORE() \ @@ -482,7 +482,7 @@ void test_test_file(int t, IOStream &rStream) free(data); in.Close(); - TEST_THAT(unlink("testfiles/test_download") == 0); + TEST_THAT(EMU_UNLINK("testfiles/test_download") == 0); } void assert_everything_deleted(BackupProtocolCallable &protocol, int64_t DirID) @@ -2651,7 +2651,7 @@ bool test_login_with_no_refcount_db() // Delete the refcount database and try to log in again. Check that // we're locked out of the account until housekeeping has recreated // the refcount db. - TEST_EQUAL(0, ::unlink("testfiles/0_0/backup/01234567/refcount.rdb.rfw")); + TEST_EQUAL(0, EMU_UNLINK("testfiles/0_0/backup/01234567/refcount.rdb.rfw")); TEST_CHECK_THROWS(BackupProtocolLocal2 protocolLocal(0x01234567, "test", "backup/01234567/", 0, false), // Not read-only BackupStoreException, CorruptReferenceCountDatabase); @@ -2676,7 +2676,7 @@ bool test_login_with_no_refcount_db() // because housekeeping may fix the refcount database while we're // stepping through. TEST_THAT_THROWONFAIL(StartServer()); - TEST_EQUAL(0, ::unlink("testfiles/0_0/backup/01234567/refcount.rdb.rfw")); + TEST_EQUAL(0, EMU_UNLINK("testfiles/0_0/backup/01234567/refcount.rdb.rfw")); TEST_CHECK_THROWS(connect_and_login(context), ConnectionException, Protocol_UnexpectedReply); diff --git a/test/backupstorefix/testbackupstorefix.cpp b/test/backupstorefix/testbackupstorefix.cpp index 38492bd15..0d9de925a 100644 --- a/test/backupstorefix/testbackupstorefix.cpp +++ b/test/backupstorefix/testbackupstorefix.cpp @@ -1009,7 +1009,7 @@ int test(int argc, const char *argv[]) TEST_THAT(KillServer(bbstored_pid)); #ifdef WIN32 - TEST_THAT(unlink("testfiles/bbstored.pid") == 0); + TEST_THAT(EMU_UNLINK("testfiles/bbstored.pid") == 0); #else TestRemoteProcessMemLeaks("bbstored.memleaks"); #endif diff --git a/test/backupstorepatch/testbackupstorepatch.cpp b/test/backupstorepatch/testbackupstorepatch.cpp index 46f278ad1..c26788dc5 100644 --- a/test/backupstorepatch/testbackupstorepatch.cpp +++ b/test/backupstorepatch/testbackupstorepatch.cpp @@ -559,7 +559,7 @@ int test(int argc, const char *argv[]) char filename[64], filename_fetched[64]; ::sprintf(filename, "testfiles/%d.test", f); ::sprintf(filename_fetched, "testfiles/%d.test.fetched", f); - ::unlink(filename_fetched); + EMU_UNLINK(filename_fetched); // Fetch the file { diff --git a/test/basicserver/testbasicserver.cpp b/test/basicserver/testbasicserver.cpp index 3f6548cdb..56ea9af76 100644 --- a/test/basicserver/testbasicserver.cpp +++ b/test/basicserver/testbasicserver.cpp @@ -526,7 +526,7 @@ int test(int argc, const char *argv[]) // Move the config file over #ifdef WIN32 - TEST_THAT(::unlink("testfiles" + TEST_THAT(EMU_UNLINK("testfiles" DIRECTORY_SEPARATOR "srv1.conf") != -1); #endif diff --git a/test/bbackupd/testbbackupd.cpp b/test/bbackupd/testbbackupd.cpp index c288c6341..76b1e28c4 100644 --- a/test/bbackupd/testbbackupd.cpp +++ b/test/bbackupd/testbbackupd.cpp @@ -1442,25 +1442,25 @@ bool test_backup_hardlinked_files() TEST_COMPARE(Compare_Same); // Create some hard links. First in the same directory: - TEST_THAT(link("testfiles/TestDir1/x1/dsfdsfs98.fd", + TEST_THAT(EMU_LINK("testfiles/TestDir1/x1/dsfdsfs98.fd", "testfiles/TestDir1/x1/hardlink1") == 0); bbackupd.RunSyncNow(); TEST_COMPARE(Compare_Same); // Now in a different directory TEST_THAT(mkdir("testfiles/TestDir1/x2", 0755) == 0); - TEST_THAT(link("testfiles/TestDir1/x1/dsfdsfs98.fd", + TEST_THAT(EMU_LINK("testfiles/TestDir1/x1/dsfdsfs98.fd", "testfiles/TestDir1/x2/hardlink2") == 0); bbackupd.RunSyncNow(); TEST_COMPARE(Compare_Same); // Now delete one of them - TEST_THAT(unlink("testfiles/TestDir1/x1/dsfdsfs98.fd") == 0); + TEST_THAT(EMU_UNLINK("testfiles/TestDir1/x1/dsfdsfs98.fd") == 0); bbackupd.RunSyncNow(); TEST_COMPARE(Compare_Same); // And another. - TEST_THAT(unlink("testfiles/TestDir1/x1/hardlink1") == 0); + TEST_THAT(EMU_UNLINK("testfiles/TestDir1/x1/hardlink1") == 0); bbackupd.RunSyncNow(); TEST_COMPARE(Compare_Same); @@ -1500,7 +1500,7 @@ bool test_backup_pauses_when_store_is_full() unpack_files("spacetest2", "testfiles/TestDir1"); // Delete a file and a directory - TEST_THAT(::unlink("testfiles/TestDir1/spacetest/f1") == 0); + TEST_THAT(EMU_UNLINK("testfiles/TestDir1/spacetest/f1") == 0); #ifdef WIN32 TEST_THAT(::system("rd /s/q testfiles\\TestDir1\\spacetest\\d7") == 0); #else @@ -1615,7 +1615,7 @@ bool test_bbackupd_exclusions() TEST_THAT(unpack_files("spacetest1", "testfiles/TestDir1")); // Delete a file and a directory - TEST_THAT(::unlink("testfiles/TestDir1/spacetest/f1") == 0); + TEST_THAT(EMU_UNLINK("testfiles/TestDir1/spacetest/f1") == 0); #ifdef WIN32 TEST_THAT(::system("rd /s/q testfiles\\TestDir1\\spacetest\\d7") == 0); @@ -2402,7 +2402,7 @@ bool test_unicode_filenames_can_be_backed_up() std::string fileToUnlink = "testfiles/restore-" + dirname + "/" + filename; - TEST_THAT(::unlink(fileToUnlink.c_str()) == 0); + TEST_THAT(EMU_UNLINK(fileToUnlink.c_str()) == 0); // Check that bbackupquery can get the file when given // on the command line in system encoding. @@ -2418,7 +2418,7 @@ bool test_unicode_filenames_can_be_backed_up() // cannot overwrite a file that exists, so delete it std::string tmp = "testfiles/" + filename; - TEST_THAT(::unlink(tmp.c_str()) == 0); + TEST_THAT(EMU_UNLINK(tmp.c_str()) == 0); // And after changing directory to an absolute path TEST_THAT(bbackupquery( @@ -2514,7 +2514,7 @@ bool test_sync_allow_script_can_pause_backup() // check that no backup has run (compare fails) TEST_COMPARE(Compare_Different); - TEST_THAT(unlink(sync_control_file) == 0); + TEST_THAT(EMU_UNLINK(sync_control_file) == 0); wait_for_sync_start(); long end_time = time(NULL); long wait_time = end_time - start_time + 2; @@ -2552,7 +2552,7 @@ bool test_delete_update_and_symlink_files() // TODO FIXME dedent { // Delete a file - TEST_THAT(::unlink("testfiles/TestDir1/x1/dsfdsfs98.fd") == 0); + TEST_THAT(EMU_UNLINK("testfiles/TestDir1/x1/dsfdsfs98.fd") == 0); #ifndef WIN32 // New symlink @@ -2707,7 +2707,7 @@ bool test_store_error_reporting() // Check that it did get uploaded, and we have no more errors TEST_COMPARE(Compare_Same); - TEST_THAT(::unlink("testfiles/notifyscript.tag") == 0); + TEST_THAT(EMU_UNLINK("testfiles/notifyscript.tag") == 0); // Stop the snapshot bbackupd TEST_THAT(StopClient()); @@ -2782,7 +2782,7 @@ bool test_store_error_reporting() // Check that it did get uploaded, and we have no more errors TEST_COMPARE(Compare_Same); - TEST_THAT(::unlink("testfiles/notifyscript.tag") == 0); + TEST_THAT(EMU_UNLINK("testfiles/notifyscript.tag") == 0); } TEARDOWN_TEST_BBACKUPD(); @@ -2806,7 +2806,7 @@ bool test_change_file_to_symlink_and_back() // Replace symlink with directory, add new directory. #ifndef WIN32 - TEST_THAT(::unlink("testfiles/TestDir1/symlink-to-dir") + TEST_THAT(EMU_UNLINK("testfiles/TestDir1/symlink-to-dir") == 0); #endif @@ -2831,7 +2831,7 @@ bool test_change_file_to_symlink_and_back() // And the inverse, replace a directory with a file/symlink #ifndef WIN32 - TEST_THAT(::unlink("testfiles/TestDir1/x1/dir-to-file" + TEST_THAT(EMU_UNLINK("testfiles/TestDir1/x1/dir-to-file" "/contents") == 0); #endif @@ -2850,7 +2850,7 @@ bool test_change_file_to_symlink_and_back() BOX_INFO("Replace symlink with directory (which was a symlink)"); #ifndef WIN32 - TEST_THAT(::unlink("testfiles/TestDir1/x1" + TEST_THAT(EMU_UNLINK("testfiles/TestDir1/x1" "/dir-to-file") == 0); #endif @@ -2873,7 +2873,7 @@ bool test_change_file_to_symlink_and_back() // directories over other old directories. #ifndef WIN32 - TEST_THAT(::unlink("testfiles/TestDir1/x1/dir-to-file" + TEST_THAT(EMU_UNLINK("testfiles/TestDir1/x1/dir-to-file" "/contents2") == 0); #endif @@ -2921,7 +2921,7 @@ bool test_file_rename_tracking() TEST_COMPARE(Compare_Same); #ifdef WIN32 - TEST_THAT(::unlink("testfiles/TestDir1/untracked-2") + TEST_THAT(EMU_UNLINK("testfiles/TestDir1/untracked-2") == 0); #endif @@ -2959,7 +2959,7 @@ bool test_file_rename_tracking() TEST_COMPARE(Compare_Same); #ifdef WIN32 - TEST_THAT(::unlink("testfiles/TestDir1/tracked-2") + TEST_THAT(EMU_UNLINK("testfiles/TestDir1/tracked-2") == 0); #endif @@ -2974,7 +2974,7 @@ bool test_file_rename_tracking() // case which went wrong: rename a tracked file // over a deleted file BOX_INFO("Rename an existing file over a deleted file"); - TEST_THAT(::unlink("testfiles/TestDir1/x1/dsfdsfs98.fd") == 0); + TEST_THAT(EMU_UNLINK("testfiles/TestDir1/x1/dsfdsfs98.fd") == 0); TEST_THAT(::rename("testfiles/TestDir1/df9834.dsf", "testfiles/TestDir1/x1/dsfdsfs98.fd") == 0); @@ -3753,7 +3753,7 @@ bool test_restore_deleted_files() bbackupd.RunSyncNow(); TEST_COMPARE(Compare_Same); - TEST_THAT(::unlink("testfiles/TestDir1/f1.dat") == 0); + TEST_THAT(EMU_UNLINK("testfiles/TestDir1/f1.dat") == 0); #ifdef WIN32 TEST_THAT(::system("rd /s/q testfiles\\TestDir1\\x1") == 0); #else diff --git a/test/httpserver/testhttpserver.cpp b/test/httpserver/testhttpserver.cpp index 08b070e40..b08f0bc74 100644 --- a/test/httpserver/testhttpserver.cpp +++ b/test/httpserver/testhttpserver.cpp @@ -598,7 +598,7 @@ bool test_httpserver() FileStream f1("testfiles/testrequests.pl"); FileStream f2("testfiles/store/newfile"); TEST_THAT(f1.CompareWith(f2)); - TEST_EQUAL(0, ::unlink("testfiles/store/newfile")); + TEST_EQUAL(0, EMU_UNLINK("testfiles/store/newfile")); } // Copy testfiles/dsfdsfs98.fd to testfiles/store/dsfdsfs98.fd @@ -723,7 +723,7 @@ bool test_httpserver() FileStream f1("testfiles/dsfdsfs98.fd"); FileStream f2("testfiles/store/newfile"); TEST_THAT(f1.CompareWith(f2)); - TEST_THAT(::unlink("testfiles/store/newfile") == 0); + TEST_THAT(EMU_UNLINK("testfiles/store/newfile") == 0); } // S3Client tests with S3Simulator daemon for realism diff --git a/test/raidfile/testraidfile.cpp b/test/raidfile/testraidfile.cpp index 508152cd5..56b970186 100644 --- a/test/raidfile/testraidfile.cpp +++ b/test/raidfile/testraidfile.cpp @@ -820,7 +820,7 @@ int test(int argc, const char *argv[]) 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" DIRECTORY_SEPARATOR "0_1" DIRECTORY_SEPARATOR "damage.rf") == 0); // stripe 1 + TEST_THAT(EMU_UNLINK("testfiles" DIRECTORY_SEPARATOR "0_1" DIRECTORY_SEPARATOR "damage.rf") == 0); // stripe 1 #ifdef TRF_CAN_INTERCEPT // Open it and read... @@ -837,7 +837,7 @@ int test(int argc, const char *argv[]) #endif //TRF_CAN_INTERCEPT // Delete another - TEST_THAT(::unlink("testfiles" DIRECTORY_SEPARATOR "0_0" DIRECTORY_SEPARATOR "damage.rf") == 0); // parity + TEST_THAT(EMU_UNLINK("testfiles" DIRECTORY_SEPARATOR "0_0" DIRECTORY_SEPARATOR "damage.rf") == 0); // parity TEST_CHECK_THROWS( std::auto_ptr pread2 = RaidFileRead::Open(0, "damage"), @@ -879,15 +879,15 @@ int test(int argc, const char *argv[]) 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" DIRECTORY_SEPARATOR "0_0" DIRECTORY_SEPARATOR "dirread" DIRECTORY_SEPARATOR "sdf9873241.rf") == 0); + TEST_THAT(EMU_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" DIRECTORY_SEPARATOR "0_1" DIRECTORY_SEPARATOR "dirread" DIRECTORY_SEPARATOR "sdf9873241.rf") == 0); + TEST_THAT(EMU_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" DIRECTORY_SEPARATOR "0_2" DIRECTORY_SEPARATOR "dirread" DIRECTORY_SEPARATOR "sdf9873241.rf") == 0); + TEST_THAT(EMU_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)); }