private static final long CLEAN_MAX_AGE = TimeUnit.DAYS.toMillis(21);
static final String TMP_NAME_PREFIX = ".sonartmp_";
private boolean started = false;
-
+
private System2 system;
private DefaultTempFolder tempFolder;
Path home = findSonarHome(bootstrapProps);
workingPath = home.resolve(workingPath).normalize();
}
-
try {
cleanTempFolders(workingPath);
} catch (IOException e) {
private static Path createTempFolder(Path workingPath) {
try {
- Files.createDirectories(workingPath);
+ Path realPath = workingPath;
+ if (Files.isSymbolicLink(realPath)) {
+ realPath = realPath.toRealPath();
+ }
+ Files.createDirectories(realPath);
} catch (IOException e) {
throw new IllegalStateException("Failed to create working path: " + workingPath, e);
}
@Override
public void dispose(PicoContainer container) {
- //nothing to do
+ // nothing to do
}
@Override
@Test
public void createTempFolderProps() throws Exception {
File workingDir = temp.newFolder();
+ workingDir.delete();
TempFolder tempFolder = tempFolderProvider.provide(new GlobalProperties(ImmutableMap.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, workingDir.getAbsolutePath())));
tempFolder.newDir();
assertThat(newFile.getParentFile().getName()).startsWith(".sonartmp_");
}
+ @Test
+ public void homeIsSymbolicLink() throws IOException {
+ File realSonarHome = temp.newFolder();
+ File symlink = temp.newFolder();
+ symlink.delete();
+ Files.createSymbolicLink(symlink.toPath(), realSonarHome.toPath());
+ GlobalProperties globalProperties = new GlobalProperties(ImmutableMap.of("sonar.userHome", symlink.getAbsolutePath()));
+
+ TempFolder tempFolder = tempFolderProvider.provide(globalProperties);
+ File newFile = tempFolder.newFile();
+ assertThat(newFile.getParentFile().getParentFile().getAbsolutePath()).isEqualTo(symlink.getAbsolutePath());
+ assertThat(newFile.getParentFile().getName()).startsWith(".sonartmp_");
+ }
+
private File getCreatedTempDir(File workingDir) {
assertThat(workingDir).isDirectory();
assertThat(workingDir.listFiles()).hasSize(1);