--- old/src/hotspot/os/windows/os_windows.cpp 2017-12-19 16:04:55.611348279 -0800 +++ new/src/hotspot/os/windows/os_windows.cpp 2017-12-19 16:04:55.213310839 -0800 @@ -4394,13 +4394,51 @@ // Is a (classpath) directory empty? bool os::dir_is_empty(const char* path) { - WIN32_FIND_DATA fd; - HANDLE f = FindFirstFile(path, &fd); + bool is_empty = false; + char* search_path = (char*)os::malloc(strlen(path) + 3, mtInternal); + if (search_path == NULL) { + errno = ENOMEM; + return false; + } + strcpy(search_path, path); + // Append "*", or possibly "\\*", to path + if (path[1] == ':' && + (path[2] == '\0' || + (path[2] == '\\' && path[3] == '\0'))) { + // No '\\' needed for cases like "Z:" or "Z:\" + strcat(search_path, "*"); + } + else { + strcat(search_path, "\\*"); + } + errno_t err = ERROR_SUCCESS; + wchar_t* wpath = create_unc_path(search_path, err); + if (err != ERROR_SUCCESS) { + if (wpath != NULL) { + destroy_unc_path(wpath); + } + os::free(search_path); + errno = err; + return false; + } + WIN32_FIND_DATAW fd; + HANDLE f = FindFirstFileW(wpath, &fd); + destroy_unc_path(wpath); if (f == INVALID_HANDLE_VALUE) { - return true; + is_empty = true; + } else { + int num_files = 0; + do { + num_files++; + } while (FindNextFileW(f, &fd)); + // An empty directory contains only the current directory file + // and the previous directory file. + is_empty = ((wcscmp(fd.cFileName, L".") == 0) || + (wcscmp(fd.cFileName, L"..") == 0)) && (num_files == 2); + FindClose(f); } - FindClose(f); - return false; + free(search_path); + return is_empty; } // create binary file, rewriting existing file if required