Permalink
Browse files

Consolidated directory creation code. Fixes #4.

  • Loading branch information...
candera committed Mar 4, 2011
1 parent adeb5fe commit 319dbd4a6612834fc30a94807b13bff54317a8ef
Showing with 7 additions and 61 deletions.
  1. +6 −26 CCopyAction.h
  2. +1 −35 Utilities.h
View
@@ -84,33 +84,13 @@ class CCopyAction : public CDirectoryAction
{
CString destDir;
Utilities::CombinePath(_destination, path, destDir);
Utilities::FixLongFilenames(destDir);
BOOL bCreated = ::CreateDirectory(destDir, NULL);
if (!bCreated)
{
DWORD error = ::GetLastError();
if (error != ERROR_ALREADY_EXISTS)
{
CString errorMessage;
Utilities::FormatErrorMessage(error, errorMessage);
CString message;
message.AppendFormat(TEXT("Creation of directory failed with error %s on directory %s"),
errorMessage, destDir);
throw new CHoboCopyException(message);
}
}
else
{
CString message;
message.AppendFormat(TEXT("Created directory %s"), destDir);
OutputWriter::WriteLine(message, VERBOSITY_THRESHOLD_IF_VERBOSE);
}
Utilities::CreateDirectory(destDir);
CString message;
message.AppendFormat(TEXT("Created directory %s"), destDir);
OutputWriter::WriteLine(message, VERBOSITY_THRESHOLD_IF_VERBOSE);
}
void VisitFile(LPCTSTR path)
void VisitFile(LPCTSTR path)
{
CString sourceFile;
Utilities::CombinePath(_source, path, sourceFile);
View
@@ -115,7 +115,7 @@ class Utilities
BOOL bWorked = ::CreateDirectory(pathToCreate, NULL);
if (!bWorked)
{
{
DWORD error = ::GetLastError();
CString errorMessage;
FormatErrorMessage(error, errorMessage);
@@ -154,40 +154,6 @@ class Utilities
}
return false;
////HANDLE hDirectory = ::CreateFile(
//// directory,
//// 0,
//// FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
//// NULL,
//// OPEN_EXISTING,
//// FILE_ATTRIBUTE_NORMAL,
//// NULL);
//if (hDirectory == INVALID_HANDLE_VALUE)
//{
// DWORD error = ::GetLastError();
// if (error == 2)
// {
// return false;
// }
// else
// {
// CString errorMessage;
// Utilities::FormatErrorMessage(error, errorMessage);
// CString message;
// message.AppendFormat(TEXT("Unable to determine if directory %s exists. Error was %s."),
// directory, errorMessage);
// throw new CHoboCopyException(message);
// }
//}
//else
//{
// ::CloseHandle(hDirectory);
// return true;
//}
}
static bool EndsWith(LPCTSTR wsz, size_t maxLength, TCHAR wchar)

0 comments on commit 319dbd4

Please sign in to comment.