Skip to content

Commit 84d36b8

Browse files
committed
Reinstall server-everything when its cached copy was pruned
If the install directory exists but lacks the server, e.g. after the OS cleaned up the temporary directory, delete it and install again instead of failing on every run. Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
1 parent 444f70a commit 84d36b8

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

‎mcp-test/src/test/java/io/modelcontextprotocol/client/ServerParameterUtils.java‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,18 @@ private static void install(Path tmpDir, Path installDir) {
8787
run(npmCommand("install", "--prefix", staging.toString(), "--no-save", "--no-audit", "--no-fund",
8888
"--loglevel=error", "@modelcontextprotocol/server-everything@" + SERVER_EVERYTHING_VERSION));
8989
try {
90-
Files.move(staging, installDir, StandardCopyOption.ATOMIC_MOVE);
90+
moveIntoPlace(staging, installDir);
9191
}
9292
catch (IOException e) {
93-
// Another build won the race and installed it first, which is fine as
94-
// long as the result is usable.
95-
if (!Files.isRegularFile(serverScriptIn(installDir))) {
96-
throw new UncheckedIOException("Failed to install server-everything to " + installDir, e);
93+
// The directory exists but lacks the server, e.g. after the OS pruned
94+
// the temporary directory: replace it instead of failing on every run.
95+
deleteRecursively(installDir);
96+
try {
97+
moveIntoPlace(staging, installDir);
98+
}
99+
catch (IOException retryFailure) {
100+
throw new UncheckedIOException("Failed to install server-everything to " + installDir,
101+
retryFailure);
97102
}
98103
}
99104
}
@@ -102,6 +107,19 @@ private static void install(Path tmpDir, Path installDir) {
102107
}
103108
}
104109

110+
private static void moveIntoPlace(Path staging, Path installDir) throws IOException {
111+
try {
112+
Files.move(staging, installDir, StandardCopyOption.ATOMIC_MOVE);
113+
}
114+
catch (IOException e) {
115+
// Another build won the race and installed it first, which is fine as long
116+
// as the result is usable.
117+
if (!Files.isRegularFile(serverScriptIn(installDir))) {
118+
throw e;
119+
}
120+
}
121+
}
122+
105123
private static void deleteRecursively(Path path) {
106124
if (!Files.exists(path)) {
107125
return;

0 commit comments

Comments
 (0)