[misc] fix log potentially not being saved on exit

* Also ensures that if the user deleted the directory we don't recreate it for the log.
* Also fix typos and Coverity warnings.
This commit is contained in:
Pete Batard 2021-09-19 21:01:45 +01:00
parent 9dc045a701
commit deee38d4e5
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
5 changed files with 20 additions and 14 deletions

View file

@ -739,10 +739,12 @@ static BOOL ClearMBRGPT(HANDLE hPhysicalDrive, LONGLONG DiskSize, DWORD SectorSi
goto out;
CHECK_FOR_USER_CANCEL;
liFilePointer.QuadPart = DiskSize - (LONGLONG)SectorSize * MAX_SECTORS_TO_CLEAR;
SetFilePointerEx(hPhysicalDrive, liFilePointer, &liFilePointer, FILE_BEGIN);
// Windows seems to be an ass about keeping a lock on a backup GPT,
// so we try to be lenient about not being able to clear it.
WriteFileWithRetry(hPhysicalDrive, pZeroBuf, SectorSize * MAX_SECTORS_TO_CLEAR, NULL, WRITE_RETRIES);
if (SetFilePointerEx(hPhysicalDrive, liFilePointer, &liFilePointer, FILE_BEGIN)) {
IGNORE_RETVAL(WriteFileWithRetry(hPhysicalDrive, pZeroBuf,
SectorSize * MAX_SECTORS_TO_CLEAR, NULL, WRITE_RETRIES));
}
r = TRUE;
out: