(p: string, flag: FileFlag, mode: number)
| 489 | throw new ApiError(ErrorCode.ENOTSUP); |
| 490 | } |
| 491 | public openSync(p: string, flag: FileFlag, mode: number): File { |
| 492 | // Check if the path exists, and is a file. |
| 493 | let stats: Stats; |
| 494 | try { |
| 495 | stats = this.statSync(p, false); |
| 496 | } catch (e) { |
| 497 | // File does not exist. |
| 498 | switch (flag.pathNotExistsAction()) { |
| 499 | case ActionType.CREATE_FILE: |
| 500 | // Ensure parent exists. |
| 501 | const parentStats = this.statSync(path.dirname(p), false); |
| 502 | if (!parentStats.isDirectory()) { |
| 503 | throw ApiError.ENOTDIR(path.dirname(p)); |
| 504 | } |
| 505 | return this.createFileSync(p, flag, mode); |
| 506 | case ActionType.THROW_EXCEPTION: |
| 507 | throw ApiError.ENOENT(p); |
| 508 | default: |
| 509 | throw new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.'); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | // File exists. |
| 514 | if (stats.isDirectory()) { |
| 515 | throw ApiError.EISDIR(p); |
| 516 | } |
| 517 | switch (flag.pathExistsAction()) { |
| 518 | case ActionType.THROW_EXCEPTION: |
| 519 | throw ApiError.EEXIST(p); |
| 520 | case ActionType.TRUNCATE_FILE: |
| 521 | // Delete file. |
| 522 | this.unlinkSync(p); |
| 523 | // Create file. Use the same mode as the old file. |
| 524 | // Node itself modifies the ctime when this occurs, so this action |
| 525 | // will preserve that behavior if the underlying file system |
| 526 | // supports those properties. |
| 527 | return this.createFileSync(p, flag, stats.mode); |
| 528 | case ActionType.NOP: |
| 529 | return this.openFileSync(p, flag, mode); |
| 530 | default: |
| 531 | throw new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.'); |
| 532 | } |
| 533 | } |
| 534 | public unlink(p: string, cb: BFSOneArgCallback): void { |
| 535 | cb(new ApiError(ErrorCode.ENOTSUP)); |
| 536 | } |
no test coverage detected