Skip to content

Commit

Permalink
feat: improve & log errors for cache deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
SoCuul committed May 17, 2024
1 parent 78ad3d1 commit d429673
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/Manager.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,41 @@ + (BOOL)FLEX {


+ (void)cleanCache {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSMutableArray<NSError *> *deletionErrors = [NSMutableArray array];

// Temp folder
BOOL tempFolderSuccess = [[NSFileManager defaultManager] removeItemAtURL:[NSURL fileURLWithPath:NSTemporaryDirectory()] error:nil];
if (!tempFolderSuccess) NSLog(@"[SCInsta] Error deleting temp folder");
NSError *tempFolderError;
[fileManager removeItemAtURL:[NSURL fileURLWithPath:NSTemporaryDirectory()] error:&tempFolderError];

if (tempFolderError) [deletionErrors addObject:tempFolderError];

// Analytics folder
NSError *analyticsFolderError;
NSString *analyticsFolder = [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Application Support/com.burbn.instagram/analytics"];
BOOL analyticsFolderSuccess = [[NSFileManager defaultManager] removeItemAtURL:[[NSURL alloc] initFileURLWithPath:analyticsFolder] error:nil];
if (!analyticsFolderSuccess) NSLog(@"[SCInsta] Error deleting analytics folder");
[fileManager removeItemAtURL:[[NSURL alloc] initFileURLWithPath:analyticsFolder] error:&analyticsFolderError];

if (analyticsFolderError) [deletionErrors addObject:analyticsFolderError];

// Caches folder
NSString *cachesFolder = [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Caches"];
NSArray *cachesFolderContents = [fileManager contentsOfDirectoryAtURL:[[NSURL alloc] initFileURLWithPath:cachesFolder] includingPropertiesForKeys:nil options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];

for (NSURL *fileURL in cachesFolderContents) {
NSError *cacheItemDeletionError;
[fileManager removeItemAtURL:fileURL error:&cacheItemDeletionError];

if (cacheItemDeletionError) [deletionErrors addObject:cacheItemDeletionError];
}

// Log errors
if (deletionErrors.count > 1) {

for (NSError *error in deletionErrors) {
NSLog(@"[SCInsta] File Deletion Error: %@", error);
}

}

}
+ (BOOL)isEmpty:(NSURL *)url {
Expand Down

0 comments on commit d429673

Please sign in to comment.