diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:19:49 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:19:49 +0200 |
commit | c8e0e909b4a8d18319fc65434a10dc446434817c (patch) | |
tree | eee91e7d2ce229dd043811eae8f1e2bd78061916 /lib/ShadowCopy | |
parent | 5.2 (diff) | |
download | FreeFileSync-c8e0e909b4a8d18319fc65434a10dc446434817c.tar.gz FreeFileSync-c8e0e909b4a8d18319fc65434a10dc446434817c.tar.bz2 FreeFileSync-c8e0e909b4a8d18319fc65434a10dc446434817c.zip |
5.3
Diffstat (limited to 'lib/ShadowCopy')
-rw-r--r-- | lib/ShadowCopy/LockFile.cpp | 5 | ||||
-rw-r--r-- | lib/ShadowCopy/Shadow_Server2003.vcxproj | 12 | ||||
-rw-r--r-- | lib/ShadowCopy/Shadow_Windows7.vcxproj | 12 | ||||
-rw-r--r-- | lib/ShadowCopy/Shadow_XP.vcxproj | 12 | ||||
-rw-r--r-- | lib/ShadowCopy/shadow.cpp | 36 | ||||
-rw-r--r-- | lib/ShadowCopy/shadow.h | 35 |
6 files changed, 53 insertions, 59 deletions
diff --git a/lib/ShadowCopy/LockFile.cpp b/lib/ShadowCopy/LockFile.cpp index b9008863..aac4c170 100644 --- a/lib/ShadowCopy/LockFile.cpp +++ b/lib/ShadowCopy/LockFile.cpp @@ -20,10 +20,9 @@ int wmain(int argc, wchar_t* argv[]) } std::wstring filename = argv[1]; - //obtain exclusive lock on test file HANDLE hFile = ::CreateFile(filename.c_str(), - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, + GENERIC_READ, + 0, //obtain *exclusive* lock on test file nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, diff --git a/lib/ShadowCopy/Shadow_Server2003.vcxproj b/lib/ShadowCopy/Shadow_Server2003.vcxproj index a893a389..ad24d4c1 100644 --- a/lib/ShadowCopy/Shadow_Server2003.vcxproj +++ b/lib/ShadowCopy/Shadow_Server2003.vcxproj @@ -99,7 +99,7 @@ <SuppressStartupBanner>true</SuppressStartupBanner> <DebugInformationFormat>EditAndContinue</DebugInformationFormat> <DisableSpecificWarnings>4100;4996</DisableSpecificWarnings> - <AdditionalIncludeDirectories>../..</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>../..;C:\Program Files\C++\boost</AdditionalIncludeDirectories> </ClCompile> <Link> <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile> @@ -111,6 +111,7 @@ </ProfileGuidedDatabase> <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary> <TargetMachine>MachineX86</TargetMachine> + <AdditionalLibraryDirectories>C:\Program Files\C++\Boost\stage\lib</AdditionalLibraryDirectories> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> @@ -132,7 +133,7 @@ <SuppressStartupBanner>true</SuppressStartupBanner> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <DisableSpecificWarnings>4100;4996</DisableSpecificWarnings> - <AdditionalIncludeDirectories>../..</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>../..;C:\Program Files\C++\boost</AdditionalIncludeDirectories> </ClCompile> <Link> <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile> @@ -144,6 +145,7 @@ </ProfileGuidedDatabase> <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary> <TargetMachine>MachineX64</TargetMachine> + <AdditionalLibraryDirectories>C:\Program Files\C++\Boost\stage64\lib</AdditionalLibraryDirectories> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> @@ -163,7 +165,7 @@ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <DisableSpecificWarnings>4100;4996</DisableSpecificWarnings> - <AdditionalIncludeDirectories>../..</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>../..;C:\Program Files\C++\boost</AdditionalIncludeDirectories> </ClCompile> <Link> <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile> @@ -177,6 +179,7 @@ </ProfileGuidedDatabase> <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary> <TargetMachine>MachineX86</TargetMachine> + <AdditionalLibraryDirectories>C:\Program Files\C++\Boost\stage\lib</AdditionalLibraryDirectories> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -199,7 +202,7 @@ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <DisableSpecificWarnings>4100;4996</DisableSpecificWarnings> - <AdditionalIncludeDirectories>../..</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>../..;C:\Program Files\C++\boost</AdditionalIncludeDirectories> </ClCompile> <Link> <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile> @@ -213,6 +216,7 @@ </ProfileGuidedDatabase> <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary> <TargetMachine>MachineX64</TargetMachine> + <AdditionalLibraryDirectories>C:\Program Files\C++\Boost\stage64\lib</AdditionalLibraryDirectories> </Link> </ItemDefinitionGroup> <ItemGroup> diff --git a/lib/ShadowCopy/Shadow_Windows7.vcxproj b/lib/ShadowCopy/Shadow_Windows7.vcxproj index 2392fa99..5381372b 100644 --- a/lib/ShadowCopy/Shadow_Windows7.vcxproj +++ b/lib/ShadowCopy/Shadow_Windows7.vcxproj @@ -99,7 +99,7 @@ <SuppressStartupBanner>true</SuppressStartupBanner> <DebugInformationFormat>EditAndContinue</DebugInformationFormat> <DisableSpecificWarnings>4100;4996</DisableSpecificWarnings> - <AdditionalIncludeDirectories>../..</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>../..;C:\Program Files\C++\boost</AdditionalIncludeDirectories> </ClCompile> <Link> <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile> @@ -111,6 +111,7 @@ </ProfileGuidedDatabase> <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary> <TargetMachine>MachineX86</TargetMachine> + <AdditionalLibraryDirectories>C:\Program Files\C++\Boost\stage\lib</AdditionalLibraryDirectories> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> @@ -131,7 +132,7 @@ <SuppressStartupBanner>true</SuppressStartupBanner> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <DisableSpecificWarnings>4100;4996</DisableSpecificWarnings> - <AdditionalIncludeDirectories>../..</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>../..;C:\Program Files\C++\boost</AdditionalIncludeDirectories> <PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;SHADOWDLL_EXPORTS;USE_SHADOW_WINDOWS7;%(PreprocessorDefinitions)</PreprocessorDefinitions> </ClCompile> <Link> @@ -144,6 +145,7 @@ </ProfileGuidedDatabase> <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary> <TargetMachine>MachineX64</TargetMachine> + <AdditionalLibraryDirectories>C:\Program Files\C++\Boost\stage64\lib</AdditionalLibraryDirectories> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> @@ -163,7 +165,7 @@ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <DisableSpecificWarnings>4100;4996</DisableSpecificWarnings> - <AdditionalIncludeDirectories>../..</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>../..;C:\Program Files\C++\boost</AdditionalIncludeDirectories> </ClCompile> <Link> <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile> @@ -177,6 +179,7 @@ </ProfileGuidedDatabase> <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary> <TargetMachine>MachineX86</TargetMachine> + <AdditionalLibraryDirectories>C:\Program Files\C++\Boost\stage\lib</AdditionalLibraryDirectories> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -198,7 +201,7 @@ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <DisableSpecificWarnings>4100;4996</DisableSpecificWarnings> - <AdditionalIncludeDirectories>../..</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>../..;C:\Program Files\C++\boost</AdditionalIncludeDirectories> <PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;SHADOWDLL_EXPORTS;USE_SHADOW_WINDOWS7;%(PreprocessorDefinitions)</PreprocessorDefinitions> </ClCompile> <Link> @@ -213,6 +216,7 @@ </ProfileGuidedDatabase> <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary> <TargetMachine>MachineX64</TargetMachine> + <AdditionalLibraryDirectories>C:\Program Files\C++\Boost\stage64\lib</AdditionalLibraryDirectories> </Link> </ItemDefinitionGroup> <ItemGroup> diff --git a/lib/ShadowCopy/Shadow_XP.vcxproj b/lib/ShadowCopy/Shadow_XP.vcxproj index e49e8941..fce942d5 100644 --- a/lib/ShadowCopy/Shadow_XP.vcxproj +++ b/lib/ShadowCopy/Shadow_XP.vcxproj @@ -99,7 +99,7 @@ <DebugInformationFormat>EditAndContinue</DebugInformationFormat> <FavorSizeOrSpeed>Neither</FavorSizeOrSpeed> <DisableSpecificWarnings>4100;4996</DisableSpecificWarnings> - <AdditionalIncludeDirectories>../..</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>../..;C:\Program Files\C++\boost</AdditionalIncludeDirectories> </ClCompile> <Link> <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile> @@ -111,6 +111,7 @@ </ProfileGuidedDatabase> <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary> <TargetMachine>MachineX86</TargetMachine> + <AdditionalLibraryDirectories>C:\Program Files\C++\Boost\stage\lib</AdditionalLibraryDirectories> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> @@ -133,7 +134,7 @@ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <FavorSizeOrSpeed>Neither</FavorSizeOrSpeed> <DisableSpecificWarnings>4100;4996</DisableSpecificWarnings> - <AdditionalIncludeDirectories>../..</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>../..;C:\Program Files\C++\boost</AdditionalIncludeDirectories> </ClCompile> <Link> <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile> @@ -145,6 +146,7 @@ </ProfileGuidedDatabase> <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary> <TargetMachine>MachineX64</TargetMachine> + <AdditionalLibraryDirectories>C:\Program Files\C++\Boost\stage64\lib</AdditionalLibraryDirectories> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> @@ -164,7 +166,7 @@ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <DisableSpecificWarnings>4100;4996</DisableSpecificWarnings> - <AdditionalIncludeDirectories>../..</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>../..;C:\Program Files\C++\boost</AdditionalIncludeDirectories> </ClCompile> <Link> <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile> @@ -178,6 +180,7 @@ </ProfileGuidedDatabase> <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary> <TargetMachine>MachineX86</TargetMachine> + <AdditionalLibraryDirectories>C:\Program Files\C++\Boost\stage\lib</AdditionalLibraryDirectories> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -200,7 +203,7 @@ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <DisableSpecificWarnings>4100;4996</DisableSpecificWarnings> - <AdditionalIncludeDirectories>../..</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>../..;C:\Program Files\C++\boost</AdditionalIncludeDirectories> </ClCompile> <Link> <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile> @@ -214,6 +217,7 @@ </ProfileGuidedDatabase> <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary> <TargetMachine>MachineX64</TargetMachine> + <AdditionalLibraryDirectories>C:\Program Files\C++\Boost\stage64\lib</AdditionalLibraryDirectories> </Link> </ItemDefinitionGroup> <ItemGroup> 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(); +} diff --git a/lib/ShadowCopy/shadow.h b/lib/ShadowCopy/shadow.h index ea113dae..66d29300 100644 --- a/lib/ShadowCopy/shadow.h +++ b/lib/ShadowCopy/shadow.h @@ -31,44 +31,37 @@ typedef ShadowData* ShadowHandle; //volumeName *must* end with "\" SHADOWDLL_API -ShadowHandle createShadowCopy(const wchar_t* volumeName, // in Returns nullptr on failure! - wchar_t* errorMessage, // out - unsigned int errorBufferLen); // in +ShadowHandle createShadowCopy(const wchar_t* volumeName); //returns nullptr on failure! -//don't forget to release the backupHandle after shadow copy is not needed anymore! +//release the backupHandle after shadow copy is not needed anymore! SHADOWDLL_API void releaseShadowCopy(ShadowHandle handle); SHADOWDLL_API -void getShadowVolume(ShadowHandle handle, //shadowVolName does *not* end with "\" - wchar_t* buffer, - unsigned int bufferLen); +const wchar_t* getShadowVolume(ShadowHandle handle); //never fails, returns shadowVolName, never ending with "\" +//get last error message if any of the functions above fail +SHADOWDLL_API +const wchar_t* getLastError(); //no nullptr check required! //########################################################################################## /*---------- |typedefs| ----------*/ -typedef ShadowHandle (*CreateShadowCopyFct)(const wchar_t* volumeName, - wchar_t* errorMessage, - unsigned int errorBufferLen); - -typedef void (*ReleaseShadowCopyFct)(ShadowHandle handle); - -typedef void (*GetShadowVolumeFct)(ShadowHandle handle, - wchar_t* buffer, - unsigned int bufferLen); - +typedef ShadowHandle (*FunType_createShadowCopy )(const wchar_t* volumeName); +typedef void (*FunType_releaseShadowCopy)(ShadowHandle handle); +typedef const wchar_t* (*FunType_getShadowVolume )(ShadowHandle handle); +typedef const wchar_t* (*FunType_getLastError)(); /*-------------- |symbol names| --------------*/ //(use const pointers to ensure internal linkage) -const char createShadowCopyFctName [] = "createShadowCopy"; -const char releaseShadowCopyFctName[] = "releaseShadowCopy"; -const char getShadowVolumeFctName [] = "getShadowVolume"; - +const char funName_createShadowCopy [] = "createShadowCopy"; +const char funName_releaseShadowCopy[] = "releaseShadowCopy"; +const char funName_getShadowVolume [] = "getShadowVolume"; +const char funName_getLastError [] = "getLastError"; /*--------------- |library names| ---------------*/ |