Skip to content

Commit 0794246

Browse files
committed
- OCCore+CommandLocalImport: add convenience shortcut/detour to reportLocalModificationOfItem when OCConnectionOptionForceReplaceKey is set
- OCSyncActionUpload: fix issue where "Replace" didn't work, could end up with two items in the database for a single item on the server
1 parent e5e30d4 commit 0794246

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

ownCloudSDK/Core/Sync/Actions/Upload/OCCore+CommandLocalImport.m

+17
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#import "OCSyncActionUpload.h"
2121
#import "OCItem+OCFileURLMetadata.h"
2222
#import "OCCore+NameConflicts.h"
23+
#import "OCCore+Internal.h"
2324

2425
#import <CoreServices/CoreServices.h>
2526

@@ -66,6 +67,22 @@ - (nullable NSProgress *)importFileNamed:(nullable NSString *)newFileName at:(OC
6667
}
6768
}
6869

70+
// Replace existing
71+
NSNumber *forceReplace = options[OCConnectionOptionForceReplaceKey];
72+
if ((forceReplace != nil) && forceReplace.boolValue)
73+
{
74+
NSError *error = nil;
75+
OCItem *existingItem = nil;
76+
77+
existingItem = [self cachedItemInParentLocation:parentItem.location withName:newFileName isDirectory:NO error:&error];
78+
79+
if (existingItem != nil)
80+
{
81+
// Schedule as local modification instead
82+
return ([self reportLocalModificationOfItem:existingItem parentItem:parentItem withContentsOfFileAtURL:inputFileURL isSecurityScoped:isSecurityScoped options:options placeholderCompletionHandler:placeholderCompletionHandler resultHandler:resultHandler]);
83+
}
84+
}
85+
6986
// Create placeholder item and fill fields required by -[NSFileProviderExtension importDocumentAtURL:toParentItemIdentifier:completionHandler:] completion handler
7087
placeholderItem = [OCItem placeholderItemOfType:OCItemTypeFile];
7188

ownCloudSDK/Core/Sync/Actions/Upload/OCSyncActionUpload.m

+7
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,13 @@ - (NSError *)resolveIssue:(OCSyncIssue *)issue withChoice:(OCSyncIssueChoice *)c
510510
options[OCConnectionOptionForceReplaceKey] = @(YES);
511511
self.options = options;
512512

513+
OCItem *preExistingItem = [self _preExistingItem];
514+
if (preExistingItem != nil)
515+
{
516+
// Remove (possible) duplicate item from database
517+
syncContext.removedItems = @[ preExistingItem ];
518+
}
519+
513520
syncContext.updateStoredSyncRecordAfterItemUpdates = YES;
514521

515522
[syncContext transitionToState:OCSyncRecordStateReady withWaitConditions:nil];

0 commit comments

Comments
 (0)