| 15 | * multiple requests interleaving. |
| 16 | */ |
| 17 | export default class LockedFS<T extends FileSystem> implements FileSystem { |
| 18 | private _fs: T; |
| 19 | private _mu: Mutex; |
| 20 | |
| 21 | constructor(fs: T) { |
| 22 | this._fs = fs; |
| 23 | this._mu = new Mutex(); |
| 24 | } |
| 25 | |
| 26 | public getName(): string { |
| 27 | return 'LockedFS<' + this._fs.getName() + '>'; |
| 28 | } |
| 29 | |
| 30 | public getFSUnlocked(): T { |
| 31 | return this._fs; |
| 32 | } |
| 33 | |
| 34 | public initialize(cb: BFSOneArgCallback): void { |
| 35 | // FIXME: check to see if FS supports initialization |
| 36 | (<any> this._fs).initialize(cb); |
| 37 | } |
| 38 | |
| 39 | public diskSpace(p: string, cb: (total: number, free: number) => any): void { |
| 40 | // FIXME: should this lock? |
| 41 | this._fs.diskSpace(p, cb); |
| 42 | } |
| 43 | |
| 44 | public isReadOnly(): boolean { |
| 45 | return this._fs.isReadOnly(); |
| 46 | } |
| 47 | |
| 48 | public supportsLinks(): boolean { |
| 49 | return this._fs.supportsLinks(); |
| 50 | } |
| 51 | |
| 52 | public supportsProps(): boolean { |
| 53 | return this._fs.supportsProps(); |
| 54 | } |
| 55 | |
| 56 | public supportsSynch(): boolean { |
| 57 | return this._fs.supportsSynch(); |
| 58 | } |
| 59 | |
| 60 | public rename(oldPath: string, newPath: string, cb: BFSOneArgCallback): void { |
| 61 | this._mu.lock(() => { |
| 62 | this._fs.rename(oldPath, newPath, (err?: ApiError) => { |
| 63 | this._mu.unlock(); |
| 64 | cb(err); |
| 65 | }); |
| 66 | }); |
| 67 | } |
| 68 | |
| 69 | public renameSync(oldPath: string, newPath: string): void { |
| 70 | if (this._mu.isLocked()) { |
| 71 | throw new Error('invalid sync call'); |
| 72 | } |
| 73 | return this._fs.renameSync(oldPath, newPath); |
| 74 | } |
nothing calls this directly
no outgoing calls
no test coverage detected