Skip to content

Commit d58c2f9

Browse files
fix (#4077)
Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com>
1 parent be51481 commit d58c2f9

3 files changed

Lines changed: 32 additions & 26 deletions

File tree

Nextcloud.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5784,7 +5784,7 @@
57845784
CLANG_WARN_UNREACHABLE_CODE = YES;
57855785
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
57865786
COPY_PHASE_STRIP = NO;
5787-
CURRENT_PROJECT_VERSION = 4;
5787+
CURRENT_PROJECT_VERSION = 0;
57885788
DEAD_CODE_STRIPPING = YES;
57895789
DEBUG_INFORMATION_FORMAT = dwarf;
57905790
DEVELOPMENT_TEAM = NKUJUXUJ3B;
@@ -5812,7 +5812,7 @@
58125812
"@executable_path/Frameworks",
58135813
"@executable_path/../../Frameworks",
58145814
);
5815-
MARKETING_VERSION = 33.0.5;
5815+
MARKETING_VERSION = 33.0.6;
58165816
ONLY_ACTIVE_ARCH = YES;
58175817
OTHER_CFLAGS = "-v";
58185818
OTHER_LDFLAGS = "";
@@ -5852,7 +5852,7 @@
58525852
CLANG_WARN_UNREACHABLE_CODE = YES;
58535853
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
58545854
COPY_PHASE_STRIP = NO;
5855-
CURRENT_PROJECT_VERSION = 4;
5855+
CURRENT_PROJECT_VERSION = 0;
58565856
DEAD_CODE_STRIPPING = YES;
58575857
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
58585858
DEVELOPMENT_TEAM = NKUJUXUJ3B;
@@ -5878,7 +5878,7 @@
58785878
"@executable_path/Frameworks",
58795879
"@executable_path/../../Frameworks",
58805880
);
5881-
MARKETING_VERSION = 33.0.5;
5881+
MARKETING_VERSION = 33.0.6;
58825882
ONLY_ACTIVE_ARCH = YES;
58835883
OTHER_CFLAGS = "-v";
58845884
OTHER_LDFLAGS = "";

iOSClient/Data/NCManageDatabase+Metadata.swift

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -340,34 +340,50 @@ extension tableMetadata {
340340
CGSize(width: width, height: height)
341341
}
342342

343+
var tagNames: [String] {
344+
tags.map(\.name)
345+
}
346+
343347
/// Returns false if the user is lokced out of the file. I.e. The file is locked but by somone else
344348
func canUnlock(as user: String) -> Bool {
345349
return !lock || (lockOwner == user && lockOwnerType == 0)
346350
}
347351

348352
/// Returns a detached (unmanaged) deep copy of the current `tableMetadata` object.
349353
///
350-
/// - Note: Primitive list properties (e.g., `shareType`) are copied automatically by `init(value:)`.
351-
/// For `List` containing Realm objects (e.g., `exifPhotos`, `tags`) this method creates new instances
352-
/// to ensure the copy is fully detached and safe to use outside of a Realm context.
354+
/// - Note: Primitive properties and lists of primitive values (for example `shareType`)
355+
/// are copied automatically by `init(value:)`.
356+
/// For `List` properties containing Realm objects (for example `exifPhotos` and `tags`),
357+
/// this method recreates each element explicitly to ensure the resulting copy is fully
358+
/// detached and safe to use across Realm contexts.
353359
///
354360
/// - Returns: A new `tableMetadata` instance fully detached from Realm.
355361
func detachedCopy() -> tableMetadata {
356-
// Use Realm's built-in copy constructor for primitive properties and List of primitives
362+
// Use Realm's built-in copy constructor for primitive properties and lists of primitive values.
357363
let detached = tableMetadata(value: self)
358364

359-
// Deep copy of List of Realm objects (exifPhotos and tags)
365+
// Deep copy of List of Realm objects
360366
detached.exifPhotos.removeAll()
361-
detached.exifPhotos.append(objectsIn: self.exifPhotos.map { NCKeyValue(value: $0) })
367+
detached.exifPhotos.append(objectsIn: self.exifPhotos.map {
368+
let copy = NCKeyValue()
369+
copy.key = $0.key
370+
copy.value = $0.value
371+
return copy
372+
})
373+
362374
detached.tags.removeAll()
363-
detached.tags.append(objectsIn: self.tags.map { tableMetadataTag(value: $0) })
375+
detached.tags.append(objectsIn: self.tags.map {
376+
let copy = tableMetadataTag()
377+
copy.primaryKey = $0.primaryKey
378+
copy.account = $0.account
379+
copy.id = $0.id
380+
copy.name = $0.name
381+
copy.color = $0.color
382+
return copy
383+
})
364384

365385
return detached
366386
}
367-
368-
var tagNames: [String] {
369-
tags.map(\.name)
370-
}
371387
}
372388

373389
extension NCManageDatabase {
@@ -474,16 +490,6 @@ extension NCManageDatabase {
474490
}
475491
}
476492

477-
func addMetadataIfNotExistsAsync(_ metadata: tableMetadata) async {
478-
let detached = metadata.detachedCopy()
479-
480-
await core.performRealmWriteAsync { realm in
481-
if realm.object(ofType: tableMetadata.self, forPrimaryKey: metadata.ocId) == nil {
482-
realm.add(detached)
483-
}
484-
}
485-
}
486-
487493
func deleteMetadataAsync(predicate: NSPredicate) async {
488494
await core.performRealmWriteAsync { realm in
489495
let result = realm.objects(tableMetadata.self)

iOSClient/Networking/NCNetworking+Recommendations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extension NCNetworking {
3939

4040
if results.error == .success, let file = results.files?.first {
4141
let metadata = await NCManageDatabaseCreateMetadata().convertFileToMetadataAsync(file)
42-
await NCManageDatabase.shared.addMetadataIfNotExistsAsync(metadata)
42+
await NCManageDatabase.shared.addMetadataAsync(metadata)
4343

4444
if metadata.isLivePhoto, metadata.isVideo {
4545
continue

0 commit comments

Comments
 (0)