This is an automated email from the ASF dual-hosted git repository. skygo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans-native-installers.git
commit 0b5c1520ba6cb64a1f53d82936fa64353dc8401b Author: Lars Bruun-Hansen <lbr...@apache.org> AuthorDate: Sat Sep 14 22:39:31 2019 +0200 [NETBEANS-3094] NBI cleaner process must attempt to delete read-only files too. - Attempt to remove read-only attrib on a file/folder before attempting to delete it. - Also added braces on existing statements to make the code more readable. --- cleaner/windows/src/main.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/cleaner/windows/src/main.c b/cleaner/windows/src/main.c index 74f0850..43271ff 100644 --- a/cleaner/windows/src/main.c +++ b/cleaner/windows/src/main.c @@ -257,6 +257,7 @@ void readStringList(HANDLE fileHandle, WCHAR *** list, DWORD *number) { } void deleteFile(WCHAR * filePath) { + BOOL canDelete = TRUE; DWORD count = 0 ; WIN32_FILE_ATTRIBUTE_DATA attrs; DWORD filePathLength = lstrlenW(filePath); @@ -271,15 +272,30 @@ void deleteFile(WCHAR * filePath) { file[i+prefixLength] = filePath[i]; } + // Implementation note: + // GetFileAttributesExW() is used not only to get file attributes + // but also as a way to check if the file/dir (still) exist. + if(GetFileAttributesExW(file, GetFileExInfoStandard, &attrs)) { - if(attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - while((!RemoveDirectoryW(file) || GetFileAttributesExW(file, GetFileExInfoStandard, &attrs)) && - ((count++) < MAX_ATTEMPTS)) - Sleep(SLEEP_DELAY); - else - while((!DeleteFileW(file) || GetFileAttributesExW(file, GetFileExInfoStandard, &attrs)) && - ((count++) < MAX_ATTEMPTS)) - Sleep(SLEEP_DELAY); + if (attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY) { // if read-only attrib is set + if (SetFileAttributesW(file, FILE_ATTRIBUTE_NORMAL) == 0) { // remove read-only attrib + // The read-only attrib could not be deleted. No point in continuing. + canDelete = FALSE; + } + } + if (canDelete) { + if (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + while ((!RemoveDirectoryW(file) || GetFileAttributesExW(file, GetFileExInfoStandard, &attrs)) && + ((count++) < MAX_ATTEMPTS)) { + Sleep(SLEEP_DELAY); + } + } else { + while ((!DeleteFileW(file) || GetFileAttributesExW(file, GetFileExInfoStandard, &attrs)) && + ((count++) < MAX_ATTEMPTS)) { + Sleep(SLEEP_DELAY); + } + } + } } LocalFree(file); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists