-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFilesDatabaseManager+KeepOffline.swift
More file actions
55 lines (50 loc) · 1.84 KB
/
FilesDatabaseManager+KeepOffline.swift
File metadata and controls
55 lines (50 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// FilesDatabaseManager+KeepOffline.swift
// NextcloudFileProviderKit
//
// Created by Claudio Cambra on 13/5/25.
//
import Foundation
import RealmSwift
public extension FilesDatabaseManager {
func set(
keepOffline: Bool, for metadata: SendableItemMetadata
) throws -> SendableItemMetadata? {
guard #available(macOS 13.0, iOS 16.0, visionOS 1.0, *) else {
let errorString = """
Could not update keepOffline status for item: \(metadata.fileName)
as the system does not support this state.
"""
Self.logger.error("\(errorString, privacy: .public)")
throw NSError(
domain: Self.errorDomain,
code: NSFeatureUnsupportedError,
userInfo: [NSLocalizedDescriptionKey: errorString]
)
}
guard let result = itemMetadatas.where({ $0.ocId == metadata.ocId }).first else {
let errorString = """
Did not update keepOffline for item metadata as it was not found.
ocID: \(metadata.ocId)
filename: \(metadata.fileName)
"""
Self.logger.error("\(errorString, privacy: .public)")
throw NSError(
domain: Self.errorDomain,
code: ErrorCode.metadataNotFound.rawValue,
userInfo: [NSLocalizedDescriptionKey: errorString]
)
}
try ncDatabase().write {
result.keepOffline = keepOffline
Self.logger.debug(
"""
Updated keepOffline status for item metadata.
ocID: \(metadata.ocId, privacy: .public)
fileName: \(metadata.fileName, privacy: .public)
"""
)
}
return SendableItemMetadata(value: result)
}
}