Skip to content
New issue

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

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

Already on GitHub? # to your account

fix(core/Filesystem): allow readdir on root directories #1818

Merged
merged 1 commit into from
Jul 29, 2019
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
9 changes: 6 additions & 3 deletions core/src/web/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ export class FilesystemPluginWeb extends WebPlugin implements FilesystemPlugin {
private getPath(directory: FilesystemDirectory | undefined, uriPath: string | undefined): string {
directory = directory || this.DEFAULT_DIRECTORY;
let cleanedUriPath = uriPath !== undefined ? uriPath.replace(/^[/]+|[/]+$/g, '') : '';
return '/' + directory + '/' + cleanedUriPath;
let fsPath = '/' + directory;
if (uriPath !== '')
fsPath += '/' + cleanedUriPath;
return fsPath;
}

async clear(): Promise<{}> {
Expand Down Expand Up @@ -295,12 +298,12 @@ export class FilesystemPluginWeb extends WebPlugin implements FilesystemPlugin {
const path: string = this.getPath(options.directory, options.path);

let entry = await this.dbRequest('get', [path]) as EntryObj;
if (entry === undefined)
if (options.path !== '' && entry === undefined)
throw Error('Folder does not exist.');

let entries: string[] = await this.dbIndexRequest('by_folder', 'getAllKeys', [IDBKeyRange.only(path)]);
let names = entries.map((e) => {
return e.substring(entry.path.length + 1);
return e.substring(path.length + 1);
});
return {files: names};
}
Expand Down