|
@@ -61,145 +61,143 @@
|
|
- (void)readFolder:(NSString *)serverUrl selector:(NSString *)selector
|
|
- (void)readFolder:(NSString *)serverUrl selector:(NSString *)selector
|
|
{
|
|
{
|
|
OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:nil withUserID:nil withPassword:nil withUrl:nil];
|
|
OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:nil withUserID:nil withPassword:nil withUrl:nil];
|
|
- [ocNetworking readFolder:serverUrl depth:@"1" account:appDelegate.activeAccount success:^(NSString *account, NSArray *metadatas, tableMetadata *metadataFolder) {
|
|
|
|
|
|
+ [ocNetworking readFolderWithAccount:appDelegate.activeAccount serverUrl:serverUrl depth:@"1" completion:^(NSString *account, NSArray *metadatas, tableMetadata *metadataFolder, NSString *message, NSInteger errorCode) {
|
|
|
|
|
|
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
|
|
|
|
- if (tableAccount == nil) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Add/update self Folder
|
|
|
|
- if (!metadataFolder || !metadatas || [metadatas count] == 0) {
|
|
|
|
- if (metadataFolder.serverUrl != nil) {
|
|
|
|
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadataFolder.serverUrl fileID:nil action:k_action_NULL];
|
|
|
|
- }
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Add metadata and update etag Directory
|
|
|
|
- (void)[[NCManageDatabase sharedInstance] addMetadata:metadataFolder];
|
|
|
|
- [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:serverUrl serverUrlTo:nil etag:metadataFolder.etag fileID:metadataFolder.fileID encrypted:metadataFolder.e2eEncrypted account:account];
|
|
|
|
-
|
|
|
|
- // reload folder ../ *
|
|
|
|
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadataFolder.serverUrl fileID:nil action:k_action_NULL];
|
|
|
|
-
|
|
|
|
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
|
|
|
|
-
|
|
|
|
- NSMutableArray *metadatasForVerifyChange = [NSMutableArray new];
|
|
|
|
- NSMutableArray *addMetadatas = [NSMutableArray new];
|
|
|
|
|
|
+ if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
|
|
|
|
|
|
- NSArray *recordsInSessions = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND session != ''", account, serverUrl] sorted:nil ascending:NO];
|
|
|
|
|
|
+ tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
|
|
|
|
+ if (tableAccount == nil) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
- // ----- Test : (DELETE) -----
|
|
|
|
|
|
+ // Add/update self Folder
|
|
|
|
+ if (!metadataFolder || !metadatas || [metadatas count] == 0) {
|
|
|
|
+ if (metadataFolder.serverUrl != nil) {
|
|
|
|
+ [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadataFolder.serverUrl fileID:nil action:k_action_NULL];
|
|
|
|
+ }
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
- NSMutableArray *metadatasNotPresents = [NSMutableArray new];
|
|
|
|
|
|
+ // Add metadata and update etag Directory
|
|
|
|
+ (void)[[NCManageDatabase sharedInstance] addMetadata:metadataFolder];
|
|
|
|
+ [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:serverUrl serverUrlTo:nil etag:metadataFolder.etag fileID:metadataFolder.fileID encrypted:metadataFolder.e2eEncrypted account:account];
|
|
|
|
|
|
- NSArray *tableMetadatas = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND session == ''", account, serverUrl] sorted:nil ascending:NO];
|
|
|
|
|
|
+ // reload folder ../ *
|
|
|
|
+ [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadataFolder.serverUrl fileID:nil action:k_action_NULL];
|
|
|
|
|
|
- for (tableMetadata *record in tableMetadatas) {
|
|
|
|
|
|
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
|
|
|
|
|
|
- BOOL fileIDFound = NO;
|
|
|
|
|
|
+ NSMutableArray *metadatasForVerifyChange = [NSMutableArray new];
|
|
|
|
+ NSMutableArray *addMetadatas = [NSMutableArray new];
|
|
|
|
|
|
- for (tableMetadata *metadata in metadatas) {
|
|
|
|
-
|
|
|
|
- if ([record.fileID isEqualToString:metadata.fileID]) {
|
|
|
|
- fileIDFound = YES;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ NSArray *recordsInSessions = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND session != ''", account, serverUrl] sorted:nil ascending:NO];
|
|
|
|
|
|
- if (!fileIDFound)
|
|
|
|
- [metadatasNotPresents addObject:record];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // delete metadata not present
|
|
|
|
- for (tableMetadata *metadata in metadatasNotPresents) {
|
|
|
|
|
|
+ // ----- Test : (DELETE) -----
|
|
|
|
+
|
|
|
|
+ NSMutableArray *metadatasNotPresents = [NSMutableArray new];
|
|
|
|
|
|
- [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID] error:nil];
|
|
|
|
|
|
+ NSArray *tableMetadatas = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND session == ''", account, serverUrl] sorted:nil ascending:NO];
|
|
|
|
|
|
- if (metadata.directory && serverUrl) {
|
|
|
|
|
|
+ for (tableMetadata *record in tableMetadatas) {
|
|
|
|
|
|
- NSString *dirForDelete = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileName];
|
|
|
|
|
|
+ BOOL fileIDFound = NO;
|
|
|
|
+
|
|
|
|
+ for (tableMetadata *metadata in metadatas) {
|
|
|
|
+
|
|
|
|
+ if ([record.fileID isEqualToString:metadata.fileID]) {
|
|
|
|
+ fileIDFound = YES;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:dirForDelete account:metadata.account];
|
|
|
|
|
|
+ if (!fileIDFound)
|
|
|
|
+ [metadatasNotPresents addObject:record];
|
|
}
|
|
}
|
|
|
|
|
|
- [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
|
|
|
|
- [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
|
|
|
|
- [[NCManageDatabase sharedInstance] deletePhotosWithFileID:metadata.fileID];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
- if ([metadatasNotPresents count] > 0)
|
|
|
|
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl fileID:nil action:k_action_NULL];
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- // ----- Test : (MODIFY) -----
|
|
|
|
-
|
|
|
|
- for (tableMetadata *metadata in metadatas) {
|
|
|
|
-
|
|
|
|
- // RECURSIVE DIRECTORY MODE
|
|
|
|
- if (metadata.directory) {
|
|
|
|
-
|
|
|
|
- // Verify if do not exists this Metadata
|
|
|
|
- tableMetadata *result = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
|
|
|
|
-
|
|
|
|
- if (!result)
|
|
|
|
- (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
|
|
|
|
-
|
|
|
|
- [self readFolder:[CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileName] selector:selector];
|
|
|
|
|
|
+ // delete metadata not present
|
|
|
|
+ for (tableMetadata *metadata in metadatasNotPresents) {
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID] error:nil];
|
|
|
|
|
|
- if ([selector isEqualToString:selectorReadFolderWithDownload]) {
|
|
|
|
|
|
+ if (metadata.directory && serverUrl) {
|
|
|
|
|
|
- // It's in session
|
|
|
|
- BOOL recordInSession = NO;
|
|
|
|
- for (tableMetadata *record in recordsInSessions) {
|
|
|
|
- if ([record.fileID isEqualToString:metadata.fileID]) {
|
|
|
|
- recordInSession = YES;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ NSString *dirForDelete = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileName];
|
|
|
|
|
|
- if (recordInSession)
|
|
|
|
- continue;
|
|
|
|
-
|
|
|
|
- // Ohhhh INSERT
|
|
|
|
- [metadatasForVerifyChange addObject:metadata];
|
|
|
|
|
|
+ [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:dirForDelete account:metadata.account];
|
|
}
|
|
}
|
|
|
|
|
|
- if ([selector isEqualToString:selectorReadFolder]) {
|
|
|
|
|
|
+ [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
|
|
|
|
+ [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
|
|
|
|
+ [[NCManageDatabase sharedInstance] deletePhotosWithFileID:metadata.fileID];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
+ if ([metadatasNotPresents count] > 0)
|
|
|
|
+ [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl fileID:nil action:k_action_NULL];
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // ----- Test : (MODIFY) -----
|
|
|
|
+
|
|
|
|
+ for (tableMetadata *metadata in metadatas) {
|
|
|
|
+
|
|
|
|
+ // RECURSIVE DIRECTORY MODE
|
|
|
|
+ if (metadata.directory) {
|
|
|
|
|
|
// Verify if do not exists this Metadata
|
|
// Verify if do not exists this Metadata
|
|
tableMetadata *result = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
|
|
tableMetadata *result = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
|
|
|
|
|
|
if (!result)
|
|
if (!result)
|
|
- [addMetadatas addObject:metadata];
|
|
|
|
|
|
+ (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
|
|
|
|
+
|
|
|
|
+ [self readFolder:[CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileName] selector:selector];
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ if ([selector isEqualToString:selectorReadFolderWithDownload]) {
|
|
|
|
+
|
|
|
|
+ // It's in session
|
|
|
|
+ BOOL recordInSession = NO;
|
|
|
|
+ for (tableMetadata *record in recordsInSessions) {
|
|
|
|
+ if ([record.fileID isEqualToString:metadata.fileID]) {
|
|
|
|
+ recordInSession = YES;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (recordInSession)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ // Ohhhh INSERT
|
|
|
|
+ [metadatasForVerifyChange addObject:metadata];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ([selector isEqualToString:selectorReadFolder]) {
|
|
|
|
+
|
|
|
|
+ // Verify if do not exists this Metadata
|
|
|
|
+ tableMetadata *result = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
|
|
|
|
+
|
|
|
|
+ if (!result)
|
|
|
|
+ [addMetadatas addObject:metadata];
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
- if ([addMetadatas count] > 0)
|
|
|
|
- (void)[[NCManageDatabase sharedInstance] addMetadatas:addMetadatas];
|
|
|
|
-
|
|
|
|
- if ([metadatasForVerifyChange count] > 0)
|
|
|
|
- [self verifyChangeMedatas:metadatasForVerifyChange serverUrl:serverUrl account:account withDownload:YES];
|
|
|
|
- });
|
|
|
|
|
|
+
|
|
|
|
+ if ([addMetadatas count] > 0)
|
|
|
|
+ (void)[[NCManageDatabase sharedInstance] addMetadatas:addMetadatas];
|
|
|
|
+
|
|
|
|
+ if ([metadatasForVerifyChange count] > 0)
|
|
|
|
+ [self verifyChangeMedatas:metadatasForVerifyChange serverUrl:serverUrl account:account withDownload:YES];
|
|
|
|
+ });
|
|
|
|
|
|
- } failure:^(NSString *account, NSString *message, NSInteger errorCode) {
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- // Folder not present, remove it
|
|
|
|
- if (errorCode == 404) {
|
|
|
|
- [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:serverUrl account:account];
|
|
|
|
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl fileID:nil action:k_action_NULL];
|
|
|
|
|
|
+ // Folder not present, remove it
|
|
|
|
+ if (errorCode == 404) {
|
|
|
|
+ [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:serverUrl account:account];
|
|
|
|
+ [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl fileID:nil action:k_action_NULL];
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
- return;
|
|
|
|
}];
|
|
}];
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
#pragma --------------------------------------------------------------------------------------------
|