From e3abde331039633a5a125d48803ca9ceef59e4fa Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 18 Sep 2025 12:33:01 +0200 Subject: [PATCH] BAZEL-2160 introduce removeProjectConfigurationAndCaches GitOrigin-RevId: dc7965c631137fcc0615d439e50b8166debe2e13 --- .../src/IprProjectStoreDescriptor.kt | 4 ++ .../project/impl/ProjectManagerImpl.kt | 53 +++++++------------ .../ProjectStorePathCustomizer.kt | 7 +++ 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/platform/configuration-store-impl/src/IprProjectStoreDescriptor.kt b/platform/configuration-store-impl/src/IprProjectStoreDescriptor.kt index 6f9c74b1cc13..903d87dc91dc 100644 --- a/platform/configuration-store-impl/src/IprProjectStoreDescriptor.kt +++ b/platform/configuration-store-impl/src/IprProjectStoreDescriptor.kt @@ -26,6 +26,10 @@ internal class IprProjectStoreDescriptor( return Files.isRegularFile(file) } + override fun removeProjectConfigurationAndCaches() { + Files.deleteIfExists(file) + } + override fun getProjectName(): String { return file.fileName.toString().removeSuffix(ProjectFileType.DOT_DEFAULT_EXTENSION) } diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.kt b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.kt index 08daf540fd5c..4a1b1f69f32c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.kt +++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.kt @@ -62,6 +62,7 @@ import com.intellij.openapi.ui.MessageDialogBuilder import com.intellij.openapi.ui.Messages import com.intellij.openapi.util.* import com.intellij.openapi.util.io.FileUtil +import com.intellij.openapi.util.io.NioFiles.deleteRecursively import com.intellij.openapi.util.registry.Registry import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.impl.ZipHandler @@ -90,7 +91,6 @@ import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.concurrency.annotations.RequiresBackgroundThread import com.intellij.util.concurrency.annotations.RequiresEdt import com.intellij.util.containers.ContainerUtil -import com.intellij.util.io.delete import com.intellij.util.runSuppressing import com.intellij.workspaceModel.ide.impl.jpsMetrics import kotlinx.coroutines.* @@ -99,7 +99,6 @@ import org.jetbrains.annotations.NonNls import org.jetbrains.annotations.TestOnly import org.jetbrains.annotations.VisibleForTesting import java.io.IOException -import java.nio.file.Files import java.nio.file.InvalidPathException import java.nio.file.LinkOption import java.nio.file.Path @@ -653,7 +652,7 @@ open class ProjectManagerImpl : ProjectManagerEx(), Disposable { val project = when { options.project != null -> options.project!! options.isNewProject -> prepareNewProject( - projectStoreBaseDir = projectStoreBaseDir, + identityFle = projectStoreBaseDir, projectName = options.projectName, beforeInit = options.beforeInit, useDefaultProjectAsTemplate = options.useDefaultProjectAsTemplate, @@ -875,7 +874,7 @@ open class ProjectManagerImpl : ProjectManagerEx(), Disposable { } private suspend fun prepareNewProject( - projectStoreBaseDir: Path, + identityFle: Path, projectName: String?, beforeInit: ((Project) -> Unit)?, useDefaultProjectAsTemplate: Boolean, @@ -892,18 +891,26 @@ open class ProjectManagerImpl : ProjectManagerEx(), Disposable { null } withContext(Dispatchers.IO) { - removeProjectConfigurationAndCaches(projectStoreBaseDir) + launch { + try { + ProjectStorePathManager.getInstance().getStoreDescriptor(identityFle).removeProjectConfigurationAndCaches() + } + catch (_: IOException) { + } + } + launch { + try { + deleteRecursively(getProjectDataPathRoot(identityFle)) + } + catch (_: IOException) { + } + } } - val project = instantiateProject(projectStoreBaseDir, projectName, beforeInit) + val project = instantiateProject(identityFle = identityFle, projectName = projectName, beforeInit = beforeInit) project.putUserData(PROJECT_NEWLY_OPENED, markAsNew) val template = templateAsync?.await() - initProject( - file = projectStoreBaseDir, - project = project, - preloadServices = preloadServices, - template = template, - ) + initProject(file = identityFle, project = project, preloadServices = preloadServices, template = template) project } } @@ -1259,28 +1266,6 @@ private fun toCanonicalName(filePath: String): Path { return file } -private fun removeProjectConfigurationAndCaches(projectFile: Path) { - try { - if (Files.isRegularFile(projectFile)) { - Files.deleteIfExists(projectFile) - } - else { - Files.newDirectoryStream(ProjectStorePathManager.getInstance().getStoreDescriptor(projectFile).dotIdea!!).use { directoryStream -> - for (file in directoryStream) { - file!!.delete() - } - } - } - } - catch (_: IOException) { - } - try { - getProjectDataPathRoot(projectFile).delete() - } - catch (_: IOException) { - } -} - private class ProjectInitHelper( private val cs: CoroutineScope, private val frameAllocator: ProjectFrameAllocator, diff --git a/platform/projectModel-impl/src/com/intellij/configurationStore/ProjectStorePathCustomizer.kt b/platform/projectModel-impl/src/com/intellij/configurationStore/ProjectStorePathCustomizer.kt index 3db5ac069fd5..12710eb412b0 100644 --- a/platform/projectModel-impl/src/com/intellij/configurationStore/ProjectStorePathCustomizer.kt +++ b/platform/projectModel-impl/src/com/intellij/configurationStore/ProjectStorePathCustomizer.kt @@ -8,6 +8,7 @@ import com.intellij.openapi.components.State import com.intellij.openapi.components.StateStorageOperation import com.intellij.openapi.components.Storage import com.intellij.openapi.project.Project +import com.intellij.openapi.util.io.NioFiles import org.jetbrains.annotations.ApiStatus.Experimental import org.jetbrains.annotations.ApiStatus.Internal import java.nio.file.Path @@ -32,6 +33,12 @@ interface ProjectStoreDescriptor { // where we do store project files (misc.xml and so on) val dotIdea: Path? + fun removeProjectConfigurationAndCaches() { + for (file in NioFiles.list(dotIdea!!)) { + NioFiles.deleteRecursively(file) + } + } + val presentableUrl: Path get() = projectIdentityFile