Directory enumeration broken in 19A512f

I have some code that perfoms a deep enumeration of system frameworks (it collects .bridgesupport files). It seems that `enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:` behaves differently in such a case under 19A512f, skipping directory contents. I have to use `subpathsAtPath:` instead.


Here's some code that demonstrates the problem:


    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSURL *fwURL = [NSURL fileURLWithPath:@"/System/Library/Frameworks/Foundation.framework"];
//    fwURL = [[fileManager URLsForDirectory:NSDesktopDirectory inDomains:NSUserDomainMask] firstObject];
    //This returns all subpaths OK:
    NSArray *temp = [fileManager subpathsAtPath:fwURL.path];
    NSLog(@"There are %lu subpaths at %@\n", (unsigned long)temp.count, fwURL.path);
  
    NSDirectoryEnumerator *enumerator = [fileManager enumeratorAtURL:fwURL includingPropertiesForKeys:@[NSURLIsDirectoryKey] options:0 errorHandler:NULL];
    NSArray *urls = [enumerator allObjects];
    NSLog(@"There are %lu urls at %@", (unsigned long)urls.count, fwURL.path);
    if (urls.count < temp.count) {
        NSLog(@"URLs found: %@\n", [[urls valueForKey:@"path"] componentsJoinedByString:@"\n"]);
    }

If you uncomment the line that modifies `fwURL`, you will see the code works fine for the Desktop directory. This suggests it might be somehow either security related (and undocumented as far as I can see), or a problem with URLs linking to the system drive. Either way, it seems like a serious bug/change in behavior.


I logged a bug (FB 6800366). The response I've received is:


our engineering team has determined that this issue behaves as intended based on the information provided. In your sample code, you’re passing 0 as the options to `enumeratorAtURL:` [fileManager enumeratorAtURL:fwURL includingPropertiesForKeys:@[NSURLIsDirectoryKey] options:0 errorHandler:…] That 0 means “NSDirectoryEnumerationSkipsSubdirectoryDescendants”, and according to the header, “it cause NSDirectoryEnumerator to perform a shallow enumeration and not descend into directories it encounters.”


This is clearly not the case: NSDirectoryEnumerationSkipsSubdirectoryDescendants is defined as 1UL << 0.


Anyone care to give me a sanity check on this?


Replies

Hi sstanley,


I suppose this is related to the new security feature of macOS Catalina. Desktop, Downloads and few more folders are now protected. Try granting "Full Disk Access" to your app in System Preferences -> Security & Privacy -> Privacy.


Best regards,


Jakub