Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import FileProvider
import Foundation
import RealmSwift

internal let stable1_0SchemaVersion: UInt64 = 100
internal let stable2_0SchemaVersion: UInt64 = 200 // Major change: deleted LocalFileMetadata type

///
/// Realm database abstraction and management.
///
Expand Down Expand Up @@ -43,7 +40,7 @@ public final class FilesDatabaseManager: Sendable {
)
}

private static let schemaVersion = stable2_0SchemaVersion
private static let schemaVersion = SchemaVersion.addedLockTokenPropertyToRealmItemMetadata
let logger: FileProviderLogger
let account: Account

Expand Down Expand Up @@ -115,9 +112,9 @@ public final class FilesDatabaseManager: Sendable {

let configuration = customConfiguration ?? Realm.Configuration(
fileURL: databaseLocation,
schemaVersion: Self.schemaVersion,
schemaVersion: Self.schemaVersion.rawValue,
migrationBlock: { migration, oldSchemaVersion in
if oldSchemaVersion == stable1_0SchemaVersion {
if oldSchemaVersion == SchemaVersion.initial.rawValue {
var localFileMetadataOcIds = Set<String>()

migration.enumerateObjects(ofType: "LocalFileMetadata") { oldObject, _ in
Expand Down Expand Up @@ -171,7 +168,7 @@ public final class FilesDatabaseManager: Sendable {

logger.info("Migrating shared legacy database to new database for \(account.ncKitAccount)")

let legacyConfiguration = Realm.Configuration(fileURL: sharedDatabaseURL, schemaVersion: stable2_0SchemaVersion, objectTypes: [RealmItemMetadata.self, RemoteFileChunk.self])
let legacyConfiguration = Realm.Configuration(fileURL: sharedDatabaseURL, schemaVersion: SchemaVersion.deletedLocalFileMetadata.rawValue, objectTypes: [RealmItemMetadata.self, RemoteFileChunk.self])

do {
let legacyRealm = try Realm(configuration: legacyConfiguration)
Expand Down
11 changes: 11 additions & 0 deletions Sources/NextcloudFileProviderKit/Database/SchemaVersion.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
// SPDX-License-Identifier: GPL-2.0-or-later

///
/// Different schema versions shipped with this project.
///
enum SchemaVersion: UInt64 {
case initial = 100
case deletedLocalFileMetadata = 200
case addedLockTokenPropertyToRealmItemMetadata = 201
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ extension NKFile {
note: note,
ownerId: ownerId,
ownerDisplayName: ownerDisplayName,
lock: lock,
lockOwner: lockOwner,
lockOwnerEditor: lockOwnerEditor,
lockOwnerType: lockOwnerType,
lockOwnerDisplayName: lockOwnerDisplayName,
lockTime: lockTime,
lockTimeOut: lockTimeOut,
lock: lock != nil ? true : false,
lockOwner: lock?.owner,
lockOwnerEditor: lock?.ownerEditor,
lockOwnerType: lock?.ownerType.rawValue,
lockOwnerDisplayName: lock?.ownerDisplayName,
lockTime: lock?.time,
lockTimeOut: lock?.timeOut,
lockToken: lock?.token,
path: path,
permissions: permissions,
quotaUsedBytes: quotaUsedBytes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,20 +304,8 @@ extension NextcloudKit: RemoteInterface {
}
}

public func setLockStateForFile(
remotePath: String,
lock: Bool,
account: Account,
options: NKRequestOptions,
taskHandler: @escaping (_ task: URLSessionTask) -> Void
) async -> (account: String, response: HTTPURLResponse?, error: NKError) {
return await withCheckedContinuation { continuation in
lockUnlockFile(
serverUrlFileName: remotePath, shouldLock: lock, account: account.ncKitAccount
) { account, response, error in
continuation.resume(returning: (account, response?.response, error))
}
}
public func lockUnlockFile(serverUrlFileName: String, type: NKLockType?, shouldLock: Bool, account: Account, options: NKRequestOptions, taskHandler: @escaping (URLSessionTask) -> Void) async throws -> NKLock? {
return try await lockUnlockFile(serverUrlFileName: serverUrlFileName, type: type, shouldLock: shouldLock, account: account.ncKitAccount, options: options, taskHandler: taskHandler)
}

public func trashedItems(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,7 @@ public protocol RemoteInterface {
taskHandler: @escaping (_ task: URLSessionTask) -> Void
) async -> (account: String, response: HTTPURLResponse?, error: NKError)

func setLockStateForFile(
remotePath: String,
lock: Bool,
account: Account,
options: NKRequestOptions,
taskHandler: @escaping (_ task: URLSessionTask) -> Void
) async -> (account: String, response: HTTPURLResponse?, error: NKError)
func lockUnlockFile(serverUrlFileName: String, type: NKLockType?, shouldLock: Bool, account: Account, options: NKRequestOptions, taskHandler: @escaping (_ task: URLSessionTask) -> Void) async throws -> NKLock?

func trashedItems(
account: Account,
Expand Down
Loading