cloud sync: small bug fixes around handling deleted files (#17236)

This commit is contained in:
Eric Warmenhoven 2024-12-07 03:59:05 -05:00 committed by GitHub
parent 3bdc71c20f
commit 7b29062e96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 8 deletions

View File

@ -159,10 +159,10 @@ static bool icloud_update(const char *p, RFILE *rfile, cloud_sync_complete_handl
static bool icloud_delete(const char *p, cloud_sync_complete_handler_t cb, void *user_data)
{
char *path = strdup(p);
NSString *path = [NSString stringWithUTF8String:p];
NSPredicate *pred = [NSComparisonPredicate
predicateWithLeftExpression:[NSExpression expressionForKeyPath:@"path"]
rightExpression:[NSExpression expressionForConstantValue:[NSString stringWithUTF8String:path]]
rightExpression:[NSExpression expressionForConstantValue:path]
modifier:NSDirectPredicateModifier
type:NSEqualToPredicateOperatorType
options:0];
@ -170,18 +170,17 @@ static bool icloud_delete(const char *p, cloud_sync_complete_handler_t cb, void
[CKContainer.defaultContainer.privateCloudDatabase performQuery:query
inZoneWithID:nil
completionHandler:^(NSArray<CKRecord *> * _Nullable results, NSError * _Nullable error) {
RARCH_DBG("[iCloud] deleting %d records for %s\n", [results count], path);
RARCH_DBG("[iCloud] deleting %d records for %s\n", [results count], [path UTF8String]);
for (CKRecord *record in results)
{
[CKContainer.defaultContainer.privateCloudDatabase deleteRecordWithID:record.recordID
completionHandler:^(CKRecordID * _Nullable recordID, NSError * _Nullable error) {
RARCH_DBG("[iCloud] delete callback for %s %s\n", path, error == nil ? "succeeded" : "failed");
RARCH_DBG("[iCloud] delete callback for %s %s\n", [path UTF8String], error == nil ? "succeeded" : "failed");
if (error)
RARCH_DBG("[iCloud] error: %s\n", [[error debugDescription] UTF8String]);
}];
}
cb(user_data, path, error == nil, NULL);
free(path);
cb(user_data, [path UTF8String], error == nil, NULL);
}];
return true;
}

View File

@ -799,7 +799,10 @@ static void task_cloud_sync_check_server_current(task_cloud_sync_state_t *sync_s
else if (!CS_FILE_DELETED(server_file))
task_cloud_sync_fetch_server_file(sync_state);
else
{
task_cloud_sync_delete_current_file(sync_state);
task_cloud_sync_add_to_updated_manifest(sync_state, CS_FILE_KEY(server_file), CS_FILE_HASH(server_file), false);
}
}
static void task_cloud_sync_delete_cb(void *user_data, const char *path, bool success, RFILE *file)
@ -952,10 +955,10 @@ static void task_cloud_sync_diff_next(task_cloud_sync_state_t *sync_state)
/* the file has been deleted locally */
if (!CS_FILE_DELETED(server_file))
{
if (CS_FILE_DELETED(current_file))
if (CS_FILE_DELETED(local_file))
/* previously saw the delete, now it's resurrected */
task_cloud_sync_fetch_server_file(sync_state);
else if (string_is_equal(CS_FILE_HASH(server_file), CS_FILE_HASH(current_file)))
else if (string_is_equal(CS_FILE_HASH(server_file), CS_FILE_HASH(local_file)))
/* server didn't change, delete from the server */
task_cloud_sync_delete_server_file(sync_state);
else