Simplify temp local file creation while fetching contents, use File Provider volume

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-03-15 12:59:02 +01:00
Родитель 8661841c44
Коммит 762aee8e41
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: C839200C384636B0
2 изменённых файлов: 11 добавлений и 19 удалений

Просмотреть файл

@ -145,7 +145,7 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
// TODO: Handle folders nicely
do {
let fileNameLocalPath = try localPathForNCFile(ocId: metadata.ocId, fileNameView: metadata.fileNameView)
let fileNameLocalPath = try localPathForNCFile(ocId: metadata.ocId, fileNameView: metadata.fileNameView, domain: self.domain)
dbManager.setStatusForItemMetadata(metadata, status: NextcloudItemMetadataTable.Status.downloading) { updatedMetadata in

Просмотреть файл

@ -30,29 +30,21 @@ func pathForFileProviderExtData() -> URL? {
return containerUrl?.appendingPathComponent("FileProviderExt/")
}
func pathForFileProviderExtFiles() -> URL? {
let fileProviderDataUrl = pathForFileProviderExtData()
return fileProviderDataUrl?.appendingPathComponent("Files/")
func pathForFileProviderTempFilesForDomain(_ domain: NSFileProviderDomain) throws -> URL? {
guard let fpManager = NSFileProviderManager(for: domain) else {
throw NSFileProviderError(.providerNotFound)
}
let fileProviderDataUrl = try fpManager.temporaryDirectoryURL()
return fileProviderDataUrl.appendingPathComponent("TemporaryNextcloudFiles/")
}
@discardableResult func localPathForNCDirectory(ocId: String) throws -> URL {
guard let fileProviderFilesPathUrl = pathForFileProviderExtFiles() else {
func localPathForNCFile(ocId: String, fileNameView: String, domain: NSFileProviderDomain) throws -> URL {
guard let fileProviderFilesPathUrl = try pathForFileProviderTempFilesForDomain(domain) else {
throw URLError(.badURL)
}
let folderPathUrl = fileProviderFilesPathUrl.appendingPathComponent(ocId)
let folderPath = folderPathUrl.path
if !FileManager.default.fileExists(atPath: folderPath) {
try FileManager.default.createDirectory(at: folderPathUrl, withIntermediateDirectories: true)
}
return folderPathUrl
}
@discardableResult func localPathForNCFile(ocId: String, fileNameView: String) throws -> URL {
let fileFolderPathUrl = try localPathForNCDirectory(ocId: ocId)
let filePathUrl = fileFolderPathUrl.appendingPathComponent(fileNameView)
let filePathUrl = fileProviderFilesPathUrl.appendingPathComponent(fileNameView)
let filePath = filePathUrl.path
if !FileManager.default.fileExists(atPath: filePath) {