OS X shell: Don't allow sharing sync roots #3505
authorJocelyn Turcotte <jturcotte@woboq.com>
Thu, 14 Jan 2016 15:24:29 +0000 (16:24 +0100)
committerJocelyn Turcotte <jturcotte@woboq.com>
Thu, 14 Jan 2016 15:25:19 +0000 (16:25 +0100)
shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/FinderSync.h
shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/FinderSync.m

index 749f8493102e8ed5b6a52c63878d232fc5510288..a1356045b7d317446b067c28de22503398a70d3b 100644 (file)
@@ -21,7 +21,6 @@
 {
        SyncClientProxy *_syncClientProxy;
        NSMutableSet *_registeredDirectories;
-       NSMutableSet *_requestedUrls;
        NSString *_shareMenuTitle;
 }
 
index 6273b5032a5f6c20ced8091d443a1d8424c575ad..440af7e33226eb14deae87b0a104144b1cd0fd8b 100644 (file)
 
 - (NSMenu *)menuForMenuKind:(FIMenuKind)whichMenu
 {
-       if (_shareMenuTitle) {
+       FIFinderSyncController *syncController = [FIFinderSyncController defaultController];
+       NSMutableSet *rootPaths = [[NSMutableSet alloc] init];
+       [syncController.directoryURLs enumerateObjectsUsingBlock: ^(id obj, BOOL *stop) {
+               [rootPaths addObject:[obj path]];
+       }];
+
+       // The server doesn't support sharing a root directory so do not show the option in this case.
+       // It is still possible to get a problematic sharing by selecting both the root and a child,
+       // but this is so complicated to do and meaningless that it's not worth putting this check
+       // also in shareMenuAction.
+       __block BOOL onlyRootsSelected = YES;
+       [syncController.selectedItemURLs enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
+               if (![rootPaths member:[obj path]]) {
+                       onlyRootsSelected = NO;
+                       *stop = YES;
+               }
+       }];
+
+       if (_shareMenuTitle && !onlyRootsSelected) {
                NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
                [menu addItemWithTitle:_shareMenuTitle action:@selector(shareMenuAction:) keyEquivalent:@"title"];