From 73feb7c8ce92389d1d50e8fac3aac38fa494cc32 Mon Sep 17 00:00:00 2001 From: "Ilia.Shulgin" Date: Mon, 20 Jan 2025 15:46:16 +0100 Subject: [PATCH] [log] Verbose logging for cleanupAllStorageFiles IOExceptions `deleteWithRenaming` swallows problems description returning only boolean value GitOrigin-RevId: 6910f25c89f07691bb751e68b40292f852220eab --- .../intellij/vcs/log/util/PersistentUtil.kt | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/util/PersistentUtil.kt b/platform/vcs-log/impl/src/com/intellij/vcs/log/util/PersistentUtil.kt index ee3f950b1613..4aae9d5c010b 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/util/PersistentUtil.kt +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/util/PersistentUtil.kt @@ -1,6 +1,7 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.vcs.log.util +import com.intellij.codeInsight.navigation.LOG import com.intellij.openapi.application.PathManager import com.intellij.openapi.project.Project import com.intellij.openapi.util.io.FileUtil @@ -11,6 +12,7 @@ import com.intellij.util.io.IOUtil import com.intellij.vcs.log.VcsLogProvider import com.intellij.vcs.log.util.PersistentUtil.getPersistenceLogCacheDir import org.jetbrains.annotations.NonNls +import java.io.IOException import java.nio.file.Files import java.nio.file.Path @@ -50,10 +52,28 @@ internal sealed class StorageId(@NonNls protected val projectName: String, @NonN val baseDir: Path by lazy { getPersistenceLogCacheDir(projectName, logId) } abstract val storagePath: Path - fun cleanupAllStorageFiles() = FileUtil.deleteWithRenaming(storagePath) + fun cleanupAllStorageFiles(): Boolean { + val tempFileNameForDeletion = FileUtil.findSequentNonexistentFile(storagePath.parent.toFile(), storagePath.fileName.toString(), "") + val dirToDelete = try { + Files.move(storagePath, tempFileNameForDeletion.toPath()) + } catch (e: IOException) { + LOG.warn("Failed to move $storagePath to $tempFileNameForDeletion", e) + storagePath + } - class Directory(projectName: String, @NonNls private val subdirName: String, logId: String, - val version: Int) : StorageId(projectName, logId) { + return try { + FileUtil.delete(dirToDelete) + true + } catch (e: IOException) { + LOG.warn("Failed to delete $dirToDelete", e) + false + } + } + + class Directory( + projectName: String, @NonNls private val subdirName: String, logId: String, + val version: Int, + ) : StorageId(projectName, logId) { override val storagePath: Path by lazy { baseDir.resolve(subdirName) } @JvmOverloads