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

Add more logging to the V1 file uploader #245

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% certain, but I don't think this gets extended attributes, if that's what you were hoping to log. There's a completely separate api for xattrs. IIRC there's a class extension somewhere that implements this since I think xattrs api is Obj-C only.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I'm looking for the attributes like "when was the file last modified/created" rather than the extended attributes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok makes sense

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
Loading