Refactoring
This commit is contained in:
@@ -198,9 +198,23 @@ private:
|
||||
|
||||
inline static CSiaFileTreePtr GetFileTree()
|
||||
{
|
||||
auto ret = _siaFileTree;
|
||||
return ret;
|
||||
return _siaFileTree;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void SetCachedFileTime(const SString& filePath, T* fd)
|
||||
{
|
||||
WIN32_FIND_DATA find = { 0 };
|
||||
HANDLE findHandle = ::FindFirstFile(&filePath[0], &find);
|
||||
if (findHandle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
fd->ftCreationTime = find.ftCreationTime;
|
||||
fd->ftLastAccessTime = find.ftLastAccessTime;
|
||||
fd->ftLastWriteTime = find.ftLastWriteTime;
|
||||
|
||||
::FindClose(findHandle);
|
||||
}
|
||||
}
|
||||
|
||||
static bool AddFileToCache(OpenFileInfo& openFileInfo, PDOKAN_FILE_INFO dokanFileInfo)
|
||||
{
|
||||
@@ -279,7 +293,7 @@ private:
|
||||
// TODO Handle error return
|
||||
// Retrieve the file times for the file.
|
||||
FILETIME fileTimes[3];
|
||||
if (GetFileTime(openFileInfo.FileHandle, &fileTimes[0], &fileTimes[1], &fileTimes[2]))
|
||||
if (::GetFileTime(openFileInfo.FileHandle, &fileTimes[0], &fileTimes[1], &fileTimes[2]))
|
||||
{
|
||||
::CloseHandle(openFileInfo.FileHandle);
|
||||
_uploadManager->AddOrUpdate(openFileInfo.SiaPath, openFileInfo.CacheFilePath, *reinterpret_cast<std::uint64_t*>(&fileTimes[2]));
|
||||
@@ -400,18 +414,17 @@ private:
|
||||
{
|
||||
if (!cacheFilePath.CreateDirectory())
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
}
|
||||
else if (creationDisposition == OPEN_ALWAYS)
|
||||
{
|
||||
if (!cacheFilePath.CreateDirectory())
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
DWORD error = ::GetLastError();
|
||||
if (error != ERROR_ALREADY_EXISTS)
|
||||
{
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -431,8 +444,7 @@ private:
|
||||
HANDLE handle = ::CreateFile(&cacheFilePath[0], genericDesiredAccess, shareAccess, &securityAttrib, OPEN_EXISTING, fileAttributesAndFlags | FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_POSIX_SEMANTICS, nullptr);
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -544,7 +556,7 @@ private:
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = DokanNtStatusFromWin32(GetLastError());
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,13 +597,13 @@ private:
|
||||
nullptr);
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
ret = DokanNtStatusFromWin32(GetLastError());
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((creationDisposition == OPEN_ALWAYS) || (creationDisposition == CREATE_ALWAYS))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
DWORD error = ::GetLastError();
|
||||
if (error == ERROR_ALREADY_EXISTS)
|
||||
{
|
||||
ret = STATUS_OBJECT_NAME_COLLISION;
|
||||
@@ -668,8 +680,7 @@ private:
|
||||
HANDLE findHandle = ::FindFirstFile(&findFile[0], &findData);
|
||||
if (findHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -703,7 +714,7 @@ private:
|
||||
}
|
||||
} while (::FindNextFile(findHandle, &findData) != 0);
|
||||
|
||||
DWORD error = GetLastError();
|
||||
DWORD error = ::GetLastError();
|
||||
::FindClose(findHandle);
|
||||
|
||||
if (error == ERROR_NO_MORE_FILES)
|
||||
@@ -746,7 +757,7 @@ private:
|
||||
li.QuadPart = file->GetFileSize();
|
||||
fd.nFileSizeHigh = li.HighPart;
|
||||
fd.nFileSizeLow = li.LowPart;
|
||||
fd.dwFileAttributes = FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_NORMAL;
|
||||
SetCachedFileTime(FilePath(GetCacheLocation(), file->GetSiaPath()), &fd);
|
||||
fillFindData(&fd, dokanFileInfo);
|
||||
}
|
||||
}
|
||||
@@ -755,7 +766,7 @@ private:
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -802,7 +813,7 @@ private:
|
||||
SString cachFileLocation = openFileInfo ? openFileInfo->CacheFilePath : FilePath(GetCacheLocation(), fileName);
|
||||
|
||||
HANDLE tempHandle = openFileInfo ? openFileInfo->FileHandle : nullptr;
|
||||
if (!siaFile && (!tempHandle || (tempHandle == INVALID_HANDLE_VALUE)))
|
||||
if (FilePath(cachFileLocation).IsFile() && (!tempHandle || (tempHandle == INVALID_HANDLE_VALUE)))
|
||||
{
|
||||
tempHandle = ::CreateFile(&cachFileLocation[0], GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
|
||||
if (tempHandle == INVALID_HANDLE_VALUE)
|
||||
@@ -821,9 +832,11 @@ private:
|
||||
{
|
||||
LARGE_INTEGER li = { 0 };
|
||||
li.QuadPart = siaFile->GetFileSize();
|
||||
GetFileInformationByHandle(tempHandle, handleFileInfo);
|
||||
handleFileInfo->dwFileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE;
|
||||
handleFileInfo->nFileSizeHigh = li.HighPart;
|
||||
handleFileInfo->nFileSizeLow = li.LowPart;
|
||||
SetCachedFileTime(cachFileLocation, handleFileInfo);
|
||||
}
|
||||
else if (!::GetFileInformationByHandle(tempHandle, handleFileInfo))
|
||||
{
|
||||
@@ -839,8 +852,7 @@ private:
|
||||
HANDLE findHandle = ::FindFirstFile(&cachFileLocation[0], &find);
|
||||
if (findHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD error = ::GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -961,8 +973,7 @@ private:
|
||||
tempHandle = ::CreateFile(&filePath[0], GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
|
||||
if (tempHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -977,13 +988,11 @@ private:
|
||||
distanceToMove.QuadPart = offset;
|
||||
if (!::SetFilePointerEx(tempHandle, distanceToMove, nullptr, FILE_BEGIN))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
else if (!::ReadFile(tempHandle, buffer, bufferLen, readLength, nullptr))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1033,8 +1042,7 @@ private:
|
||||
tempHandle = ::CreateFile(&filePath[0], GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr);
|
||||
if (tempHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1048,8 +1056,7 @@ private:
|
||||
{
|
||||
if (!::GetFileSizeEx(tempHandle, &li))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1059,8 +1066,7 @@ private:
|
||||
LARGE_INTEGER z = { 0 };
|
||||
if (!::SetFilePointerEx(tempHandle, z, nullptr, FILE_END))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1105,8 +1111,7 @@ private:
|
||||
distanceToMove.QuadPart = offset;
|
||||
if (!::SetFilePointerEx(tempHandle, distanceToMove, nullptr, FILE_BEGIN))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1121,8 +1126,7 @@ private:
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1178,13 +1182,11 @@ private:
|
||||
offset.QuadPart = byteOffset;
|
||||
if (!::SetFilePointerEx(openFileInfo->FileHandle, offset, nullptr, FILE_BEGIN))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
else if (!::SetEndOfFile(openFileInfo->FileHandle))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
|
||||
if (ret == STATUS_SUCCESS)
|
||||
@@ -1257,8 +1259,7 @@ private:
|
||||
{
|
||||
if (!::FlushFileBuffers(openFileInfo->FileHandle))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1278,8 +1279,7 @@ private:
|
||||
HANDLE findHandle = ::FindFirstFile(&filePath[0], &findData);
|
||||
if (findHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1293,7 +1293,7 @@ private:
|
||||
while ((ret == STATUS_SUCCESS) && (::FindNextFile(findHandle, &findData) != 0));
|
||||
if (ret != STATUS_DIRECTORY_NOT_EMPTY)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
DWORD error = ::GetLastError();
|
||||
if (error != ERROR_NO_MORE_FILES)
|
||||
{
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
@@ -1326,7 +1326,7 @@ private:
|
||||
fdi.DeleteFile = dokanFileInfo->DeleteOnClose;
|
||||
if (!::SetFileInformationByHandle(openFileInfo->FileHandle, FileDispositionInfo, &fdi, sizeof(FILE_DISPOSITION_INFO)))
|
||||
{
|
||||
ret = DokanNtStatusFromWin32(GetLastError());
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1374,8 +1374,7 @@ private:
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1397,8 +1396,7 @@ private:
|
||||
|
||||
if (!::SetFileAttributes(&filePath[0], fileAttributes))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanSetFileAttributesW(filePath, ret)));
|
||||
@@ -1415,6 +1413,7 @@ private:
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanGetFileAttributesW(filePath)));
|
||||
SECURITY_INFORMATION requestingSaclInfo = ((*securityInfo & SACL_SECURITY_INFORMATION) || (*securityInfo & BACKUP_SECURITY_INFORMATION));
|
||||
|
||||
// TODO Implement this properly
|
||||
//if (!g_HasSeSecurityPrivilege) {
|
||||
if (true)
|
||||
{
|
||||
@@ -1431,8 +1430,7 @@ private:
|
||||
|
||||
if (!handle || (handle == INVALID_HANDLE_VALUE))
|
||||
{
|
||||
int error = ::GetLastError();
|
||||
return DokanNtStatusFromWin32(error);
|
||||
return DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
|
||||
if (!::GetUserObjectSecurity(handle, securityInfo, securityDescriptor, bufferLen, lengthNeeded))
|
||||
@@ -1446,7 +1444,7 @@ private:
|
||||
else
|
||||
{
|
||||
::CloseHandle(handle);
|
||||
return DokanNtStatusFromWin32(error);
|
||||
return DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
}
|
||||
::CloseHandle(handle);
|
||||
@@ -1473,8 +1471,7 @@ private:
|
||||
|
||||
if (!::SetUserObjectSecurity(openFileInfo->FileHandle, securityInfo, securityDescriptor))
|
||||
{
|
||||
int error = ::GetLastError();
|
||||
return DokanNtStatusFromWin32(error);
|
||||
return DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
@@ -1494,8 +1491,7 @@ private:
|
||||
}
|
||||
else if (!::SetFileTime(openFileInfo->FileHandle, creationTime, lastAccessTime, lastWriteTime))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanSetFileTime(filePath, ret)));
|
||||
@@ -1523,20 +1519,17 @@ private:
|
||||
fileSize.QuadPart = allocSize;
|
||||
if (!::SetFilePointerEx(openFileInfo->FileHandle, fileSize, nullptr, FILE_BEGIN))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
else if (!::SetEndOfFile(openFileInfo->FileHandle))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
ret = DokanNtStatusFromWin32(::GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user