@@ -72,12 +72,14 @@ object KeeShareImport {
7272 val groupsToProcess = mutableListOf<GroupKDBX >()
7373
7474 // Collect all groups with KeeShare config
75+ Log .d(TAG , " Scanning groups for KeeShare config..." )
7576 database.rootGroup?.doForEachChild(
7677 null ,
7778 object : NodeHandler <GroupKDBX >() {
7879 override fun operate (node : GroupKDBX ): Boolean {
7980 val hasPerDevice = node.customData.get(KeeShareReference .PER_DEVICE_KEY ) != null
8081 val hasClassic = node.customData.get(KeeShareReference .CLASSIC_KEY ) != null
82+ Log .d(TAG , " Group '${node.title} ': perDevice=$hasPerDevice , classic=$hasClassic " )
8183 if (hasPerDevice || hasClassic) {
8284 groupsToProcess.add(node)
8385 }
@@ -90,11 +92,13 @@ object KeeShareImport {
9092 database.rootGroup?.let { root ->
9193 val hasPerDevice = root.customData.get(KeeShareReference .PER_DEVICE_KEY ) != null
9294 val hasClassic = root.customData.get(KeeShareReference .CLASSIC_KEY ) != null
95+ Log .d(TAG , " Root '${root.title} ': perDevice=$hasPerDevice , classic=$hasClassic " )
9396 if (hasPerDevice || hasClassic) {
9497 groupsToProcess.add(0 , root)
9598 }
9699 }
97100
101+ Log .d(TAG , " Found ${groupsToProcess.size} groups with KeeShare config" )
98102 for (group in groupsToProcess) {
99103 results.addAll(importGroup(database, group, ownDeviceId, cacheDirectory,
100104 fileProvider, singleFileProvider, isRAMSufficient))
@@ -117,10 +121,13 @@ object KeeShareImport {
117121
118122 // Priority 1: Per-device sync config
119123 val perDeviceData = group.customData.get(KeeShareReference .PER_DEVICE_KEY )
124+ Log .d(TAG , " importGroup('$groupName '): perDeviceData=${if (perDeviceData != null ) " present (${perDeviceData.value.length} chars)" else " null" } " )
120125 if (perDeviceData != null ) {
121126 val config = PerDeviceSyncConfig .fromCustomData(perDeviceData.value)
127+ Log .d(TAG , " PerDeviceSyncConfig: ${if (config != null ) " syncDir=${config.syncDir} , password=${if (config.password.isNotEmpty()) " (set)" else " (empty)" } " else " parse failed" } " )
122128 if (config != null ) {
123129 val containers = fileProvider(config.syncDir, ownDeviceId)
130+ Log .d(TAG , " fileProvider returned ${containers.size} container(s)" )
124131 for ((fileName, inputStream) in containers) {
125132 results.add(
126133 importContainer(database, group, groupName, fileName,
@@ -133,8 +140,10 @@ object KeeShareImport {
133140
134141 // Priority 2: Classic KeeShare/Reference (fallback for KeePassXC-created databases)
135142 val classicData = group.customData.get(KeeShareReference .CLASSIC_KEY )
143+ Log .d(TAG , " importGroup('$groupName '): classicData=${if (classicData != null ) " present (${classicData.value.length} chars)" else " null" } , singleFileProvider=${singleFileProvider != null } " )
136144 if (classicData != null && singleFileProvider != null ) {
137145 val ref = KeeShareReference .fromClassicCustomData(classicData.value)
146+ Log .d(TAG , " Classic ref: ${if (ref != null ) " type=${ref.type} , path='${ref.path} ', perDevice=${ref.isPerDeviceMode()} " else " parse failed" } " )
138147 if (ref != null && ref.path.isNotEmpty()
139148 && (ref.type == KeeShareReference .Type .IMPORT
140149 || ref.type == KeeShareReference .Type .SYNCHRONIZE )
@@ -168,15 +177,18 @@ object KeeShareImport {
168177 stream, password, cacheDirectory, isRAMSufficient
169178 )
170179
171- val entryCount = countEntries(containerDb)
180+ val containerEntryCount = countEntries(containerDb)
181+ val beforeCount = countEntriesInDb(database)
172182
173183 val merger = DatabaseKDBXMerger (database).apply {
174184 this .isRAMSufficient = isRAMSufficient
175185 }
176186 merger.mergeIntoGroup(containerDb, targetGroup)
177187
178- Log .i(TAG , " Imported $entryCount entries from $containerName into $groupName " )
179- ImportResult (groupName, containerName, entryCount, success = true )
188+ val afterCount = countEntriesInDb(database)
189+ val newEntries = afterCount - beforeCount
190+ Log .i(TAG , " Merged $containerName into $groupName : $containerEntryCount in container, $newEntries new entries added (total $beforeCount -> $afterCount )" )
191+ ImportResult (groupName, containerName, containerEntryCount, success = true )
180192 }
181193 } catch (e: Exception ) {
182194 Log .e(TAG , " Failed to import $containerName into $groupName " , e)
@@ -198,4 +210,8 @@ object KeeShareImport {
198210 )
199211 return count
200212 }
213+
214+ private fun countEntriesInDb (database : DatabaseKDBX ): Int {
215+ return countEntries(database)
216+ }
201217}
0 commit comments