Skip to content

Instantly share code, notes, and snippets.

@core-code
Last active July 9, 2016 09:55
Show Gist options
  • Save core-code/ef5ac3346118bb1e9a7af0807f7e8cde to your computer and use it in GitHub Desktop.
Save core-code/ef5ac3346118bb1e9a7af0807f7e8cde to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool
{
BOOL broken = FALSE;
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtURL:[NSURL fileURLWithPath:@"~".stringByExpandingTildeInPath]
includingPropertiesForKeys:@[NSURLIsRegularFileKey, NSURLIsPackageKey]
options:(NSDirectoryEnumerationOptions)0 errorHandler:nil];
for (NSURL *file in enumerator)
{
@autoreleasepool
{
NSError *error;
NSNumber *isRegularFile = nil, *isPackage;
if (![file getResourceValue:&isRegularFile forKey:NSURLIsRegularFileKey error:&error] ||
![file getResourceValue:&isPackage forKey:NSURLIsPackageKey error:&error])
{
NSLog(@"Warning: could not get resource values for file! %@ %@", file, error);
}
else if (isRegularFile.boolValue || isPackage.boolValue)
{
NSArray *otherVersions = [NSFileVersion otherVersionsOfItemAtURL:file];
for (NSFileVersion *ov in otherVersions)
{
NSString *path = ov.URL.path;
if (!path)
NSLog(@"Warning: file (%@) version (%@) is NIL: localizedName: %@ localzesNameOfSavingComputer: %@ modificationDate: %@ persistentIdentifier: %@ conflict: %i resolved: %i discardable: %i hasLocalContents: %i hasThumbnail: %i\n", file, ov.description, ov.localizedName, ov. localizedNameOfSavingComputer, ov.modificationDate, ov.persistentIdentifier, ov.conflict, ov.resolved, ov.discardable, ov.hasLocalContents, ov.hasThumbnail);
else if (path &&
(![[NSFileManager defaultManager] fileExistsAtPath:path] ||
![[NSFileManager defaultManager] isReadableFileAtPath:path]))
{
NSLog(@"Error: file (%@) version (%@) NOT accessible (%@): localizedName: %@ localzesNameOfSavingComputer: %@ modificationDate: %@ persistentIdentifier: %@ conflict: %i resolved: %i discardable: %i hasLocalContents: %i hasThumbnail: %i\n", file, ov.description, path, ov.localizedName, ov. localizedNameOfSavingComputer, ov.modificationDate, ov.persistentIdentifier, ov.conflict, ov.resolved, ov.discardable, ov.hasLocalContents, ov.hasThumbnail);
broken = TRUE;
}
}
}
}
}
if (broken)
NSLog(@"Error: NSFileVersion database is corrupted ;-(");
else
NSLog(@"Info: NSFileVersion database is fine ;-)");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment