From 1fdc5f7daf214757009d8bb1ca081d2bbf37014c Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Mon, 20 Apr 2026 10:12:35 +0200 Subject: [PATCH] fix Signed-off-by: Marino Faggiana --- Nextcloud.xcodeproj/project.pbxproj | 8 ++-- .../Data/NCManageDatabase+Metadata.swift | 48 +++++++++++-------- .../NCNetworking+Recommendations.swift | 2 +- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index 72d1ca23e6..0f134dc404 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -5784,7 +5784,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 0; DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = NKUJUXUJ3B; @@ -5812,7 +5812,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 33.0.5; + MARKETING_VERSION = 33.0.6; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "-v"; OTHER_LDFLAGS = ""; @@ -5852,7 +5852,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 0; DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = NKUJUXUJ3B; @@ -5878,7 +5878,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 33.0.5; + MARKETING_VERSION = 33.0.6; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "-v"; OTHER_LDFLAGS = ""; diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index 187ddd9a1c..90a5963798 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -340,6 +340,10 @@ extension tableMetadata { CGSize(width: width, height: height) } + var tagNames: [String] { + tags.map(\.name) + } + /// Returns false if the user is lokced out of the file. I.e. The file is locked but by somone else func canUnlock(as user: String) -> Bool { return !lock || (lockOwner == user && lockOwnerType == 0) @@ -347,27 +351,39 @@ extension tableMetadata { /// Returns a detached (unmanaged) deep copy of the current `tableMetadata` object. /// - /// - Note: Primitive list properties (e.g., `shareType`) are copied automatically by `init(value:)`. - /// For `List` containing Realm objects (e.g., `exifPhotos`, `tags`) this method creates new instances - /// to ensure the copy is fully detached and safe to use outside of a Realm context. + /// - Note: Primitive properties and lists of primitive values (for example `shareType`) + /// are copied automatically by `init(value:)`. + /// For `List` properties containing Realm objects (for example `exifPhotos` and `tags`), + /// this method recreates each element explicitly to ensure the resulting copy is fully + /// detached and safe to use across Realm contexts. /// /// - Returns: A new `tableMetadata` instance fully detached from Realm. func detachedCopy() -> tableMetadata { - // Use Realm's built-in copy constructor for primitive properties and List of primitives + // Use Realm's built-in copy constructor for primitive properties and lists of primitive values. let detached = tableMetadata(value: self) - // Deep copy of List of Realm objects (exifPhotos and tags) + // Deep copy of List of Realm objects detached.exifPhotos.removeAll() - detached.exifPhotos.append(objectsIn: self.exifPhotos.map { NCKeyValue(value: $0) }) + detached.exifPhotos.append(objectsIn: self.exifPhotos.map { + let copy = NCKeyValue() + copy.key = $0.key + copy.value = $0.value + return copy + }) + detached.tags.removeAll() - detached.tags.append(objectsIn: self.tags.map { tableMetadataTag(value: $0) }) + detached.tags.append(objectsIn: self.tags.map { + let copy = tableMetadataTag() + copy.primaryKey = $0.primaryKey + copy.account = $0.account + copy.id = $0.id + copy.name = $0.name + copy.color = $0.color + return copy + }) return detached } - - var tagNames: [String] { - tags.map(\.name) - } } extension NCManageDatabase { @@ -474,16 +490,6 @@ extension NCManageDatabase { } } - func addMetadataIfNotExistsAsync(_ metadata: tableMetadata) async { - let detached = metadata.detachedCopy() - - await core.performRealmWriteAsync { realm in - if realm.object(ofType: tableMetadata.self, forPrimaryKey: metadata.ocId) == nil { - realm.add(detached) - } - } - } - func deleteMetadataAsync(predicate: NSPredicate) async { await core.performRealmWriteAsync { realm in let result = realm.objects(tableMetadata.self) diff --git a/iOSClient/Networking/NCNetworking+Recommendations.swift b/iOSClient/Networking/NCNetworking+Recommendations.swift index a61c1dd7f0..9750e6aec4 100644 --- a/iOSClient/Networking/NCNetworking+Recommendations.swift +++ b/iOSClient/Networking/NCNetworking+Recommendations.swift @@ -39,7 +39,7 @@ extension NCNetworking { if results.error == .success, let file = results.files?.first { let metadata = await NCManageDatabaseCreateMetadata().convertFileToMetadataAsync(file) - await NCManageDatabase.shared.addMetadataIfNotExistsAsync(metadata) + await NCManageDatabase.shared.addMetadataAsync(metadata) if metadata.isLivePhoto, metadata.isVideo { continue