From 9ff66bb94f6063f7622a4e6a8f95f4c208fa96a7 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 12 Jan 2023 20:34:07 +0100 Subject: [PATCH] Add isFileSynced helper func to FileProviderFilesUtils Signed-off-by: Claudio Cambra --- .../NextcloudFileProviderFilesUtils.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/NextcloudFileProviderFilesUtils.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/NextcloudFileProviderFilesUtils.swift index fd64200c9..52d5c51da 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/NextcloudFileProviderFilesUtils.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/NextcloudFileProviderFilesUtils.swift @@ -102,3 +102,17 @@ func parentItemIdentifierFromMetadata(_ metadata: NextcloudFileMetadataTable) -> return nil } + +func isFileSynced(metadata: NextcloudFileMetadataTable) -> Bool { + do { + let localPathForFile = try localPathForNCFile(fileMetadata: metadata) + let localFileAttributes = try FileManager.default.attributesOfItem(atPath: localPathForFile.path) + let localFileSize = localFileAttributes[.size] as? Int64 + + return localFileSize == metadata.size + } catch let error { + print("Could not check if file %@ is synced, received error: %@", metadata.fileNameView, error) + } + + return false +}