Skip to content
This repository was archived by the owner on Nov 24, 2021. It is now read-only.

Remove sqlite-shm and sqlite-wal #20

Merged
merged 1 commit into from
Sep 30, 2015
Merged
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
31 changes: 25 additions & 6 deletions Source/DATAStack.m
Original file line number Diff line number Diff line change
Expand Up @@ -296,20 +296,39 @@ - (void)backgroundContextDidSave:(NSNotification *)backgroundContextNotification

#pragma mark - Test

- (void)drop
{
- (void)drop {
NSPersistentStore *store = [self.persistentStoreCoordinator.persistentStores lastObject];
NSURL *storeURL = store.URL;
NSString *sqliteFile = [storeURL.path stringByDeletingPathExtension];
NSFileManager *fileManager = [NSFileManager defaultManager];

self.writerContext = nil;
self.mainContext = nil;
self.persistentStoreCoordinator = nil;

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *shm = [NSString stringWithFormat:@"%@.sqlite-shm", sqliteFile];
NSError *removeShmError = nil;
if ([fileManager fileExistsAtPath:shm]) {
[fileManager removeItemAtURL:[NSURL fileURLWithPath:shm] error:&removeShmError];
}
if (removeShmError) {
NSLog(@"Could not delete persitent store shm: %@", removeShmError.localizedDescription);
}

NSError *error = nil;
if ([fileManager fileExistsAtPath:store.URL.path]) [fileManager removeItemAtURL:store.URL error:&error];
NSString *wal = [NSString stringWithFormat:@"%@.sqlite-wal", sqliteFile];
NSError *removeWalError = nil;
if ([fileManager fileExistsAtPath:wal]) {
[fileManager removeItemAtURL:[NSURL fileURLWithPath:wal] error:&removeWalError];
}
if (removeWalError) {
NSLog(@"Could not delete persitent store wal: %@", removeWalError.localizedDescription);
}

if (error) {
NSError *removeStoreURLError = nil;
if ([fileManager fileExistsAtPath:storeURL.path]) {
[fileManager removeItemAtURL:storeURL error:&removeStoreURLError];
}
if (removeStoreURLError) {
NSLog(@"error deleting sqlite file");
abort();
}
Expand Down