I'm clearing my app's Documents folder using a NSDirectoryEnumerator. It works, mostly, except that for some reason that I cannot fathom, it leaves 1 file behind. Here's my code:
NSDirectoryEnumerator * enumerator = [fileMan enumeratorAtURL:[NSURL fileURLWithPath:docsFolder()] includingPropertiesForKeys:nil options:NSDirectoryEnumerationSkipsSubdirectoryDescendants errorHandler:^BOOL(NSURL *url, NSError *error) {
NSLog(@"%@,%@",url,error);
return YES;
}];
for (NSURL * fileURL in enumerator) {
BOOL removed = [fileMan removeItemAtURL:fileURL error:nil];
NSLog(@"Removed %@:%d",fileURL.path,removed);
}
The docsFolder()
call in the above code is a function which simply returns the app's documents folder, using NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)
. I've breakpointed and logged in the error handler, it never hits. I've got a ton of files in there, they all get deleted fine. Except, there's always one file, always the same file, that gets left behind. This is in iOS 8.1, in the Simulator. Even if, for some reason, the file was locked (or whatever else) the error handler should have gotten called, so I'm at a loss as to what is happening.
Could it have something to do with the fact that all the files in the Documents folder are "hard" links to files in a separate folder? What would cause a hard link to not get... unlinked?
Anyone have any ideas why this might be happening?