Reputation: 1966
I often run into troubles if my clients put the SQLite database on a managed folder. With managed folder I mean:
Is there a secure way to identify such locations to warn the user?
Upvotes: 1
Views: 36
Reputation: 1966
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;
}
Upvotes: 0
Reputation: 16940
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
Upvotes: 1