Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix/fp-word] Fix Word FileProvider issue #574

Merged
merged 3 commits into from
Dec 11, 2019
Merged
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 ios-sdk
Submodule ios-sdk updated 27 files
+8 −0 CHANGELOG.md
+42 −2 ownCloudSDK.xcodeproj/project.pbxproj
+42 −0 ownCloudSDK/Authentication/Browser Session/OCAuthenticationBrowserSession.h
+55 −0 ownCloudSDK/Authentication/Browser Session/OCAuthenticationBrowserSession.m
+38 −0 ownCloudSDK/Authentication/Browser Session/UIWebView/OCAuthenticationBrowserSessionUIWebView.h
+178 −0 ownCloudSDK/Authentication/Browser Session/UIWebView/OCAuthenticationBrowserSessionUIWebView.m
+4 −0 ownCloudSDK/Authentication/OCAuthenticationMethodOAuth2.h
+57 −3 ownCloudSDK/Authentication/OCAuthenticationMethodOAuth2.m
+2 −2 ownCloudSDK/Core/Connection Status/Network Path Monitor/OCCoreNetworkPathMonitorSignalProvider.m
+3 −0 ownCloudSDK/Core/FileProvider/OCSyncAction+FileProvider.m
+8 −2 ownCloudSDK/Core/Sharing/OCCore+Sharing.m
+16 −1 ownCloudSDK/Core/Sync/Actions/CreateFolder/OCCore+CommandCreateFolder.m
+1 −0 ownCloudSDK/Core/Sync/Actions/OCSyncAction.h
+24 −1 ownCloudSDK/Core/Sync/Actions/OCSyncAction.m
+7 −9 ownCloudSDK/Core/Sync/Actions/Upload/OCCore+CommandLocalImport.m
+2 −2 ownCloudSDK/Core/Sync/Actions/Upload/OCSyncActionUpload.m
+2 −1 ownCloudSDK/Core/Sync/OCCore+SyncEngine.h
+15 −2 ownCloudSDK/Core/Sync/OCCore+SyncEngine.m
+29 −1 ownCloudSDK/Item/OCItem.m
+37 −0 ownCloudSDK/OCFeatureAvailability.h
+1 −1 ownCloudSDK/Settings/Sources/OCClassSettingsFlatSourceEnvironment.m
+3 −0 ownCloudSDK/Vaults/OCVault+Internal.h
+9 −0 ownCloudSDK/Vaults/OCVault+Internal.m
+9 −1 ownCloudSDK/Vaults/OCVault.h
+7 −0 ownCloudSDK/Vaults/OCVault.m
+1 −0 ownCloudSDK/ownCloudSDK.h
+3 −0 ownCloudUI/openssl/framework/openssl.xcodeproj/project.pbxproj
149 changes: 93 additions & 56 deletions ownCloud File Provider/FileProviderExtension.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#import "NSError+MessageResolution.h"

@interface FileProviderExtension ()
{
NSFileCoordinator *_fileCoordinator;
}

@property (nonatomic, readonly, strong) NSFileManager *fileManager;

Expand All @@ -40,6 +43,8 @@ - (instancetype)init
{
NSDictionary *bundleInfoDict = [[NSBundle bundleForClass:[FileProviderExtension class]] infoDictionary];

_fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];

OCCoreManager.sharedCoreManager.memoryConfiguration = OCCoreMemoryConfigurationMinimum;

OCAppIdentity.sharedAppIdentity.appIdentifierPrefix = bundleInfoDict[@"OCAppIdentifierPrefix"];
Expand All @@ -59,10 +64,15 @@ - (instancetype)init

- (void)dealloc
{
OCLogDebug(@"Deallocating FileProvider %@", self);

[_fileCoordinator cancel];

[self removeObserver:self forKeyPath:@"domain" context:(__bridge void *)self];

if (_core != nil)
{
OCLogDebug(@"Returning OCCore for FileProvider %@", self);
[[OCCoreManager sharedCoreManager] returnCoreForBookmark:self.bookmark completionHandler:nil];
}
}
Expand Down Expand Up @@ -130,13 +140,13 @@ - (NSFileProviderItem)itemForIdentifier:(NSFileProviderItemIdentifier)identifier
}
});

// OCLogDebug(@"-itemForIdentifier:error: %@ => %@", identifier, item);

if ((item == nil) && (returnError == nil))
{
returnError = [NSError fileProviderErrorForNonExistentItemWithIdentifier:identifier];
}

// OCLogDebug(@"-itemForIdentifier:error: %@ => %@ / %@", identifier, item, returnError);

if (outError != NULL)
{
*outError = [returnError translatedError];
Expand Down Expand Up @@ -513,80 +523,105 @@ - (void)deleteItemWithIdentifier:(NSFileProviderItemIdentifier)itemIdentifier co
- (void)importDocumentAtURL:(NSURL *)fileURL toParentItemIdentifier:(NSFileProviderItemIdentifier)parentItemIdentifier completionHandler:(void (^)(NSFileProviderItem _Nullable, NSError * _Nullable))completionHandler
{
NSError *error = nil;
BOOL isImportingFromVault = NO;
BOOL importByCopying = NO;
NSString *importFileName = fileURL.lastPathComponent;
OCItem *parentItem;
BOOL stopAccess = NO;

FPLogCmdBegin(@"Import", @"Start of importDocumentAtURL=%@, toParentItemIdentifier=%@", fileURL, parentItemIdentifier);
if ([fileURL startAccessingSecurityScopedResource])
{
stopAccess = YES;
}

// Detect import of documents from our own internal storage (=> used by Files.app for duplication of files)
isImportingFromVault = [fileURL.path hasPrefix:self.core.vault.filesRootURL.path];
FPLogCmdBegin(@"Import", @"Start of importDocumentAtURL=%@, toParentItemIdentifier=%@, attributes=%@", fileURL, parentItemIdentifier, [NSFileManager.defaultManager attributesOfItemAtPath:fileURL.path error:nil]);

if (isImportingFromVault)
{
NSFileProviderItemIdentifier sourceItemIdentifier;
NSFileProviderItem sourceItem;
[_fileCoordinator coordinateReadingItemAtURL:fileURL options:NSFileCoordinatorReadingWithoutChanges|NSFileCoordinatorReadingForUploading error:&error byAccessor:^(NSURL * _Nonnull readURL) {
NSError *error = nil;
BOOL isImportingFromVault = NO;
BOOL importByCopying = NO;
NSString *importFileName = readURL.lastPathComponent;
OCItem *parentItem;

// Determine source item
if (((sourceItemIdentifier = [self persistentIdentifierForItemAtURL:fileURL]) != nil) &&
((sourceItem = [self itemForIdentifier:sourceItemIdentifier error:nil]) != nil))
{
importByCopying = YES;
}
}
FPLogCmd(@"Coordinated read of readURL=%@, toParentItemIdentifier=%@, attributes=%@", readURL, parentItemIdentifier, [NSFileManager.defaultManager attributesOfItemAtPath:readURL.path error:nil]);

if ((parentItem = (OCItem *)[self itemForIdentifier:parentItemIdentifier error:&error]) != nil)
{
// Detect name collissions
OCItem *existingItem;
// Detect import of documents from our own internal storage (=> used by Files.app for duplication of files)
isImportingFromVault = [readURL.path hasPrefix:self.core.vault.filesRootURL.path];

if ((existingItem = [self.core cachedItemInParent:parentItem withName:importFileName isDirectory:NO error:NULL]) != nil)
if (isImportingFromVault)
{
// Return collission error
FPLogCmd(@"Completed with collission with existingItem=%@ (local)", existingItem);
completionHandler(nil, [NSError fileProviderErrorForCollisionWithItem:existingItem]);
return;
NSFileProviderItemIdentifier sourceItemIdentifier;
NSFileProviderItem sourceItem;

// Determine source item
if (((sourceItemIdentifier = [self persistentIdentifierForItemAtURL:readURL]) != nil) &&
((sourceItem = [self itemForIdentifier:sourceItemIdentifier error:nil]) != nil))
{
importByCopying = YES;
}
}

FPLogCmd(@"Importing %@ at %@ fromURL %@", importFileName, parentItem, fileURL);
if ((parentItem = (OCItem *)[self itemForIdentifier:parentItemIdentifier error:&error]) != nil)
{
// Detect name collissions
OCItem *existingItem;

// Import item
[self.core importItemNamed:importFileName at:parentItem fromURL:fileURL isSecurityScoped:YES options:@{
OCCoreOptionImportByCopying : @(importByCopying)
} placeholderCompletionHandler:^(NSError *error, OCItem *item) {
FPLogCmd(@"Completed with placeholderItem=%@, error=%@", item, error);
completionHandler(item, [error translatedError]);
} resultHandler:^(NSError *error, OCCore *core, OCItem *item, id parameter) {
if ([error.domain isEqual:OCHTTPStatusErrorDomain] && (error.code == OCHTTPStatusCodePRECONDITION_FAILED))
if ((existingItem = [self.core cachedItemInParent:parentItem withName:importFileName isDirectory:NO error:NULL]) != nil)
{
// Collission: file already exists
if ((parameter != nil) && ([parameter isKindOfClass:[OCItem class]]))
// Return collission error
FPLogCmd(@"Completed with collission with existingItem=%@ (local)", existingItem);
completionHandler(nil, [NSError fileProviderErrorForCollisionWithItem:existingItem]);
return;
}

FPLogCmd(@"Importing %@ at %@ readURL %@", importFileName, parentItem, readURL);

// Import item
[self.core importItemNamed:importFileName at:parentItem fromURL:readURL isSecurityScoped:YES options:@{
OCCoreOptionImportByCopying : @(importByCopying)
} placeholderCompletionHandler:^(NSError *error, OCItem *item) {
FPLogCmd(@"Completed with placeholderItem=%@, error=%@", item, error);
completionHandler(item, [error translatedError]);
} resultHandler:^(NSError *error, OCCore *core, OCItem *item, id parameter) {
if ([error.domain isEqual:OCHTTPStatusErrorDomain] && (error.code == OCHTTPStatusCodePRECONDITION_FAILED))
{
OCItem *placeholderItem = (OCItem *)parameter;
// Collission: file already exists
if ((parameter != nil) && ([parameter isKindOfClass:[OCItem class]]))
{
OCItem *placeholderItem = (OCItem *)parameter;

// TODO (defunct):
// Upload errors (such as NSFileProviderErrorInsufficientQuota) should be handled
// with a subsequent update to the [placeholder] item, setting its uploadingError property.
// TODO (defunct):
// Upload errors (such as NSFileProviderErrorInsufficientQuota) should be handled
// with a subsequent update to the [placeholder] item, setting its uploadingError property.

// TODO (not yet implemented):
// Upload errors should not prevent creating or importing a document, because they
// can be resolved at a later date (for example, when the user has quota again.)
// TODO (not yet implemented):
// Upload errors should not prevent creating or importing a document, because they
// can be resolved at a later date (for example, when the user has quota again.)

if (placeholderItem.isPlaceholder)
{
FPLogCmd(@"Completed with fileAlreadyExistsAs=%@", placeholderItem);
[placeholderItem setUploadingError:[NSError fileProviderErrorForCollisionWithItem:placeholderItem]];
if (placeholderItem.isPlaceholder)
{
FPLogCmd(@"Completed with fileAlreadyExistsAs=%@", placeholderItem);
[placeholderItem setUploadingError:[NSError fileProviderErrorForCollisionWithItem:placeholderItem]];
}
}
}
}
}];
}
else
}];
}
else
{
FPLogCmd(@"Completed with parentItem=%@ not found, error=%@", parentItem, error);
completionHandler(nil, error);
}

if (stopAccess)
{
[readURL stopAccessingSecurityScopedResource];
}
}];

FPLogCmd(@"File Coordinator returned with error=%@", error);

if (error != nil)
{
FPLogCmd(@"Completed with parentItem=%@ not found, error=%@", parentItem, error);
completionHandler(nil, error);
}

}

- (void)setFavoriteRank:(NSNumber *)favoriteRank forItemIdentifier:(NSFileProviderItemIdentifier)itemIdentifier completionHandler:(void (^)(NSFileProviderItem _Nullable, NSError * _Nullable))completionHandler
Expand Down Expand Up @@ -851,6 +886,8 @@ - (OCCore *)core
{
if (self.bookmark != nil)
{
OCLogDebug(@"Requesting OCCore for FileProvider %@", self);

OCSyncExec(waitForCore, {
[[OCCoreManager sharedCoreManager] requestCoreForBookmark:self.bookmark setup:^(OCCore *core, NSError *error) {
self->_core = core;
Expand Down
7 changes: 5 additions & 2 deletions ownCloud/Client/ClientRootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,17 @@ class ClientRootViewController: UITabBarController, UINavigationControllerDelega

self.tabBar.isTranslucent = false

// Add tab bar icons
Theme.shared.add(tvgResourceFor: "folder")
Theme.shared.add(tvgResourceFor: "owncloud-logo")
Theme.shared.add(tvgResourceFor: "status-flash")

filesNavigationController = ThemeNavigationController()
filesNavigationController?.delegate = self
filesNavigationController?.navigationBar.isTranslucent = false
filesNavigationController?.tabBarItem.title = "Browse".localized
filesNavigationController?.tabBarItem.image = Theme.shared.image(for: "folder", size: folderButtonsSize)

Theme.shared.add(tvgResourceFor: "status-flash")

activityViewController = ClientActivityViewController()
activityNavigationController = ThemeNavigationController(rootViewController: activityViewController!)
activityNavigationController?.tabBarItem.title = "Status".localized
Expand Down