Skip to content

Commit

Permalink
* MXFileStore: Logs all files when a data corruption is detected
Browse files Browse the repository at this point in the history
  • Loading branch information
manuroe committed May 3, 2021
1 parent aeebbe4 commit 3432d78
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes to be released in next version

🙌 Improvements
* MXCallKitAdapter: Update incoming calls if answered from application UI.
* MXFileStore: Logs all files when a data corruption is detected (to track vector-im/element-ios/issues/4921).

🐛 Bugfix
* MXTools: Fix bad linkification of matrix alias and URL (vector-im/element-ios/issues/4258).
Expand Down
32 changes: 29 additions & 3 deletions MatrixSDK/Data/Store/MXFileStore/MXFileStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,27 @@ - (void)diskUsageWithBlock:(void (^)(NSUInteger))block
});
}

- (void)logFiles
{
NSLog(@"[MXFileStore] logFiles: Files in %@:", self->storePath);
NSArray *contents = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:self->storePath error:nil];
NSEnumerator *contentsEnumurator = [contents objectEnumerator];

NSUInteger fileCount = 0, diskUsage = 0;

NSString *file;
while (file = [contentsEnumurator nextObject])
{
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[self->storePath stringByAppendingPathComponent:file] error:nil];
NSUInteger fileSize = [[fileAttributes objectForKey:NSFileSize] intValue];

NSLog(@"[MXFileStore] logFiles: - %@: %@", file, [NSByteCountFormatter stringFromByteCount:fileSize countStyle:NSByteCountFormatterCountStyleFile]);
diskUsage += fileSize;
fileCount++;
}

NSLog(@"[MXFileStore] logFiles: %@ files: %@", @(fileCount), [NSByteCountFormatter stringFromByteCount:diskUsage countStyle:NSByteCountFormatterCountStyleFile]);
}

+ (void)setPreloadOptions:(MXFileStorePreloadOptions)thePreloadOptions
{
Expand Down Expand Up @@ -1021,6 +1042,7 @@ - (BOOL)checkStorageValidity
if (!checkStorageValidity)
{
NSLog(@"[MXFileStore] Restore data: Cannot restore previous data. Reset the store");
[self logFiles];
[self deleteAllData];
}
}
Expand Down Expand Up @@ -1049,11 +1071,11 @@ - (void)loadRoomsMessages
MXFileRoomStore *roomStore;
@try
{
roomStore =[NSKeyedUnarchiver unarchiveObjectWithFile:roomFile];
roomStore = [NSKeyedUnarchiver unarchiveObjectWithFile:roomFile];
}
@catch (NSException *exception)
{
NSLog(@"[MXFileStore] Warning: MXFileRoomStore file for room %@ has been corrupted", roomId);
NSLog(@"[MXFileStore] Warning: MXFileRoomStore file for room %@ has been corrupted. Exception: %@", roomId, exception);
}

if (roomStore)
Expand All @@ -1063,7 +1085,10 @@ - (void)loadRoomsMessages
}
else
{
NSLog(@"[MXFileStore] Warning: MXFileStore has been reset due to room file corruption. Room id: %@", roomId);
NSLog(@"[MXFileStore] Warning: MXFileStore has been reset due to room file corruption. Room id: %@. File path: %@",
roomId, roomFile);

[self logFiles];
[self deleteAllData];
break;
}
Expand Down Expand Up @@ -1402,6 +1427,7 @@ - (void)loadMetaData
else
{
NSLog(@"[MXFileStore] loadMetaData: event stream token is missing");
[self logFiles];
[self deleteAllData];
}
}
Expand Down

0 comments on commit 3432d78

Please sign in to comment.