Skip to content

Commit

Permalink
Remove link and unlink macros on Windows.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
qris committed Dec 17, 2016
1 parent 03f955b commit 953ae97
Show file tree
Hide file tree
Showing 24 changed files with 106 additions and 100 deletions.
6 changes: 3 additions & 3 deletions lib/backupclient/BackupClientRestore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 '" <<
Expand Down Expand Up @@ -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 <<
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/backupstore/BackupClientFileAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<
Expand Down
4 changes: 2 additions & 2 deletions lib/backupstore/BackupFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ RaidBackupFileSystem::PutFilePatch(int64_t ObjectID, int64_t DiffFromFileID,
FileStream diff2(tempFn.c_str(), O_RDONLY);

// Unlink it immediately, so it definitely goes away
if(::unlink(tempFn.c_str()) != 0)
if(EMU_UNLINK(tempFn.c_str()) != 0)
{
THROW_EXCEPTION(CommonException, OSFileError);
}
Expand Down Expand Up @@ -426,7 +426,7 @@ RaidBackupFileSystem::PutFilePatch(int64_t ObjectID, int64_t DiffFromFileID,
catch(...)
{
// Be very paranoid about deleting this temp file -- we could only leave a zero byte file anyway
::unlink(tempFn.c_str());
EMU_UNLINK(tempFn.c_str());
throw;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/backupstore/BackupStoreContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ int64_t BackupStoreContext::AddFile(IOStream &rFile, int64_t InDirectory,
FileStream diff2(tempFn.c_str(), O_RDONLY);

// Unlink it immediately, so it definitely goes away
if(::unlink(tempFn.c_str()) != 0)
if(EMU_UNLINK(tempFn.c_str()) != 0)
{
THROW_EXCEPTION(CommonException, OSFileError);
}
Expand Down Expand Up @@ -646,7 +646,7 @@ int64_t BackupStoreContext::AddFile(IOStream &rFile, int64_t InDirectory,
catch(...)
{
// Be very paranoid about deleting this temp file -- we could only leave a zero byte file anyway
::unlink(tempFn.c_str());
EMU_UNLINK(tempFn.c_str());
throw;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/backupstore/BackupStoreFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ void BackupStoreFile::DecodeFile(IOStream &rEncodedFile, const char *DecodedFile
}
catch(...)
{
::unlink(DecodedFilename);
EMU_UNLINK(DecodedFilename);
throw;
}
}
Expand Down
26 changes: 13 additions & 13 deletions lib/backupstore/BackupStoreRefCountDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,25 @@ void BackupStoreRefCountDatabase::Commit()
mapDatabaseFile->Close();
mapDatabaseFile.reset();

std::string Final_Filename = GetFilename(mAccount, false);
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,
"database file", final_filename, CommonException,
OSFileError);
}
#endif

if(rename(mFilename.c_str(), Final_Filename.c_str()) != 0)
if(rename(mFilename.c_str(), final_filename.c_str()) != 0)
{
THROW_EMU_ERROR("Failed to rename temporary refcount database "
"file from " << mFilename << " to " <<
Final_Filename, CommonException, OSFileError);
final_filename, CommonException, OSFileError);
}

mFilename = Final_Filename;
mFilename = final_filename;
mIsModified = false;
mIsTemporaryFile = false;
}
Expand All @@ -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,
Expand Down Expand Up @@ -180,23 +180,23 @@ std::auto_ptr<BackupStoreRefCountDatabase>
hdr.mMagicValue = htonl(REFCOUNT_MAGIC_VALUE);
hdr.mAccountID = htonl(rAccount.GetID());

std::string Filename = GetFilename(rAccount, true); // temporary
std::string filename = GetFilename(rAccount, true); // temporary

// Open the file for writing
if (FileExists(Filename))
if (FileExists(filename))
{
BOX_WARNING(BOX_FILE_MESSAGE(Filename, "Overwriting existing "
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,
"reference count database file", filename,
CommonException, OSFileError);
}
}

int flags = O_CREAT | O_BINARY | O_RDWR | O_EXCL;
std::auto_ptr<FileStream> DatabaseFile(new FileStream(Filename, flags));
std::auto_ptr<FileStream> DatabaseFile(new FileStream(filename, flags));

// Write header
DatabaseFile->Write(&hdr, sizeof(hdr));
Expand Down
10 changes: 5 additions & 5 deletions lib/bbackupd/BackupDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ void BackupDaemon::Run()
mapCommandSocketInfo->mListeningSocket.Listen(
socketName);
#else
::unlink(socketName);
EMU_UNLINK(socketName);
mapCommandSocketInfo->mListeningSocket.Listen(
Socket::TypeUNIX, socketName);
#endif
Expand Down Expand Up @@ -2830,7 +2830,7 @@ void BackupDaemon::FillIDMapVector(std::vector<BackupClientInodeToIDMap *> &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 "
Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions lib/bbackupquery/BackupQueries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,17 +1003,17 @@ void BackupQueries::CommandGetObject(const std::vector<std::string> &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.");
}
}
Expand Down Expand Up @@ -1242,18 +1242,18 @@ void BackupQueries::CommandGet(std::vector<std::string> 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());
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/common/InvisibleTempFileStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/common/NamedLock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions lib/common/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,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 << "\")"));
Expand Down Expand Up @@ -558,7 +558,7 @@ void TestRemoteProcessMemLeaksFunc(const char *filename,
}

// Delete it
::unlink(filename);
EMU_UNLINK(filename);
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion lib/httpserver/S3Simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ void S3Simulator::HandleDelete(HTTPRequest &rRequest, HTTPResponse &rResponse)
// I think that DELETE is idempotent.
if(FileExists(path))
{
if(::unlink(path.c_str()) != 0)
if(EMU_UNLINK(path.c_str()) != 0)
{
THROW_SYS_FILE_ERROR("Failed to delete file", path,
HTTPException, S3SimulatorError);
Expand Down
30 changes: 15 additions & 15 deletions lib/raidfile/RaidFileWrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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, \
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/server/Daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,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");
Expand Down
Loading

0 comments on commit 953ae97

Please sign in to comment.