Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Pictures no longer on device but only on iCloud should be uploaded as well. #1339

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion kDriveCore/Utils/PHAsset/PHAsset+Exension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public extension PHAsset {
shouldTransformIntoJPEG = true
}

// Asset are copied when we start the Upload, thus guarantees the stability of the file
// Asset is copied when we start the Upload, thus guarantees the stability of the file
@InjectService var fileImportHelper: FileImportHelper
let targetURL = fileImportHelper.generateImportURL(for: resourceUTI)
do {
Expand All @@ -149,6 +149,7 @@ public extension PHAsset {
return targetURL
} catch {
SentryDebug.addBreadcrumb(message: error.localizedDescription, category: SentryDebug.Category.PHAsset, level: .error)
SentryDebug.capturePHAssetResourceManagerError(error)
}
return nil
}
Expand Down
23 changes: 17 additions & 6 deletions kDriveCore/Utils/PHAsset/PHAssetIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,32 +147,43 @@ struct PHAssetIdentifier: PHAssetIdentifiable {
let activity = ExpiringActivity(id: uid, delegate: activityDelegate)
activity.start()

// TODO: Check iCloud behaviour
let options = PHAssetResourceRequestOptions()
options.isNetworkAccessAllowed = true
options.progressHandler = { progress in
Log.photoLibraryUploader("hashing resource \(progress * 100)% …")
}

group.enter()
var resourceManagerError: Error?
PHAssetResourceManager.default().requestData(for: bestResource,
options: options) { data in
hasher.update(data)
} completionHandler: { _ in
} completionHandler: { error in
adrien-coye marked this conversation as resolved.
Show resolved Hide resolved
if let error {
resourceManagerError = error
Log.photoLibraryUploader("hashing resource failed with \(error)", level: .error)
} else {
Log.photoLibraryUploader("hashing resource finished successfully")
}
hasher.finalize()
group.leave()
}
group.wait()

activity.endAll()

guard let error = activityDelegate.error else {
// All good
return hasher.digestString
// PHAssetResourceManager errors, possibly fetching an asset on iCloud failed
if let resourceManagerError {
SentryDebug.capturePHAssetResourceManagerError(resourceManagerError)
throw resourceManagerError
}

// The processing of the hash was interrupted by the system
throw error
if let activityError = activityDelegate.error {
throw activityError
}

return hasher.digestString
}
}
}
9 changes: 9 additions & 0 deletions kDriveCore/Utils/Sentry/SentryDebug+Upload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ extension SentryDebug {
SentryDebug.capture(message: EventNames.uploadCompletedSuccess, extras: metadata)
}

static func capturePHAssetResourceManagerError(_ error: Error, function: StaticString = #function) {
let metadata: [String: Any] = [
"func": function,
"error": error,
"localizedError": error.localizedDescription
]
SentryDebug.capture(message: ErrorNames.assetResourceManagerError, context: metadata, level: .error)
}

// MARK: - Upload notifications

static func uploadNotificationError(_ metadata: [String: Any]) {
Expand Down
2 changes: 2 additions & 0 deletions kDriveCore/Utils/Sentry/SentryDebug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public enum SentryDebug {
static let uploadSessionErrorHandling = "UploadSessionErrorHandling"
static let uploadErrorUserNotification = "UploadErrorUserNotification"
static let viewModelNotConnectedToView = "ViewModelNotConnected"
/// An error was generated by an instance of `PHAssetResourceManager`
static let assetResourceManagerError = "PHAssetResourceManagerError"
}

static func logTokenMigration(newToken: ApiToken, oldToken: ApiToken) {
Expand Down
Loading