From 7b29062e96feb7fd2deeaf51dbabdadbc5b8be5d Mon Sep 17 00:00:00 2001 From: Eric Warmenhoven Date: Sat, 7 Dec 2024 03:59:05 -0500 Subject: [PATCH] cloud sync: small bug fixes around handling deleted files (#17236) --- network/cloud_sync/icloud.m | 11 +++++------ tasks/task_cloudsync.c | 7 +++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/network/cloud_sync/icloud.m b/network/cloud_sync/icloud.m index a5a2ce2b23..86f605af01 100644 --- a/network/cloud_sync/icloud.m +++ b/network/cloud_sync/icloud.m @@ -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 * _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; } diff --git a/tasks/task_cloudsync.c b/tasks/task_cloudsync.c index 5b51504d3f..ed8549cf8c 100644 --- a/tasks/task_cloudsync.c +++ b/tasks/task_cloudsync.c @@ -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