■ ■ ■ ■ ■ ■
src/main/java/io/onedev/k8shelper/KubernetesHelper.java
| skipped 69 lines |
70 | 70 | | |
71 | 71 | | public static final String WORKSPACE = "workspace"; |
72 | 72 | | |
73 | | - | public static final String HOME_PREFIX = "home:"; |
74 | | - | |
75 | 73 | | public static final String ATTRIBUTES = "attributes"; |
76 | 74 | | |
77 | 75 | | public static final String PLACEHOLDER_PREFIX = "<&onedev#"; |
| skipped 385 lines |
463 | 461 | | |
464 | 462 | | for (Map.Entry<CacheInstance, String> entry: cacheAllocations.entrySet()) { |
465 | 463 | | if (!PathUtils.isCurrent(entry.getValue())) { |
466 | | - | for (String link: resolveCachePath(workspace.getAbsolutePath(), entry.getValue())) { |
467 | | - | File linkTarget = entry.getKey().getDirectory(cacheHome); |
468 | | - | // create possible missing parent directories |
469 | | - | if (isWindows()) { |
470 | | - | setupCommands.add(String.format("echo Setting up cache \"%s\"...", link)); |
471 | | - | setupCommands.add(String.format("if not exist \"%s\" mkdir \"%s\"", link, link)); |
472 | | - | setupCommands.add(String.format("rmdir /q /s \"%s\"", link)); |
473 | | - | setupCommands.add(String.format("mklink /D \"%s\" \"%s\"", link, linkTarget.getAbsolutePath())); |
474 | | - | } else { |
475 | | - | setupCommands.add(String.format("echo Setting up cache \"%s\"...", link)); |
476 | | - | setupCommands.add(String.format("mkdir -p \"%s\"", link)); |
477 | | - | setupCommands.add(String.format("rm -rf \"%s\"", link)); |
478 | | - | setupCommands.add(String.format("ln -s \"%s\" \"%s\"", linkTarget.getAbsolutePath(), link)); |
479 | | - | } |
| 464 | + | String link = PathUtils.resolve(workspace.getAbsolutePath(), entry.getValue()); |
| 465 | + | File linkTarget = entry.getKey().getDirectory(cacheHome); |
| 466 | + | // create possible missing parent directories |
| 467 | + | if (isWindows()) { |
| 468 | + | setupCommands.add(String.format("echo Setting up cache \"%s\"...", link)); |
| 469 | + | setupCommands.add(String.format("if not exist \"%s\" mkdir \"%s\"", link, link)); |
| 470 | + | setupCommands.add(String.format("rmdir /q /s \"%s\"", link)); |
| 471 | + | setupCommands.add(String.format("mklink /D \"%s\" \"%s\"", link, linkTarget.getAbsolutePath())); |
| 472 | + | } else { |
| 473 | + | setupCommands.add(String.format("echo Setting up cache \"%s\"...", link)); |
| 474 | + | setupCommands.add(String.format("mkdir -p \"%s\"", link)); |
| 475 | + | setupCommands.add(String.format("rm -rf \"%s\"", link)); |
| 476 | + | setupCommands.add(String.format("ln -s \"%s\" \"%s\"", linkTarget.getAbsolutePath(), link)); |
480 | 477 | | } |
481 | 478 | | } |
482 | 479 | | } |
| skipped 565 lines |
1048 | 1045 | | } |
1049 | 1046 | | matcher.appendTail(buffer); |
1050 | 1047 | | return buffer.toString(); |
1051 | | - | } |
1052 | | - | |
1053 | | - | public static String[] resolveCachePath(String basePath, String cachePath) { |
1054 | | - | if (cachePath.startsWith(HOME_PREFIX)) { |
1055 | | - | cachePath = cachePath.substring(HOME_PREFIX.length()); |
1056 | | - | if (SystemUtils.IS_OS_WINDOWS) { |
1057 | | - | cachePath = cachePath.replace('/', '\\'); |
1058 | | - | if (cachePath.startsWith("\\")) |
1059 | | - | cachePath = cachePath.substring(1); |
1060 | | - | return new String[] { |
1061 | | - | "C:\\Users\\ContainerAdministrator\\" + cachePath, |
1062 | | - | "C:\\Users\\ContainerUser\\" + cachePath |
1063 | | - | }; |
1064 | | - | } else { |
1065 | | - | cachePath = cachePath.replace('\\', '/'); |
1066 | | - | if (cachePath.startsWith("/")) |
1067 | | - | cachePath = cachePath.substring(1); |
1068 | | - | return new String[] {"/root/" + cachePath}; |
1069 | | - | } |
1070 | | - | } else { |
1071 | | - | return new String[] {PathUtils.resolve(basePath, cachePath)}; |
1072 | | - | } |
1073 | 1048 | | } |
1074 | 1049 | | |
1075 | 1050 | | public static String replacePlaceholders(String string, File buildHome) { |
| skipped 22 lines |