Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions src/hotspot/os/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4680,13 +4680,13 @@ static bool is_symbolic_link(const wchar_t* wide_path) {
if (f != INVALID_HANDLE_VALUE) {
const bool result = fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT && fd.dwReserved0 == IO_REPARSE_TAG_SYMLINK;
if (::FindClose(f) == 0) {
errno = ::GetLastError();
log_debug(os)("is_symbolic_link() failed to FindClose: GetLastError->%ld.", errno);
DWORD errcode = ::GetLastError();
log_debug(os)("is_symbolic_link() failed to FindClose: GetLastError->%lu.", errcode);
}
return result;
} else {
errno = ::GetLastError();
log_debug(os)("is_symbolic_link() failed to FindFirstFileW: GetLastError->%ld.", errno);
DWORD errcode = ::GetLastError();
log_debug(os)("is_symbolic_link() failed to FindFirstFileW: GetLastError->%lu.", errcode);
return false;
}
}
Expand All @@ -4696,17 +4696,17 @@ static WCHAR* get_path_to_target(const wchar_t* wide_path) {
HANDLE hFile = CreateFileW(wide_path, GENERIC_READ, FILE_SHARE_READ, nullptr,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if (hFile == INVALID_HANDLE_VALUE) {
errno = ::GetLastError();
log_debug(os)("get_path_to_target() failed to CreateFileW: GetLastError->%ld.", errno);
DWORD errcode = ::GetLastError();
log_debug(os)("get_path_to_target() failed to CreateFileW: GetLastError->%lu.", errcode);
return nullptr;
}

// Returned value includes the terminating null character.
const size_t target_path_size = ::GetFinalPathNameByHandleW(hFile, nullptr, 0,
FILE_NAME_NORMALIZED);
if (target_path_size == 0) {
errno = ::GetLastError();
log_debug(os)("get_path_to_target() failed to GetFinalPathNameByHandleW: GetLastError->%ld.", errno);
DWORD errcode = ::GetLastError();
log_debug(os)("get_path_to_target() failed to GetFinalPathNameByHandleW: GetLastError->%lu.", errcode);
return nullptr;
}

Expand All @@ -4716,14 +4716,14 @@ static WCHAR* get_path_to_target(const wchar_t* wide_path) {
const size_t res = ::GetFinalPathNameByHandleW(hFile, path_to_target, static_cast<DWORD>(target_path_size),
FILE_NAME_NORMALIZED);
if (res != target_path_size - 1) {
errno = ::GetLastError();
log_debug(os)("get_path_to_target() failed to GetFinalPathNameByHandleW: GetLastError->%ld.", errno);
DWORD errcode = ::GetLastError();
log_debug(os)("get_path_to_target() failed to GetFinalPathNameByHandleW: GetLastError->%lu.", errcode);
return nullptr;
}

if (::CloseHandle(hFile) == 0) {
errno = ::GetLastError();
log_debug(os)("get_path_to_target() failed to CloseHandle: GetLastError->%ld.", errno);
DWORD errcode = ::GetLastError();
log_debug(os)("get_path_to_target() failed to CloseHandle: GetLastError->%lu.", errcode);
return nullptr;
}

Expand Down Expand Up @@ -4804,9 +4804,8 @@ int os::stat(const char *path, struct stat *sbuf) {
if (is_symlink) {
path_to_target = get_path_to_target(wide_path);
if (path_to_target == nullptr) {
// it is a symbolic link, but we failed to resolve it,
// errno has been set in the call to get_path_to_target(),
// no need to overwrite it
// it is a symbolic link, but we failed to resolve it
errno = ENOENT;
os::free(wide_path);
return -1;
}
Expand All @@ -4817,8 +4816,11 @@ int os::stat(const char *path, struct stat *sbuf) {

// if getting attributes failed, GetLastError should be called immediately after that
if (!bret) {
errno = ::GetLastError();
log_debug(os)("os::stat() failed to GetFileAttributesExW: GetLastError->%ld.", errno);
DWORD errcode = ::GetLastError();
if (errcode == ERROR_FILE_NOT_FOUND || errcode == ERROR_PATH_NOT_FOUND) {
errno = ENOENT;
}
log_debug(os)("os::stat() failed to GetFileAttributesExW: GetLastError->%lu.", errcode);
os::free(wide_path);
os::free(path_to_target);
return -1;
Expand Down Expand Up @@ -5018,20 +5020,18 @@ int os::open(const char *path, int oflag, int mode) {
if (is_symlink) {
path_to_target = get_path_to_target(wide_path);
if (path_to_target == nullptr) {
// it is a symbolic link, but we failed to resolve it,
// errno has been set in the call to get_path_to_target(),
// no need to overwrite it
// it is a symbolic link, but we failed to resolve it
errno = ENOENT;
os::free(wide_path);
return -1;
}
}

int fd = ::_wopen(is_symlink ? path_to_target : wide_path, oflag | O_BINARY | O_NOINHERIT, mode);

// if opening files failed, GetLastError should be called immediately after that
// if opening files failed, errno has been set to indicate the problem
if (fd == -1) {
errno = ::GetLastError();
log_debug(os)("os::open() failed to _wopen: GetLastError->%ld.", errno);
log_debug(os)("os::open() failed to _wopen: errno->%ld.", errno);
}
os::free(wide_path);
os::free(path_to_target);
Expand Down Expand Up @@ -5099,7 +5099,8 @@ bool os::dir_is_empty(const char* path) {
}
FindClose(f);
} else {
errno = ::GetLastError();
DWORD errcode = ::GetLastError();
log_debug(os)("os::dir_is_empty() failed to FindFirstFileW: GetLastError->%lu.", errcode);
}

return is_empty;
Expand Down
6 changes: 0 additions & 6 deletions src/hotspot/share/cds/aotClassLocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,6 @@ AOTClassLocation* AOTClassLocation::allocate(JavaThread* current, const char* pa
// The timestamp of $JAVA_HOME/lib/modules is not checked at runtime.
check_time = !is_jrt;
}
#ifdef _WINDOWS
} else if (errno == ERROR_FILE_NOT_FOUND || errno == ERROR_PATH_NOT_FOUND) {
// On Windows, the errno could be ERROR_PATH_NOT_FOUND (3) in case the directory
// path doesn't exist.
type = FileType::NOT_EXIST;
#endif
} else if (errno == ENOENT) {
// We allow the file to not exist, as long as it also doesn't exist during runtime.
type = FileType::NOT_EXIST;
Expand Down