Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #245 from BridgeDigitalHealth/syoung/orphan-upload…
Browse files Browse the repository at this point in the history
…-logging

Add more logging to the V1 file uploader
  • Loading branch information
syoung-smallwisdom authored Feb 16, 2024
2 parents 164b771 + 609a96a commit 900f37c
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -1355,21 +1357,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)
Expand Down

0 comments on commit 900f37c

Please sign in to comment.