Skip to content

Commit

Permalink
Fixed deleting files if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
fkorotkov committed Jun 4, 2024
1 parent bc4ac28 commit 1a66d7d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CirrusModuleManager : IndexableSetContributor() {
}

internal val globalCacheLocation: Path
get() = Paths.get(PathManager.getSystemPath(), "extStarlarkModules")
get() = Paths.get(PathManager.getSystemPath(), "externalStarlarkModules")

fun modulePath(module: ModuleLocator): Path =
globalCacheLocation.resolve(module.org)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
import com.intellij.codeInspection.LocalQuickFix
import com.intellij.codeInspection.ProblemDescriptor
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.Task.Backgroundable
Expand All @@ -25,17 +26,17 @@ class DownloadGitHubModuleQuickFix(private val module: ModuleLocator) : LocalQui

override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
val containingFile = descriptor.psiElement.containingFile
val modulePath = CirrusModuleManager.modulePath(module)
val moduleParentDir = VfsUtil.createDirectories(modulePath.parent.toString())
try {
moduleParentDir.findChild(modulePath.name)?.delete(this)
} catch (e: Throwable) {
thisLogger().warn(e)
}

ProgressManager.getInstance().run(object : Backgroundable(project, StarlarkBundle.getMessage("starlark.intention.fetch.progress.fetching.module")) {
override fun run(indicator: ProgressIndicator) {
val modulePath = CirrusModuleManager.modulePath(module)
val git = Git.getInstance()

val moduleParentDir = VfsUtil.createDirectories(modulePath.parent.toString())
moduleParentDir.findChild(modulePath.name)?.also {
ApplicationManager.getApplication().runWriteAction { it.delete(this@DownloadGitHubModuleQuickFix) }
}

val success = GitCheckoutProvider.doClone(
project,
git,
Expand Down

0 comments on commit 1a66d7d

Please sign in to comment.