void ReportError(int err, LPCSTR szContext, LPCTSTR pszPath) { BPRINT_BUFFER & bp = *g_pbpErr; bprint_EndLine(bp); bprint(bp, szContext); if (pszPath) { bprint_Sep(bp, ' '); bprint(bp, pszPath); } bprint_Sep(bp, ' '); bprint(bp, TEXT("Failed : ")); bprint_AppendErrorText(bp, err); bprint_EndLine(bp); }
static int WINAPI DpdDeleteFile ( LPCWSTR pszPath, int ochName, DeletePathData & dpd, DWORD fdwVerbose, DWORD fdwFlags) { int err = 0; if (dpd.fNoDelete) { if (fdwVerbose) bprintf(*dpd.pbp, TEXT("NoDelete %s "), pszPath); return 0; } if (fdwVerbose) bprintf(*dpd.pbp, TEXT("Deleting %s "), pszPath); if (DeleteFileW(pszPath)) { dpd.cFilesDeleted += 1; } else { err = GetLastError(); if ((ERROR_ACCESS_DENIED == err) && (fdwFlags & DPD_F_REMOVEDACLS)) { if ( ! dpd.fDirAlreadyTriedDACLRemove && (ochName > 1)) { LPWSTR pszParent = strdupW(pszPath); pszParent[ochName-1] = 0; //StrCopyN(szParent, NUMCHARS(szParent), pszPath, ochName); int errT = RemoveFileDACLs(pszParent, dpd.fDiagnostic, dpd.pbp); if (errT) err = errT; else if (DeleteFileW(pszPath)) { err = 0; dpd.cFilesDeleted += 1; } else { err = GetLastError(); } // dont try to remove dacls again for this directory. dpd.fDirAlreadyTriedDACLRemove = true; free(pszParent); } // the error _may_ have been cleared by the time we get here, if it hasn't // then try and remove dacls from the file, then try again to delete the file. // if (ERROR_ACCESS_DENIED == err) { int errT = RemoveFileDACLs(pszPath, dpd.fDiagnostic, dpd.pbp); if (errT) err = errT; else if (DeleteFileW(pszPath)) { err = 0; dpd.cFilesDeleted += 1; } else { err = GetLastError(); } } } if (err) { dpd.cDeleteFailures += 1; if (fdwVerbose) { bprint_Sep(*dpd.pbp, ' '); bprint_AppendErrorText(*dpd.pbp, err); } } } return err; }
static int WINAPI DpdRemoveDirectory ( LPCTSTR pszPath, int ochName, DeletePathData & dpd, DWORD fdwVerbose, DWORD fdwFlags) { int err = 0; if (dpd.fNoDelete) { if (fdwVerbose) bprintf(*dpd.pbp, TEXT("NoRemove %s "), pszPath); return 0; } if (fdwVerbose) bprintf(*dpd.pbp, TEXT("Removing %s "), pszPath); if (RemoveDirectory(pszPath)) { dpd.cDirsRemoved += 1; } else { err = GetLastError(); if ((ERROR_ACCESS_DENIED == err) && (fdwFlags & DPD_F_REMOVEDACLS)) { if ( ! dpd.fDirAlreadyTriedDACLRemove && (ochName > 1)) { TCHAR szParent[MAX_PATH]; StrCopyN(szParent, NUMCHARS(szParent), pszPath, ochName); int errT = RemoveFileDACLs(szParent, fdwVerbose & (TDT_DIAGNOSTIC | TDT_USER_F_VERBOSE), dpd.pbp); if (errT) err = errT; else if (RemoveDirectory(pszPath)) { err = 0; dpd.cDirsRemoved += 1; } else { err = GetLastError(); } // dont try to remove dacls again for this directory. dpd.fDirAlreadyTriedDACLRemove = true; } // the error _may_ have been cleared by the time we get here, if it hasn't // then try and remove dacls from the file, then try again to delete the file. // if (ERROR_ACCESS_DENIED == err) { int errT = RemoveFileDACLs(pszPath, fdwVerbose & (TDT_DIAGNOSTIC | TDT_USER_F_VERBOSE), dpd.pbp); if (errT) err = errT; else if (RemoveDirectory(pszPath)) { err = 0; dpd.cDirsRemoved += 1; } else { err = GetLastError(); } } } if (err) { dpd.cRemoveFailures += 1; if (fdwVerbose) { bprint_Sep(*dpd.pbp, ' '); bprint_AppendErrorText(*dpd.pbp, err); } } } return err; }