IJPL-217399, IJPL-217405 rdct: Add progress bar and implement settings backup in file-based sync

If there are any conflicts between settings files during the first initial sync, then after selecting a resolution:
- A backup is made on the side where the settings files are going to be overwritten
- A progress bar is shown during the initial sync
- A notification with the path to the backup is shown in the end

GitOrigin-RevId: 8f4b7fdf2e33150135efc3923bce3c3672205060
This commit is contained in:
Nikita Zaytsev
2025-11-15 08:25:11 +00:00
committed by intellij-monorepo-bot
parent 3b35aa640f
commit 71ff6d86a3
4 changed files with 27 additions and 3 deletions
+2
View File
@@ -116,6 +116,8 @@ com.intellij.ide.wizard.StepListener
- java.util.EventListener
- a:stateChanged():V
c:com.intellij.notification.Notification
a:com.intellij.notification.NotificationAction
- s:createExpiring(java.lang.String,java.lang.String,java.util.function.BiConsumer):com.intellij.notification.NotificationAction
com.intellij.notification.NotificationGroupManager
- s:getInstance():com.intellij.notification.NotificationGroupManager
- a:getNotificationGroup(java.lang.String):com.intellij.notification.NotificationGroup
@@ -57,6 +57,14 @@ public abstract class NotificationAction extends DumbAwareAction {
return new Simple(dynamicText, action, false, action, null);
}
public static @NotNull NotificationAction createExpiring(
@NotNull @NotificationContent String text,
@NotNull String actionId,
@NotNull BiConsumer<? super AnActionEvent, ? super Notification> action
) {
return new Simple(text, action, true, action, actionId);
}
public static @NotNull NotificationAction createExpiring(
@NotNull @NotificationContent String text,
@NotNull BiConsumer<? super AnActionEvent, ? super Notification> action
@@ -396,12 +396,22 @@ public final class ConfigImportHelper {
}
private static Path backupAndDeleteCurrentConfig(Path currentConfig, Logger log, @Nullable ConfigImportSettings settings) throws IOException {
return backupCurrentConfig(currentConfig, log, settings, true);
}
public static Path backupCurrentConfig(Path currentConfig, Logger log, @Nullable ConfigImportSettings settings) throws IOException {
return backupCurrentConfig(currentConfig, log, settings, false);
}
private static Path backupCurrentConfig(Path currentConfig, Logger log, @Nullable ConfigImportSettings settings, boolean deleteFiles) throws IOException {
var tempDir = Files.createDirectories(currentConfig.getFileSystem().getPath(System.getProperty("java.io.tmpdir")));
var tempBackupDir = Files.createTempDirectory(tempDir, currentConfig.getFileName() + "-backup-" + UUID.randomUUID());
log.info("Backup config from " + currentConfig + " to " + tempBackupDir);
NioFiles.copyRecursively(currentConfig, tempBackupDir, file -> !shouldSkipFileDuringImport(file, settings));
deleteCurrentConfigDir(currentConfig, log);
if (deleteFiles) {
deleteCurrentConfigDir(currentConfig, log);
}
var pluginDir = currentConfig.getFileSystem().getPath(PathManager.getPluginsDir().toString());
if (Files.exists(pluginDir) && !pluginDir.startsWith(currentConfig)) {
@@ -409,7 +419,9 @@ public final class ConfigImportHelper {
log.info("Backup plugins dir separately from " + pluginDir + " to " + pluginBackup);
NioFiles.createDirectories(pluginBackup);
NioFiles.copyRecursively(pluginDir, pluginBackup);
NioFiles.deleteRecursively(pluginDir);
if (deleteFiles) {
NioFiles.deleteRecursively(pluginDir);
}
}
return tempBackupDir;
@@ -16,7 +16,7 @@ import kotlin.io.path.*
@ApiStatus.Internal
class ConfigBackup(private val configDir: Path) {
@Throws(IOException::class)
fun moveToBackup(dirToMove: Path) {
fun moveToBackup(dirToMove: Path): Path {
val backupDir = getBackupDir(configDir)
if (backupDir.exists()) {
migratePreviousBackupIfExists(backupDir)
@@ -27,6 +27,8 @@ class ConfigBackup(private val configDir: Path) {
LOG.info("Move backup from $dirToMove to $backupPath")
NioFiles.copyRecursively(dirToMove, backupPath)
NioFiles.deleteRecursively(dirToMove)
return backupPath
}
private fun migratePreviousBackupIfExists(backupDir: Path) {