summaryrefslogtreecommitdiff
path: root/lib/ShadowCopy/shadow.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:19:49 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:19:49 +0200
commitc8e0e909b4a8d18319fc65434a10dc446434817c (patch)
treeeee91e7d2ce229dd043811eae8f1e2bd78061916 /lib/ShadowCopy/shadow.cpp
parent5.2 (diff)
downloadFreeFileSync-c8e0e909b4a8d18319fc65434a10dc446434817c.tar.gz
FreeFileSync-c8e0e909b4a8d18319fc65434a10dc446434817c.tar.bz2
FreeFileSync-c8e0e909b4a8d18319fc65434a10dc446434817c.zip
5.3
Diffstat (limited to 'lib/ShadowCopy/shadow.cpp')
-rw-r--r--lib/ShadowCopy/shadow.cpp36
1 files changed, 13 insertions, 23 deletions
diff --git a/lib/ShadowCopy/shadow.cpp b/lib/ShadowCopy/shadow.cpp
index bc27e2c3..c47ce983 100644
--- a/lib/ShadowCopy/shadow.cpp
+++ b/lib/ShadowCopy/shadow.cpp
@@ -10,6 +10,7 @@
#include <zen/com_ptr.h>
#include <zen/com_error.h>
#include <zen/scope_guard.h>
+#include <boost/thread/tss.hpp>
#ifdef USE_SHADOW_XP
#include "xp/inc/vss.h"
@@ -74,21 +75,6 @@ std::wstring formatVssError(HRESULT hr) //at least the one's from IVssBackupComp
}
-
-inline
-void copyString(const std::wstring& input, wchar_t* buffer, size_t bufferSize)
-{
- if (bufferSize > 0)
- {
- //size_t endPos = input.copy(buffer, bufferSize - 1);
- //buffer[endPos] = 0;
- const size_t maxSize = std::min(input.length(), bufferSize - 1);
- std::copy(input.begin(), input.begin() + maxSize, buffer);
- buffer[maxSize] = 0;
- }
-}
-
-
shadow::ShadowData createShadowCopy(const wchar_t* volumeName) //throw ComError
{
ComPtr<IVssBackupComponents> backupComp;
@@ -156,12 +142,12 @@ shadow::ShadowData createShadowCopy(const wchar_t* volumeName) //throw ComError
//finally: write volume name of newly created shadow copy
return shadow::ShadowData(backupComp, props.m_pwszSnapshotDeviceObject);
}
+
+boost::thread_specific_ptr<std::wstring> lastErrorMessage; //use "thread_local" in C++11
}
-shadow::ShadowHandle shadow::createShadowCopy(const wchar_t* volumeName,
- wchar_t* errorMessage,
- unsigned int errorBufferLen)
+shadow::ShadowHandle shadow::createShadowCopy(const wchar_t* volumeName)
{
try
{
@@ -170,17 +156,15 @@ shadow::ShadowHandle shadow::createShadowCopy(const wchar_t* volumeName,
}
catch (const zen::ComError& e)
{
- copyString(e.toString(), errorMessage, errorBufferLen);
+ lastErrorMessage.reset(new std::wstring(e.toString()));
return nullptr;
}
}
-void shadow::getShadowVolume(shadow::ShadowHandle handle,
- wchar_t* buffer,
- unsigned int bufferLen)
+const wchar_t* shadow::getShadowVolume(shadow::ShadowHandle handle)
{
- copyString(handle->shadowVolume_, buffer, bufferLen);
+ return handle ? handle->shadowVolume_.c_str() : nullptr; //better fail in client code than here!
}
@@ -188,3 +172,9 @@ void shadow::releaseShadowCopy(ShadowHandle handle)
{
delete handle;
}
+
+
+const wchar_t* shadow::getLastError()
+{
+ return !lastErrorMessage.get() ? L"" : lastErrorMessage->c_str();
+}
bgstack15