From 969b5c975b339ec7293ee9049d0c32a0c5683cd5 Mon Sep 17 00:00:00 2001 From: Shannon Young Date: Fri, 16 Feb 2024 11:13:05 -0800 Subject: [PATCH 1/2] Add more logging to the V1 file uploader --- .../V1/BridgeFileUploadManager.swift | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/SwiftPackage/Sources/BridgeClientExtension/File Uploading/V1/BridgeFileUploadManager.swift b/SwiftPackage/Sources/BridgeClientExtension/File Uploading/V1/BridgeFileUploadManager.swift index 892fda5a6..28388c298 100644 --- a/SwiftPackage/Sources/BridgeClientExtension/File Uploading/V1/BridgeFileUploadManager.swift +++ b/SwiftPackage/Sources/BridgeClientExtension/File Uploading/V1/BridgeFileUploadManager.swift @@ -1355,21 +1355,30 @@ class BridgeFileUploadManager: SandboxFileManager, BridgeURLSessionDownloadDeleg } func apiInfoFromXAttrs(for filePath: String, debugMessage: String? = nil) -> (uploadApi: BridgeFileUploadAPI, fileId: String, contentType: String, extras: Codable?)? { + var message = "\(debugMessage ?? ""): File=\(filePath)" do { - return try self._apiInfoFromXAttrs(for: filePath) + let (tempFile, attributes) = try _tempFile(for: filePath) + if let attributes = attributes { + message += ", attributes=\(attributes)" + } + return try self._apiInfoFromXAttrs(for: tempFile) } catch { - Logger.log(tag: .upload, error: error, message: debugMessage) + Logger.log(tag: .upload, error: error, message: message) return nil } } - func _apiInfoFromXAttrs(for filePath: String) throws -> (uploadApi: BridgeFileUploadAPI, fileId: String, contentType: String, extras: Codable?) { + func _tempFile(for filePath: String) throws -> (URL, [FileAttributeKey : Any]?) { let fullPath = self.fullyQualifiedPath(of: filePath) guard FileManager.default.fileExists(atPath: fullPath) else { let message = "Unexpected: Attempting to retrieve upload API info for temp file with invariant path '\(filePath) but temp file does not exist at '\(fullPath)" throw BridgeUnexpectedNullError(category: .missingFile, message: message) } - let tempFile = URL(fileURLWithPath: fullPath) + let attributes = try? FileManager.default.attributesOfItem(atPath: fullPath) + return (URL(fileURLWithPath: fullPath), attributes) + } + + func _apiInfoFromXAttrs(for tempFile: URL) throws -> (uploadApi: BridgeFileUploadAPI, fileId: String, contentType: String, extras: Codable?) { let apiStringData = try tempFile.extendedAttribute(forName: self.uploadApiAttributeName) let fileIdData = try tempFile.extendedAttribute(forName: self.fileIdAttributeName) From 609a96a548f23f2c913006f94eb9a96951c49ac6 Mon Sep 17 00:00:00 2001 From: Shannon Young Date: Fri, 16 Feb 2024 15:41:08 -0800 Subject: [PATCH 2/2] Do not attempt to process files that are not in an uploads subdirectory This was trying to process files that were being stored by the app in app support at the base directory. --- .../File Uploading/V1/BridgeFileUploadManager.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SwiftPackage/Sources/BridgeClientExtension/File Uploading/V1/BridgeFileUploadManager.swift b/SwiftPackage/Sources/BridgeClientExtension/File Uploading/V1/BridgeFileUploadManager.swift index 28388c298..00d993dd4 100644 --- a/SwiftPackage/Sources/BridgeClientExtension/File Uploading/V1/BridgeFileUploadManager.swift +++ b/SwiftPackage/Sources/BridgeClientExtension/File Uploading/V1/BridgeFileUploadManager.swift @@ -1042,11 +1042,13 @@ class BridgeFileUploadManager: SandboxFileManager, BridgeURLSessionDownloadDeleg else { continue } + let uploadSuffix = "Uploads" if isDirectory { - if !name.hasSuffix("Uploads") { + if !name.hasSuffix(uploadSuffix) { dirEnumerator.skipDescendants() } - } else { + } else if fileUrl.pathComponents.contains(where: { $0.hasSuffix(uploadSuffix) }) { + // Exclude files at the base of the application support directory. allFiles.append(fileUrl) } }