0

I often run into troubles if my clients put the SQLite database on a managed folder. With managed folder I mean:

  • Mounted volumes
  • Dropbox folder
  • iCloud Drive folder
  • FUSE and the like

Is there a secure way to identify such locations to warn the user?

Holtwick
  • 1,849
  • 23
  • 29

2 Answers2

1

Dropbox does offer a way to programmatically get the path of the local Dropbox folder(s) (if any):

https://help.dropbox.com/installs-integrations/desktop/locate-dropbox-folder#programmatically

Greg
  • 16,359
  • 2
  • 34
  • 44
  • Thanks, this hint is really useful! For iCloud and NAS I found some NSURL properties that do the job. – Holtwick Jul 21 '20 at 19:14
0

Based on the hint of @Greg I came up with a solution in ObjC using some private helpers, but I guess the idea should become clear:

- (BOOL)isDropbox:(NSURL *)url {
    // https://help.dropbox.com/de-de/installs-integrations/desktop/locate-dropbox-folder#programmatically
    id json = [[NSData dataWithContentsOfURL:hxFileURL(@"~/.dropbox/info.json".stringByExpandingTildeInPath)] fromJSON];
    NSString *ppath = json[@"personal"][@"path"];
    NSString *bpath = json[@"business"][@"path"];
    NSString *path = hxFilePath(url);
    return (ppath && [path hasPrefix:ppath]) || (bpath && [path hasPrefix:bpath]);
}

- (BOOL)hoIsLocal:(NSURL *)url {
    @try {
        if (![FS hoIsDir:url]) {
            url = [url URLByDeletingLastPathComponent];
        }

        // Is it local in general?
        ERROR_DEF;
        NSNumber *state;
        [url getResourceValue:&state forKey:NSURLVolumeIsLocalKey error:&error];
        XLogInfo(@"state=%@ url=%@", state, url);

        // If so it could be stored in iCloud Drive
        if (state.boolValue) {
            BOOL ubiq = [FS isUbiquitousItemAtURL:url];
            XLogInfo(@"ubiq=%@ url=%@", @(ubiq), url);

            // Or on Dropbox
            if (!ubiq) {
                BOOL dbx = [FS isDropbox:url];
                XLogInfo(@"dbx=%@ url=%@", @(dbx), url);
                return !dbx;
            }
        }
    }
    @catch (id ex) {
        XLogException(ex);
    }
    return NO;
}
Holtwick
  • 1,849
  • 23
  • 29