From 824756aadab385140ae5c1ccdf382c387f646ca6 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 30 Aug 2006 14:18:40 +0000 Subject: * bin/bbstored/BackupCommands.cpp - Can't unlink open files on Win32. This is not the correct fix, but it does work around the problem. - Only include syslog.h if we have it --- bin/bbstored/BackupCommands.cpp | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'bin/bbstored/BackupCommands.cpp') diff --git a/bin/bbstored/BackupCommands.cpp b/bin/bbstored/BackupCommands.cpp index 35bc095d..845903b2 100644 --- a/bin/bbstored/BackupCommands.cpp +++ b/bin/bbstored/BackupCommands.cpp @@ -9,7 +9,12 @@ #include "Box.h" +#ifdef HAVE_SYSLOG_H #include +#endif + +#include +#include #include "autogen_BackupProtocolServer.h" #include "BackupConstants.h" @@ -327,8 +332,15 @@ std::auto_ptr BackupProtocolServerGetFile::DoCommand(BackupProto std::auto_ptr diff2(rContext.OpenObject(patchID)); // Choose a temporary filename for the result of the combination - std::string tempFn(RaidFileController::DiscSetPathToFileSystemPath(rContext.GetStoreDiscSet(), rContext.GetStoreRoot() + ".recombinetemp", - p + 16 /* rotate which disc it's on */)); +#ifdef WIN32 + std::ostringstream fs(rContext.GetStoreRoot()); + fs << ".recombinetemp."; + fs << p; + std::string tempFn(fs.str()); + tempFn = RaidFileController::DiscSetPathToFileSystemPath(rContext.GetStoreDiscSet(), tempFn, p + 16); +#else + std::string tempFn(RaidFileController::DiscSetPathToFileSystemPath(rContext.GetStoreDiscSet(), rContext.GetStoreRoot() + ".recombinetemp", p + 16 /* rotate which disc it's on */)); +#endif // Open the temporary file std::auto_ptr combined; @@ -336,14 +348,23 @@ std::auto_ptr BackupProtocolServerGetFile::DoCommand(BackupProto { { // Write nastily to allow this to work with gcc 2.x +#ifdef WIN32 + combined.reset(new FileStream( + tempFn.c_str(), + O_RDWR | O_CREAT | O_EXCL | + O_BINARY | O_TRUNC)); +#else std::auto_ptr t(new FileStream(tempFn.c_str(), O_RDWR | O_CREAT | O_EXCL)); combined = t; +#endif } +#ifndef WIN32 // Unlink immediately as it's a temporary file if(::unlink(tempFn.c_str()) != 0) { THROW_EXCEPTION(CommonException, OSFileError); } +#endif } catch(...) { @@ -359,6 +380,9 @@ std::auto_ptr BackupProtocolServerGetFile::DoCommand(BackupProto combined->Seek(0, IOStream::SeekType_Absolute); // Then shuffle round for the next go +#ifdef WIN32 + if (from.get()) from->Close(); +#endif from = combined; } @@ -396,8 +420,9 @@ std::auto_ptr BackupProtocolServerGetFile::DoCommand(BackupProto stream = t; } - // Object will be deleted when the stream is deleted, so can release the object auto_ptr here to - // avoid premature deletiong + // Object will be deleted when the stream is deleted, + // so can release the object auto_ptr here to avoid + // premature deletion object.release(); } -- cgit v1.2.3