Skip to content

Commit

Permalink
fix(core/Filesystem): allow readdir on root directories (#1818)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Jul 29, 2019
1 parent 1243d8f commit 4059694
Showing 1 changed file with 6 additions and 3 deletions.
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

0 comments on commit 4059694

Please # to comment.