Skip to content

CoreFoundation: finish up file numeration Windows TODO #2678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions CoreFoundation/Base.subproj/CFFileUtilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,14 +1058,28 @@ CF_PRIVATE void _CFIterateDirectory(CFStringRef directoryPath, Boolean appendSla
continue;
}

assert(!stuffToPrefix && "prefix not yet implemented");
const UniChar kSlash = CFPreferredSlash;

CFStringAppendBuffer buffer;
CFStringInitAppendBuffer(kCFAllocatorSystemDefault, &buffer);

if (stuffToPrefix) {
for (CFIndex i = 0, e = CFArrayGetCount(stuffToPrefix); i < e; i++) {
CFStringRef entry = CFArrayGetValueAtIndex(stuffToPrefix, i);
CFStringAppendStringToAppendBuffer(&buffer, entry);
if (CFStringGetCharacterAtIndex(entry, CFStringGetLength(entry) - 1) != _CFGetSlash()) {
CFStringAppendCharactersToAppendBuffer(&buffer, &kSlash, 1);
}
}
}

CFStringAppendStringToAppendBuffer(&buffer, fileName);
Boolean isDirectory = file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
CFMutableStringRef filePath = CFStringCreateMutableCopy(kCFAllocatorSystemDefault, nameLen + 1, fileName);
if (appendSlashForDirectories && isDirectory) {
UniChar slash = CFPreferredSlash;
CFStringAppendCharacters(filePath, &slash, 1);
CFStringAppendCharactersToAppendBuffer(&buffer, &kSlash, 1);
}

CFMutableStringRef filePath = CFStringCreateMutableWithAppendBuffer(&buffer);
Boolean result = fileHandler(fileName, filePath, isDirectory ? DT_DIR : DT_REG);
CFRelease(fileName);
CFRelease(filePath);
Expand Down