Skip to content
This repository was archived by the owner on Aug 5, 2024. It is now read-only.

Commit f4fb71b

Browse files
mrkocotSpace Team
authored andcommitted
[fix] Correctly find symlink names even after folder renaming | #BAZEL-425 Done
Merge-request: BAZEL-MR-482 Merged-by: Marcin Kocot <[email protected]>
1 parent edcfd4b commit f4fb71b

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

server/src/main/java/org/jetbrains/bsp/bazel/server/sync/IntelliJProjectTreeViewFix.kt

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ import org.jetbrains.bsp.bazel.workspacecontext.WorkspaceContext
1010
import java.net.URI
1111
import java.nio.file.Files
1212
import java.nio.file.Paths
13-
import kotlin.io.path.Path
1413
import kotlin.io.path.name
1514
import kotlin.io.path.toPath
16-
import kotlin.io.path.listDirectoryEntries
17-
import kotlin.io.path.isSymbolicLink
18-
import kotlin.io.path.readSymbolicLink
1915

2016
class IntelliJProjectTreeViewFix(
2117
private val bazelPathsResolver: BazelPathsResolver,
@@ -58,28 +54,14 @@ class IntelliJProjectTreeViewFix(
5854

5955
private fun computeSymlinksToExclude(workspaceRoot: URI): Set<URI> {
6056
val stableSymlinkNames = setOf("bazel-out", "bazel-testlogs", "bazel-bin")
61-
val execRoot = Path(bazelInfo.execRoot)
62-
val execRootSymlinkNames = execRoot.name.let { name ->
63-
// newer bazel versions put workspace name as last component of exec root
64-
// still, the symlink to this directory is in form of bazel-<sanitized-workspace-name>
65-
// it seems to not accept '_' as a character, and it is replaced with '-'
66-
//
67-
// In older bazel versions, the exec root directory is named __main__ and I am using
68-
// less efficient heuristic: finding all bazel-* files that are symlinks that point to
69-
// exec root
70-
if (name != "__main__") {
71-
setOf("bazel-" + name.replace("[^A-Za-z0-9]".toRegex(), "-"))
72-
} else {
73-
workspaceRoot.toPath()
74-
.listDirectoryEntries("bazel-*")
75-
.filterNot { it.name in stableSymlinkNames }
76-
.filter { it.isSymbolicLink() && it.readSymbolicLink() == execRoot }
77-
.map { it.name }
78-
}
79-
}
80-
81-
return (stableSymlinkNames + execRootSymlinkNames).map {
82-
workspaceRoot.toPath().resolve(it).toUri()
57+
val workspaceRootPath = workspaceRoot.toPath()
58+
val sanitizedWorkspaceRootPath = workspaceRootPath
59+
.name
60+
.replace("[^A-Za-z0-9]".toRegex(), "-")
61+
val workspaceSymlinkNames = setOf("bazel-$sanitizedWorkspaceRootPath")
62+
63+
return (stableSymlinkNames + workspaceSymlinkNames).map {
64+
workspaceRootPath.resolve(it).toUri()
8365
}.toSet()
8466
}
8567

0 commit comments

Comments
 (0)