Skip to content

Commit

Permalink
fix: do not clean up old launch directory if current and old links ar…
Browse files Browse the repository at this point in the history
…e the same files (#1440)
  • Loading branch information
junfuchen99 authored and MikeDombo committed Apr 20, 2023
1 parent 2a69115 commit dcb6f5d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,15 @@ public Deployment.DeploymentStage determineDeploymentStage(BootstrapManager boot
* @throws IOException if file or directory changes fail
*/
public void activationSucceeds() throws IOException {
Path launchDirToCleanUp = Files.readSymbolicLink(getOldDir());
Path launchDirToCleanUp = Files.readSymbolicLink(getOldDir()).toAbsolutePath();
Files.delete(getOldDir());
if (Files.isSameFile(launchDirToCleanUp, getCurrentDir())) {
logger.atInfo().kv("oldDir", launchDirToCleanUp).log("Skipping launch directory cleanup after kernel "
+ "update due to matching directory names. Likely the same deployment was executed twice on the "
+ "device");
return;
}
logger.atDebug().kv("oldDir", launchDirToCleanUp).log("Cleaning up previous kernel launch directory");
cleanupLaunchDirectorySingleLevel(launchDirToCleanUp.toFile());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ void GIVEN_kernel_update_WHEN_success_THEN_launch_dir_update_correctly() throws
assertThat(initPath.toFile(), not(anExistingFileOrDirectory()));
}

@Test
void GIVEN_kernel_update_with_same_deployment_id_WHEN_success_THEN_launch_dir_update_correctly() throws Exception {
// testing the scenario when the existing launch dir and the new launch dir are constructed from the same
// deployment id
String mockDeploymentId = "mockDeployment";
Path launchPath = altsDir.resolve(mockDeploymentId);
Files.createDirectories(launchPath);
kernelAlternatives.setupLinkToDirectory(kernelAlternatives.getCurrentDir(), launchPath);

kernelAlternatives.prepareBootstrap(mockDeploymentId);
assertEquals(launchPath, Files.readSymbolicLink(kernelAlternatives.getCurrentDir()));
assertEquals(launchPath, Files.readSymbolicLink(kernelAlternatives.getOldDir()));

kernelAlternatives.activationSucceeds();
assertThat(kernelAlternatives.getOldDir().toFile(), not(anExistingFileOrDirectory()));
assertThat(launchPath.toFile(), anExistingFileOrDirectory());
}

@Test
void GIVEN_initDirPointingWrongLocation_WHEN_redirectInitDir_THEN_dirIsRedirectedCorrectly() throws Exception {
Path outsidePath = createRandomDirectory();
Expand Down

0 comments on commit dcb6f5d

Please sign in to comment.