Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions apps/automated/src/file-system/file-system-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,11 @@ export var testEnumEntities = function () {
var file = documents.getFile('Test.txt');
var file1 = documents.getFile('Test1.txt');
var testFolder = documents.getFolder('testFolder');
var nestedFile = testFolder.getFile('Nested.txt');
var fileFound = false;
var file1Found = false;
var testFolderFound = false;
var nestedFileFound = false;
var console = {
log: function (file) {
if (file === 'Test.txt') {
Expand All @@ -381,6 +383,8 @@ export var testEnumEntities = function () {
file1Found = true;
} else if (file === 'testFolder') {
testFolderFound = true;
} else if (file === 'Nested.txt') {
nestedFileFound = true;
Comment thread
NathanWalker marked this conversation as resolved.
}
},
};
Expand All @@ -395,9 +399,11 @@ export var testEnumEntities = function () {
TKUnit.assert(fileFound, 'Failed to enumerate Test.txt');
TKUnit.assert(file1Found, 'Failed to enumerate Test1.txt');
TKUnit.assert(testFolderFound, 'Failed to enumerate testFolder');
TKUnit.assert(!nestedFileFound, 'eachEntity should not enumerate nested files');

file.remove();
file1.remove();
nestedFile.remove();
testFolder.remove();
// << (hide)
// << file-system-enum-content
Expand Down
29 changes: 19 additions & 10 deletions packages/core/file-system/file-system-access.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,27 +629,34 @@ export class FileSystemAccess {
private enumEntities(path: string, callback: (entity: { path: string; name: string; extension: string }) => boolean, onError?: (error) => any) {
try {
const fileManager = NSFileManager.defaultManager;
let files: NSArray<string>;
try {
files = fileManager.contentsOfDirectoryAtPathError(path);
} catch (ex) {
if (onError) {
onError(new Error("Failed to enum files for folder '" + path + "': " + ex));
}
if (!this.folderExists(path)) {
console.error(`Failed to enum files for folder '${path}': no folder exists at path`);
return;
}

const enumerator = fileManager.enumeratorAtPath(path);
if (!enumerator) {
console.error(`Failed to enum files for folder '${path}': unable to create directory enumerator`);
return;
}

for (let i = 0; i < files.count; i++) {
const file = files.objectAtIndex(i);
let file = enumerator.nextObject() as string;
while (file) {
// Only surface direct children to match the previous shallow enumeration contract.
if (enumerator.level > 1) {
file = enumerator.nextObject() as string;
continue;
}

const info = {
path: this.concatPath(path, file),
name: file,
extension: '',
};

if (!this.folderExists(this.joinPath(path, file))) {
if (this.folderExists(this.joinPath(path, file))) {
enumerator.skipDescendants();
} else {
info.extension = this.getFileExtension(info.path);
}

Expand All @@ -658,6 +665,8 @@ export class FileSystemAccess {
// the callback returned false meaning we should stop the iteration
break;
}

file = enumerator.nextObject() as string;
}
} catch (ex) {
if (onError) {
Expand Down
Loading