From e8cb50ab6ddbf3926eb10866f8e7545fdbe95f10 Mon Sep 17 00:00:00 2001 From: Sunny Chung Date: Fri, 16 Feb 2024 20:49:26 +0800 Subject: [PATCH] fix could not import a partially corrupted backup --- .../multiplatform/hellohttp/importer/DataDumpImporter.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/importer/DataDumpImporter.kt b/src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/importer/DataDumpImporter.kt index 167fe82a..ff07da30 100644 --- a/src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/importer/DataDumpImporter.kt +++ b/src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/importer/DataDumpImporter.kt @@ -106,14 +106,14 @@ class DataDumpImporter { } } - fun copyWithNewId(current: TreeObject): TreeObject { + fun copyWithNewId(current: TreeObject): TreeObject? { return when (current) { is TreeFolder -> current.copy( id = uuidString(), - childs = current.childs.map { copyWithNewId(it) }.toMutableList(), + childs = current.childs.mapNotNull { copyWithNewId(it) }.toMutableList(), ) is TreeRequest -> current.copy( - id = newRequestTemplateIds[current.id]!! + id = newRequestTemplateIds[current.id] ?: return null ) } } @@ -129,7 +129,7 @@ class DataDumpImporter { environments = it.environments.map { it.copy(id = uuidString()) }.toMutableList(), - treeObjects = it.treeObjects.map { copyWithNewId(it) }.toMutableList(), + treeObjects = it.treeObjects.mapNotNull { copyWithNewId(it) }.toMutableList(), grpcApiSpecIds = it.grpcApiSpecIds.mapNotNull { newApiSpecIds[it] }.toMutableSet(), ) }.toMutableList()