Skip to content
Open
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
2 changes: 1 addition & 1 deletion ownCloudSDK/Authentication/OCAuthenticationMethodOAuth2.m
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ - (void)_refreshTokenForConnection:(OCConnection *)connection availabilityHandle
{
__weak OCAuthenticationMethodOAuth2 *weakSelf = self;

OCLockRequest *lockRequest = [[OCLockRequest alloc] initWithResourceIdentifier:[NSString stringWithFormat:@"authentication-data-update:%@", connection.bookmark.uuid.UUIDString] acquiredHandler:^(NSError * _Nullable error, OCLock * _Nullable lock) {
OCLockRequest *lockRequest = [[OCLockRequest alloc] initWithResourceIdentifier:[NSString stringWithFormat:@"authentication-data-update:%@", connection.bookmark.uuidString] acquiredHandler:^(NSError * _Nullable error, OCLock * _Nullable lock) {
// Wait for exclusive lock on authentication data before performing the refresh
[weakSelf __refreshTokenForConnection:connection availabilityHandler:^(NSError *error, BOOL authenticationIsAvailable) {
// Invoke original availabilityHandler
Expand Down
1 change: 1 addition & 0 deletions ownCloudSDK/Bookmark/OCBookmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface OCBookmark : NSObject <NSSecureCoding, NSCopying>

@property(readonly) OCBookmarkUUID uuid; //!< UUID uniquely identifying the bookmark
@property(readonly,nonatomic) OCBookmarkUUIDString uuidString; //!< String version of .uuid (cached!)

@property(strong,nullable) NSString *name; //!< Name of the server
@property(strong,nullable) NSURL *url; //!< URL to use to connect to the server
Expand Down
19 changes: 15 additions & 4 deletions ownCloudSDK/Bookmark/OCBookmark.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#import <UIKit/UIKit.h>
#endif /* TARGET_OS_IOS */

@interface OCBookmark ()
@implementation OCBookmark
{
OCIPCNotificationName _coreUpdateNotificationName;
OCIPCNotificationName _bookmarkAuthUpdateNotificationName;
Expand All @@ -40,10 +40,9 @@ @interface OCBookmark ()
NSString *_lastUsername;

NSString *_lastDescription;
}
@end

@implementation OCBookmark
OCBookmarkUUIDString _uuidString;
}

@synthesize uuid = _uuid;

Expand Down Expand Up @@ -119,6 +118,17 @@ - (NSData *)bookmarkData
return ([NSKeyedArchiver archivedDataWithRootObject:self]);
}

#pragma mark - UUID string
- (OCBookmarkUUIDString)uuidString
{
if (_uuidString == nil)
{
_uuidString = _uuid.UUIDString;
}

return (_uuidString);
}

#pragma mark - Keychain access
- (NSData *)authenticationData
{
Expand Down Expand Up @@ -462,6 +472,7 @@ - (instancetype)initWithCoder:(NSCoder *)decoder
if ((self = [self init]) != nil)
{
_uuid = [decoder decodeObjectOfClass:NSUUID.class forKey:@"uuid"];
_uuidString = nil;

_name = [decoder decodeObjectOfClass:NSString.class forKey:@"name"];
_url = [decoder decodeObjectOfClass:NSURL.class forKey:@"url"];
Expand Down
2 changes: 1 addition & 1 deletion ownCloudSDK/Connection/OCConnection+Upload.m
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ - (OCProgress *)_continueTusJob:(OCTUSJob *)tusJob lastTask:(NSString *)lastTask
}

tusProgress = [[OCProgress alloc] initWithPath:((self.bookmark.uuid != nil) ?
@[ OCProgressPathElementIdentifierCoreRoot, self.bookmark.uuid.UUIDString, OCProgressPathElementIdentifierCoreConnectionPath, tusJob.trackingID ] :
@[ OCProgressPathElementIdentifierCoreRoot, self.bookmark.uuidString, OCProgressPathElementIdentifierCoreConnectionPath, tusJob.trackingID ] :
@[])
progress:actionProgress];
}
Expand Down
9 changes: 8 additions & 1 deletion ownCloudSDK/Connection/OCConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ - (instancetype)initWithBookmark:(OCBookmark *)bookmark
{
if ((self = [super init]) != nil)
{
_partitionID = bookmark.uuid.UUIDString;
_partitionID = bookmark.uuidString;

self.bookmark = bookmark;

Expand Down Expand Up @@ -2076,6 +2076,13 @@ - (void)_handleRetrieveItemListAtPathResult:(OCHTTPRequest *)request error:(NSEr
{
event.error = errors.firstObject;
}
else if (items != nil)
{
OCBookmarkUUIDString bookmarkUUIDString = self.bookmark.uuidString;
for (OCItem *item in items) {
item.bookmarkUUID = bookmarkUUIDString;
}
}

switch (eventType)
{
Expand Down
2 changes: 1 addition & 1 deletion ownCloudSDK/Core/ItemList/OCCore+ItemList.m
Original file line number Diff line number Diff line change
Expand Up @@ -1957,7 +1957,7 @@ - (void)_coordinatedScanForChanges

if (_scanForChangesLockRequest == nil) // do not make second request if another one is already in progress - do nothing in that case
{
_scanForChangesLockRequest = [[OCLockRequest alloc] initWithResourceIdentifier:[OCLockResourceIdentifierCoreUpdateScan stringByAppendingFormat:@":%@",_bookmark.uuid.UUIDString] tryAcquireHandler:^(NSError * _Nullable error, OCLock * _Nullable lock) {
_scanForChangesLockRequest = [[OCLockRequest alloc] initWithResourceIdentifier:[OCLockResourceIdentifierCoreUpdateScan stringByAppendingFormat:@":%@",_bookmark.uuidString] tryAcquireHandler:^(NSError * _Nullable error, OCLock * _Nullable lock) {
OCCore *core;

if ((core = weakSelf) != nil)
Expand Down
2 changes: 1 addition & 1 deletion ownCloudSDK/Core/ItemPolicies/OCCore+ItemPolicies.m
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ - (void)_updatePolicyProcessors
#pragma mark - IPC
- (OCIPCNotificationName)itemPoliciesChangedNotificationName
{
return ([OCIPCNotificationNameItemPoliciesChangedPrefix stringByAppendingFormat:@".%@", self.bookmark.uuid.UUIDString]);
return ([OCIPCNotificationNameItemPoliciesChangedPrefix stringByAppendingFormat:@".%@", self.bookmark.uuidString]);
}

- (void)setupItemPolicies
Expand Down
4 changes: 2 additions & 2 deletions ownCloudSDK/Core/OCCore.m
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ - (instancetype)initWithBookmark:(OCBookmark *)bookmark

_preferredChecksumAlgorithm = OCChecksumAlgorithmIdentifierSHA1;

_eventHandlerIdentifier = [@"OCCore-" stringByAppendingString:_bookmark.uuid.UUIDString];
_eventHandlerIdentifier = [@"OCCore-" stringByAppendingString:_bookmark.uuidString];
_pendingThumbnailRequests = [NSMutableDictionary new];

_ipNotificationCenter = OCIPNotificationCenter.sharedNotificationCenter;
Expand Down Expand Up @@ -318,7 +318,7 @@ - (instancetype)initWithBookmark:(OCBookmark *)bookmark
}]);
}];

_activityManager = [[OCActivityManager alloc] initWithUpdateNotificationName:[@"OCCore.ActivityUpdate." stringByAppendingString:_bookmark.uuid.UUIDString]];
_activityManager = [[OCActivityManager alloc] initWithUpdateNotificationName:[@"OCCore.ActivityUpdate." stringByAppendingString:_bookmark.uuidString]];
_publishedActivitySyncRecordIDs = [NSMutableSet new];

_itemPolicies = [NSMutableArray new];
Expand Down
2 changes: 1 addition & 1 deletion ownCloudSDK/Core/Resources/Sources/OCResourceSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ - (instancetype)initWithCore:(OCCore *)core
if ((self = [super init]) != nil)
{
_core = core;
_eventHandlerIdentifier = [NSString stringWithFormat:@"%@-%@-%@", NSStringFromClass(self.class), self.identifier, core.bookmark.uuid.UUIDString];
_eventHandlerIdentifier = [NSString stringWithFormat:@"%@-%@-%@", NSStringFromClass(self.class), self.identifier, core.bookmark.uuidString];
}

return (self);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ - (instancetype)initWithParentItem:(OCItem *)parentItem folderName:(NSString *)f

if ((placeholderItem = [OCItem placeholderItemOfType:OCItemTypeCollection]) != nil)
{
placeholderItem.bookmarkUUID = self.core.bookmark.uuidString;
placeholderItem.parentFileID = parentItem.fileID;
placeholderItem.parentLocalID = parentItem.localID;
placeholderItem.driveID = parentItem.driveID;
Expand Down Expand Up @@ -73,7 +74,13 @@ - (void)preflightWithContext:(OCSyncContext *)syncContext

if ((placeholderCompletionHandler = self.ephermalParameters[OCCoreOptionPlaceholderCompletionHandler]) != nil)
{
placeholderCompletionHandler(nil, _placeholderItem);
OCItem *placeholderItem = _placeholderItem;

// Run completion handler only after database updates have been performed, so the returned item is immediately usable
[syncContext addContextActionsCompletionHandler:^{
placeholderCompletionHandler(nil, placeholderItem);
}];

self.ephermalParameters = nil;
}

Expand Down
6 changes: 6 additions & 0 deletions ownCloudSDK/Core/Sync/Context/OCSyncContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
@class OCSyncIssue;
@class OCWaitCondition;

typedef dispatch_block_t OCSyncContextActionsCompletionHandler;

NS_ASSUME_NONNULL_BEGIN

@interface OCSyncContext : NSObject
Expand Down Expand Up @@ -58,9 +60,13 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)eventHandlingContextWith:(OCSyncRecord *)syncRecord event:(OCEvent *)event;
+ (instancetype)waitConditionRecoveryContextWith:(OCSyncRecord *)syncRecord;

#pragma mark - Add objects
- (void)addWaitCondition:(OCWaitCondition *)waitCondition;
- (void)addSyncIssue:(OCSyncIssue *)syncIssue;

- (void)addContextActionsCompletionHandler:(OCSyncContextActionsCompletionHandler)completionHandler; //!< Adds a block to run after the sync context actions have been completed (f.ex. updates to the database have been completed)
- (void)runContextCompletionHandlers;

#pragma mark - State
- (void)transitionToState:(OCSyncRecordState)state withWaitConditions:(nullable NSArray <OCWaitCondition *> *)waitConditions; //!< Convenience method, calling the same method on .syncRecord, but also adding in .queuedWaitConditins and setting updateStoredSyncRecordAfterItemUpdates to YES.

Expand Down
37 changes: 32 additions & 5 deletions ownCloudSDK/Core/Sync/Context/OCSyncContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@
#import "OCSyncIssue.h"
#import "OCWaitConditionIssue.h"

@interface OCSyncContext ()
@implementation OCSyncContext
{
BOOL _canHandleErrors;
NSMutableArray <OCSyncContextActionsCompletionHandler> *_actionsCompletionHandler;
}

@end

@implementation OCSyncContext

+ (instancetype)preflightContextWithSyncRecord:(OCSyncRecord *)syncRecord
{
OCSyncContext *syncContext = [OCSyncContext new];
Expand Down Expand Up @@ -98,6 +95,36 @@ - (void)addSyncIssue:(OCSyncIssue *)syncIssue
[self addWaitCondition:[syncIssue makeWaitCondition]];
}

- (void)addContextActionsCompletionHandler:(OCSyncContextActionsCompletionHandler)completionHandler
{
@synchronized(self)
{
if (_actionsCompletionHandler == nil) {
_actionsCompletionHandler = [NSMutableArray new];
}

[_actionsCompletionHandler addObject:completionHandler];
}
}

- (void)runContextCompletionHandlers
{
NSMutableArray<OCSyncContextActionsCompletionHandler> *completionHandlers;

@synchronized (self)
{
completionHandlers = _actionsCompletionHandler;
_actionsCompletionHandler = nil;
}

if (completionHandlers == nil) { return; }

for (OCSyncContextActionsCompletionHandler completionHandler in completionHandlers)
{
completionHandler();
}
}

#pragma mark - State
- (void)transitionToState:(OCSyncRecordState)state withWaitConditions:(nullable NSArray <OCWaitCondition *> *)waitConditions
{
Expand Down
12 changes: 7 additions & 5 deletions ownCloudSDK/Core/Sync/OCCore+SyncEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ @implementation OCCore (SyncEngine)
#pragma mark - Setup & shutdown
- (OCIPCNotificationName)notificationNameForProcessSyncRecordsTriggerForProcessSession:(OCProcessSession *)processSession
{
return ([OCIPCNotificationNameProcessSyncRecordsBase stringByAppendingFormat:@":%@;%@", self.bookmark.uuid.UUIDString, processSession.bundleIdentifier]);
return ([OCIPCNotificationNameProcessSyncRecordsBase stringByAppendingFormat:@":%@;%@", self.bookmark.uuidString, processSession.bundleIdentifier]);
}

- (OCIPCNotificationName)notificationNameForProcessSyncRecordsTriggerAcknowledgementForProcessSession:(OCProcessSession *)processSession
{
return ([OCIPCNotificationNameProcessSyncRecordsBase stringByAppendingFormat:@":%@;%@;ack", self.bookmark.uuid.UUIDString, processSession.bundleIdentifier]);
return ([OCIPCNotificationNameProcessSyncRecordsBase stringByAppendingFormat:@":%@;%@;ack", self.bookmark.uuidString, processSession.bundleIdentifier]);
}

- (OCIPCNotificationName)notificationNameForSyncRecordsUpdate
{
return ([OCIPCNotificationNameUpdateSyncRecordsBase stringByAppendingFormat:@":%@", self.bookmark.uuid.UUIDString]);
return ([OCIPCNotificationNameUpdateSyncRecordsBase stringByAppendingFormat:@":%@", self.bookmark.uuidString]);
}

- (void)setupSyncEngine
Expand Down Expand Up @@ -363,7 +363,7 @@ - (void)submitSyncRecord:(OCSyncRecord *)record withPreflightResultHandler:(OCCo
OCLogDebug(@"record %@ added to database with error %@", record, blockError);

// Set sync record's progress path
record.progress.path = @[OCProgressPathElementIdentifierCoreRoot, self.bookmark.uuid.UUIDString, OCProgressPathElementIdentifierCoreSyncRecordPath, [record.recordID stringValue]];
record.progress.path = @[OCProgressPathElementIdentifierCoreRoot, self.bookmark.uuidString, OCProgressPathElementIdentifierCoreSyncRecordPath, [record.recordID stringValue]];

// Pre-flight
BOOL recordRemovedSelf = NO;
Expand Down Expand Up @@ -1614,6 +1614,8 @@ - (void)performSyncContextActions:(OCSyncContext *)syncContext
[self _scheduleNextWaitConditionRunForRecord:syncContext.syncRecord];

[self performUpdatesForAddedItems:syncContext.addedItems removedItems:syncContext.removedItems updatedItems:syncContext.updatedItems refreshLocations:syncContext.refreshLocations newSyncAnchor:nil beforeQueryUpdates:beforeQueryUpdateAction afterQueryUpdates:nil queryPostProcessor:nil skipDatabase:NO];

[syncContext runContextCompletionHandlers];
}

- (void)_scheduleNextWaitConditionRunForRecord:(OCSyncRecord *)syncRecord
Expand Down Expand Up @@ -2127,7 +2129,7 @@ - (void)restartStuckSyncRecordsWithFilter:(nullable NSArray<OCSyncRecord *> * _N

// Retrieve tracking IDs and total number of requests (incl. without tracking ID) from HTTP pipeline backend
OCSyncExec(trackingIDsRetrieved, {
[OCHTTPPipelineManager.sharedPipelineManager.backend retrieveActionTrackingIDsForPartition:self.connection.bookmark.uuid.UUIDString resultHandler:^(NSError * _Nullable error, NSSet<OCActionTrackingID> * _Nullable trackingIDs, NSNumber * _Nullable totalNumberOfRequestsInBackend) {
[OCHTTPPipelineManager.sharedPipelineManager.backend retrieveActionTrackingIDsForPartition:self.connection.bookmark.uuidString resultHandler:^(NSError * _Nullable error, NSSet<OCActionTrackingID> * _Nullable trackingIDs, NSNumber * _Nullable totalNumberOfRequestsInBackend) {
httpActionTrackingIDs = trackingIDs;
totalNumberOfRequestsInBackendForPartition = totalNumberOfRequestsInBackend;
OCTLogDebug(@[@"Health"], @"Found HTTP requests with trackingIDs=%@ total=%@ error=%@ (1)", trackingIDs, totalNumberOfRequestsInBackend, error);
Expand Down
2 changes: 1 addition & 1 deletion ownCloudSDK/Resource Management/OCCoreManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ - (void)_returnCoreForBookmark:(OCBookmark *)bookmark completionHandler:(dispatc
{
NSNumber *requestCount = _requestCountByUUID[bookmark.uuid];

OCLogDebug(@"core returned for bookmark %@ (%@)", bookmark.uuid.UUIDString, bookmark.name);
OCLogDebug(@"core returned for bookmark %@ (%@)", bookmark.uuidString, bookmark.name);

if (requestCount.integerValue > 0)
{
Expand Down
11 changes: 11 additions & 0 deletions ownCloudSDK/VFS/OCVFSCore.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ - (void)_relinquishCore:(OCCore *)core
return (self.rootNode);
}

// OCLogVerbose(@"Resolving %@: start", identifier);

if ((location = [[OCVaultLocation alloc] initWithVFSItemID:identifier]) != nil)
{
if (location.vfsNodeID != nil)
Expand All @@ -187,6 +189,8 @@ - (void)_relinquishCore:(OCCore *)core
{
item = (id<OCVFSItem>)[_nodesByID objectForKey:location.vfsNodeID];
}

// OCLogVerbose(@"Resolving %@: vfs node from _nodesByID: %@ -- location: %@", identifier, item, location);
}
else if (location.isVirtual)
{
Expand All @@ -195,6 +199,7 @@ - (void)_relinquishCore:(OCCore *)core
{
item = (id<OCVFSItem>)[self driveRootNodeForLocation:[[OCLocation alloc] initWithBookmarkUUID:location.bookmarkUUID driveID:location.driveID path:@"/"]];
}
// OCLogVerbose(@"Resolving %@: virtual node from driveRootNodeForLocation: %@ -- location: %@", identifier, item, location);
}
else
{
Expand Down Expand Up @@ -227,8 +232,14 @@ - (void)_relinquishCore:(OCCore *)core

}
}

// OCLogVerbose(@"Resolving %@: other item, via database: %@ -- location: %@", identifier, item, location);
}
}
else
{
// OCLogVerbose(@"Resolving %@: parsing as OCVaultLocation failed", identifier);
}

if (outError != NULL)
{
Expand Down
28 changes: 19 additions & 9 deletions ownCloudSDK/Vaults/OCVaultLocation.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#import "OCVaultLocation.h"
#import "OCVFSCore.h"
#import "OCMacros.h"

@implementation OCVaultLocation

Expand Down Expand Up @@ -86,16 +87,13 @@ - (instancetype)initWithVFSItemID:(OCVFSItemID)vfsItemID

- (OCVFSItemID)vfsItemID
{
if (_vfsNodeID != nil)
if ((_bookmarkUUID != nil) && (_driveID != nil) && _isVirtual)
{
if ((_bookmarkUUID != nil) && (_driveID != nil))
{
return ([[NSString alloc] initWithFormat:@"V\\%@\\%@", _bookmarkUUID, _driveID]);
}
else
{
return ([[NSString alloc] initWithFormat:@"V\\%@", _vfsNodeID]);
}
return ([[NSString alloc] initWithFormat:@"V\\%@\\%@", _bookmarkUUID, _driveID]);
}
else if (_vfsNodeID != nil)
{
return ([[NSString alloc] initWithFormat:@"V\\%@", _vfsNodeID]);
}
else if ((_bookmarkUUID != nil) && (_localID != nil))
{
Expand All @@ -105,4 +103,16 @@ - (OCVFSItemID)vfsItemID
return (nil);
}

#pragma mark - Description
- (NSString *)description
{
return ([NSString stringWithFormat:@"<%@: %p, isVirtual: %d%@%@%@%@>", NSStringFromClass(self.class), self,
_isVirtual,
OCExpandVar(bookmarkUUID),
OCExpandVar(driveID),
OCExpandVar(localID),
OCExpandVar(vfsNodeID)
]);
}

@end
Loading