Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.0.0] Partial fix for bug with creating a junction to file instead of symlink #24058

Merged
merged 1 commit into from
Oct 25, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ protected void createSymbolicLink(PathFragment linkPath, PathFragment targetFrag
try {
java.nio.file.Path link = getIoFile(linkPath).toPath();
java.nio.file.Path target = getIoFile(targetPath).toPath();
// Still Create a dangling junction if the target doesn't exist.
if (!target.toFile().exists() || target.toFile().isDirectory()) {
if (target.toFile().isDirectory()) {
WindowsFileOperations.createJunction(link.toString(), target.toString());
} else if (createSymbolicLinks) {
WindowsFileOperations.createSymlink(link.toString(), target.toString());
} else if (!target.toFile().exists()) {
// Still Create a dangling junction if the target doesn't exist.
WindowsFileOperations.createJunction(link.toString(), target.toString());
} else {
if (createSymbolicLinks) {
WindowsFileOperations.createSymlink(link.toString(), target.toString());
} else {
Files.copy(target, link);
}
Files.copy(target, link);
}
} catch (java.nio.file.FileAlreadyExistsException e) {
throw new IOException(linkPath + ERR_FILE_EXISTS, e);
Expand Down
3 changes: 2 additions & 1 deletion src/main/native/windows/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,8 @@ int CreateSymlink(const wstring& symlink_name, const wstring& symlink_target,
const wstring target = AddUncPrefixMaybe(symlink_target);

DWORD attrs = GetFileAttributesW(target.c_str());
if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
if ((attrs != INVALID_FILE_ATTRIBUTES) &&
(attrs & FILE_ATTRIBUTE_DIRECTORY)) {
// Instead of creating a symlink to a directory use a Junction.
return CreateSymlinkResult::kTargetIsDirectory;
}
Expand Down
Loading