diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index c25611872e..ba2a852732 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -6323,7 +6323,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = NKUJUXUJ3B; @@ -6391,7 +6391,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = NKUJUXUJ3B; diff --git a/iOSClient/Utility/NCUtilityFileSystem.swift b/iOSClient/Utility/NCUtilityFileSystem.swift index 20f875f41b..86d0898a32 100644 --- a/iOSClient/Utility/NCUtilityFileSystem.swift +++ b/iOSClient/Utility/NCUtilityFileSystem.swift @@ -801,8 +801,7 @@ final class NCUtilityFileSystem: NSObject, @unchecked Sendable { let minimumDate = Date().addingTimeInterval(-days * 24 * 60 * 60) let storageURL = URL(fileURLWithPath: getDirectoryProviderStorage()) let manager = FileManager.default - - var offlineDirectories: [String] = [] + var protectedOcIds = Set() let directories = await database.getTablesDirectoryAsync( predicate: NSPredicate(format: "offline == true"), @@ -811,17 +810,20 @@ final class NCUtilityFileSystem: NSObject, @unchecked Sendable { ) for directory in directories { - guard let metadata = await database.getMetadataFromOcIdAsync(directory.ocId) else { - continue - } - - let path = getDirectoryProviderStorageOcId( - metadata.ocId, - userId: metadata.userId, - urlBase: metadata.urlBase + let serverUrl = directory.serverUrl.hasSuffix("/") + ? String(directory.serverUrl.dropLast()) + : directory.serverUrl + let metadatas: [tableMetadata] = await database.getMetadatasAsync( + predicate: NSPredicate( + format: "account == %@ AND directory == false AND (serverUrl == %@ OR serverUrl BEGINSWITH %@)", + directory.account, + serverUrl, + serverUrl + "/" + ) ) - offlineDirectories.append(path) + protectedOcIds.insert(directory.ocId) + protectedOcIds.formUnion(metadatas.map(\.ocId)) } let localFiles = await database.getTableLocalFilesAsync( @@ -847,10 +849,10 @@ final class NCUtilityFileSystem: NSObject, @unchecked Sendable { ((attributes[.size] as? NSNumber)?.uint64Value ?? 0) > 0 else { continue } + let directoryURL = fileURL.deletingLastPathComponent() + let ocId = directoryURL.lastPathComponent - if offlineDirectories.contains(where: { - fileURL.path == $0 || fileURL.path.hasPrefix($0 + "/") - }) { + if protectedOcIds.contains(ocId) { continue } @@ -866,9 +868,6 @@ final class NCUtilityFileSystem: NSObject, @unchecked Sendable { } } - let directoryURL = fileURL.deletingLastPathComponent() - let ocId = directoryURL.lastPathComponent - guard !processedOcIds.contains(ocId), let localFile = localFilesByOcId[ocId], (localFile.lastOpeningDate as Date) < minimumDate else {