remove hardcoded test paths
This commit is contained in:
parent
eb598a2408
commit
45a3c89605
|
@ -46,31 +46,13 @@ JSClassRef RJSRealmTypeClass() {
|
|||
return JSClassCreate(&realmTypesDefinition);
|
||||
}
|
||||
|
||||
NSString *RealmPathForFile(NSString *fileName) {
|
||||
NSString *RealmFileDirectory() {
|
||||
#if TARGET_OS_IPHONE
|
||||
NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
|
||||
return NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
|
||||
#else
|
||||
NSString *path = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES)[0];
|
||||
path = [path stringByAppendingPathComponent:[[[NSBundle mainBundle] executablePath] lastPathComponent]];
|
||||
return [path stringByAppendingPathComponent:[[[NSBundle mainBundle] executablePath] lastPathComponent]];
|
||||
#endif
|
||||
return [path stringByAppendingPathComponent:fileName];
|
||||
}
|
||||
|
||||
static void DeleteOrThrow(NSString *path) {
|
||||
NSError *error;
|
||||
if (![[NSFileManager defaultManager] removeItemAtPath:path error:&error]) {
|
||||
if (error.code != NSFileNoSuchFileError) {
|
||||
@throw [NSException exceptionWithName:@"RLMTestException"
|
||||
reason:[@"Unable to delete realm: " stringByAppendingString:error.description]
|
||||
userInfo:nil];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void DeleteRealmFilesAtPath(NSString *path) {
|
||||
DeleteOrThrow(path);
|
||||
DeleteOrThrow([path stringByAppendingString:@".lock"]);
|
||||
DeleteOrThrow([path stringByAppendingString:@".note"]);
|
||||
}
|
||||
|
||||
static JSValueRef DeleteTestFiles(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) {
|
||||
|
@ -103,12 +85,13 @@ static JSValueRef DeleteTestFiles(JSContextRef ctx, JSObjectRef function, JSObje
|
|||
realm::Realm::s_global_cache.invalidate_all();
|
||||
realm::Realm::s_global_cache.clear();
|
||||
|
||||
// FIXME - find all realm files in the docs dir and delete them rather than hardcoding these
|
||||
|
||||
DeleteRealmFilesAtPath(RealmPathForFile(@"test.realm"));
|
||||
DeleteRealmFilesAtPath(RealmPathForFile(@"test1.realm"));
|
||||
DeleteRealmFilesAtPath(RealmPathForFile(@"test2.realm"));
|
||||
DeleteRealmFilesAtPath(@(RJSDefaultPath().c_str()));
|
||||
NSFileManager *manager = [NSFileManager defaultManager];
|
||||
NSString *fileDir = RealmFileDirectory();
|
||||
for (NSString *path in [manager enumeratorAtPath:fileDir]) {
|
||||
if (![manager removeItemAtPath:[fileDir stringByAppendingPathComponent:path] error:nil]) {
|
||||
@throw [NSException exceptionWithName:@"removeItemAtPath error" reason:@"Failed to delete file" userInfo:nil];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue