* Create a directory
(p: string, mode: number, cb: BFSOneArgCallback)
| 612 | * Create a directory |
| 613 | */ |
| 614 | public mkdir(p: string, mode: number, cb: BFSOneArgCallback): void { |
| 615 | // Dropbox.js' client.mkdir() behaves like `mkdir -p`, i.e. it creates a |
| 616 | // directory and all its ancestors if they don't exist. |
| 617 | // Node's fs.mkdir() behaves like `mkdir`, i.e. it throws an error if an attempt |
| 618 | // is made to create a directory without a parent. |
| 619 | // To handle this inconsistency, a check for the existence of `path`'s parent |
| 620 | // must be performed before it is created, and an error thrown if it does |
| 621 | // not exist |
| 622 | const parent = path.dirname(p); |
| 623 | this._client.stat(parent, (error, stat) => { |
| 624 | if (error) { |
| 625 | cb(this.convert(error, parent)); |
| 626 | } else { |
| 627 | this._client.mkdir(p, (error) => { |
| 628 | if (error) { |
| 629 | cb(ApiError.FileError(ErrorCode.EEXIST, p)); |
| 630 | } else { |
| 631 | cb(null); |
| 632 | } |
| 633 | }); |
| 634 | } |
| 635 | }); |
| 636 | } |
| 637 | |
| 638 | /** |
| 639 | * Get the names of the files in a directory |