Skip to content

Commit 39add16

Browse files
Temporary directories should be removed on exit #167 (#209)
1 parent 67d9486 commit 39add16

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

utbot-core/src/main/kotlin/org/utbot/common/FileUtil.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,16 @@ object FileUtil {
7575
}.forEach { it.deleteRecursively() }
7676
}
7777

78-
private fun createTempDirectory(): Path {
79-
val tempFolderPath = Paths.get(tempDirectoryPath + File.separator + utBotTempFolderPrefix)
80-
81-
tempFolderPath.toFile().mkdirs()
82-
83-
return createTempDirectory(tempFolderPath, "generated-")
78+
fun createTempDirectory(prefix: String): Path {
79+
return createTempDirectory(utBotTempDirectory, prefix)
8480
}
8581

8682
/**
8783
* Copy the class file for given [classes] to temporary folder.
8884
* It can be used for Soot analysis.
8985
*/
9086
fun isolateClassFiles(vararg classes: KClass<*>): File {
91-
val tempDir = createTempDirectory().toFile()
87+
val tempDir = createTempDirectory("generated-").toFile()
9288

9389
for (clazz in classes) {
9490
val path = clazz.toClassFilePath()

utbot-framework/src/main/kotlin/org/utbot/engine/z3/Z3initializer.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.utbot.engine.z3
22

33
import com.microsoft.z3.Context
44
import com.microsoft.z3.Global
5+
import org.utbot.common.FileUtil
56
import java.io.File
67
import java.nio.file.Files.createTempDirectory
78

@@ -41,7 +42,7 @@ abstract class Z3Initializer : AutoCloseable {
4142

4243
val libFolder: String?
4344
if (libZ3DllUrl.toURI().scheme == "jar") {
44-
val tempDir = createTempDirectory(null).toFile().apply { deleteOnExit() }
45+
val tempDir = FileUtil.createTempDirectory("libs-").toFile()
4546

4647
allLibraries.forEach { name ->
4748
Z3Initializer::class.java

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/Settings.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import com.intellij.openapi.components.Storage
3232
import com.intellij.openapi.project.Project
3333
import com.intellij.util.xmlb.Converter
3434
import com.intellij.util.xmlb.annotations.OptionTag
35+
import org.utbot.common.FileUtil
36+
import java.util.concurrent.CompletableFuture
3537
import kotlin.reflect.KClass
3638

3739
@State(
@@ -153,6 +155,11 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
153155

154156
override fun getState(): State = state
155157

158+
override fun initializeComponent() {
159+
super.initializeComponent()
160+
CompletableFuture.runAsync { FileUtil.clearTempDirectory(UtSettings.daysLimitForTempFiles) }
161+
}
162+
156163
override fun loadState(state: State) {
157164
this.state = state
158165
}

utbot-intellij/src/main/resources/META-INF/plugin.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
<projectConfigurable parentId="tools" instance="org.utbot.intellij.plugin.settings.Configurable"
3131
id="org.utbot.intellij.plugin.settings.Configurable"
3232
displayName="UtBot"/>
33-
<projectService serviceImplementation="org.utbot.intellij.plugin.settings.Settings"/>
33+
<!--suppress PluginXmlValidity -->
34+
<projectService serviceImplementation="org.utbot.intellij.plugin.settings.Settings" preload="true"/>
3435
<registryKey defaultValue="false" description="Enable editing Kotlin test files" key="kotlin.ultra.light.classes.empty.text.range"/>
3536
</extensions>
3637

0 commit comments

Comments
 (0)