@zenfs/core 0.0.12 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  var _a;
11
2
  import { BaseFileSystem } from '../filesystem.js';
12
3
  import { ApiError, ErrorCode } from '../ApiError.js';
@@ -41,14 +32,12 @@ class OverlayFile extends PreloadFile {
41
32
  constructor(fs, path, flag, stats, data) {
42
33
  super(fs, path, flag, stats, data);
43
34
  }
44
- sync() {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- if (!this.isDirty()) {
47
- return;
48
- }
49
- yield this._fs._syncAsync(this);
50
- this.resetDirty();
51
- });
35
+ async sync() {
36
+ if (!this.isDirty()) {
37
+ return;
38
+ }
39
+ await this._fs._syncAsync(this);
40
+ this.resetDirty();
52
41
  }
53
42
  syncSync() {
54
43
  if (this.isDirty()) {
@@ -56,10 +45,8 @@ class OverlayFile extends PreloadFile {
56
45
  this.resetDirty();
57
46
  }
58
47
  }
59
- close() {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- yield this.sync();
62
- });
48
+ async close() {
49
+ await this.sync();
63
50
  }
64
51
  closeSync() {
65
52
  this.syncSync();
@@ -94,7 +81,12 @@ export class UnlockedOverlayFS extends BaseFileSystem {
94
81
  }
95
82
  }
96
83
  get metadata() {
97
- return Object.assign(Object.assign({}, super.metadata), { name: OverlayFS.Name, synchronous: this._readable.metadata.synchronous && this._writable.metadata.synchronous, supportsProperties: this._readable.metadata.supportsProperties && this._writable.metadata.supportsProperties });
84
+ return {
85
+ ...super.metadata,
86
+ name: OverlayFS.Name,
87
+ synchronous: this._readable.metadata.synchronous && this._writable.metadata.synchronous,
88
+ supportsProperties: this._readable.metadata.supportsProperties && this._writable.metadata.supportsProperties,
89
+ };
98
90
  }
99
91
  getOverlayedFileSystems() {
100
92
  return {
@@ -102,12 +94,10 @@ export class UnlockedOverlayFS extends BaseFileSystem {
102
94
  writable: this._writable,
103
95
  };
104
96
  }
105
- _syncAsync(file) {
106
- return __awaiter(this, void 0, void 0, function* () {
107
- const stats = file.getStats();
108
- yield this.createParentDirectoriesAsync(file.getPath(), stats.getCred(0, 0));
109
- return this._writable.writeFile(file.getPath(), file.getBuffer(), getFlag('w'), stats.mode, stats.getCred(0, 0));
110
- });
97
+ async _syncAsync(file) {
98
+ const stats = file.getStats();
99
+ await this.createParentDirectoriesAsync(file.getPath(), stats.getCred(0, 0));
100
+ return this._writable.writeFile(file.getPath(), file.getBuffer(), getFlag('w'), stats.mode, stats.getCred(0, 0));
111
101
  }
112
102
  _syncSync(file) {
113
103
  const stats = file.getStats();
@@ -119,25 +109,23 @@ export class UnlockedOverlayFS extends BaseFileSystem {
119
109
  *
120
110
  * Called once to load up metadata stored on the writable file system.
121
111
  */
122
- _initialize() {
123
- return __awaiter(this, void 0, void 0, function* () {
124
- // if we're already initialized, immediately invoke the callback
125
- if (this._isInitialized) {
126
- return;
127
- }
128
- // Read deletion log, process into metadata.
129
- try {
130
- const data = yield this._writable.readFile(deletionLogPath, getFlag('r'), Cred.Root);
131
- this._deleteLog = decode(data);
132
- }
133
- catch (err) {
134
- if (err.errno !== ErrorCode.ENOENT) {
135
- throw err;
136
- }
112
+ async _initialize() {
113
+ // if we're already initialized, immediately invoke the callback
114
+ if (this._isInitialized) {
115
+ return;
116
+ }
117
+ // Read deletion log, process into metadata.
118
+ try {
119
+ const data = await this._writable.readFile(deletionLogPath, getFlag('r'), Cred.Root);
120
+ this._deleteLog = decode(data);
121
+ }
122
+ catch (err) {
123
+ if (err.errno !== ErrorCode.ENOENT) {
124
+ throw err;
137
125
  }
138
- this._isInitialized = true;
139
- this._reparseDeletionLog();
140
- });
126
+ }
127
+ this._isInitialized = true;
128
+ this._reparseDeletionLog();
141
129
  }
142
130
  getDeletionLog() {
143
131
  return this._deleteLog;
@@ -147,61 +135,59 @@ export class UnlockedOverlayFS extends BaseFileSystem {
147
135
  this._reparseDeletionLog();
148
136
  this.updateLog('', cred);
149
137
  }
150
- rename(oldPath, newPath, cred) {
151
- return __awaiter(this, void 0, void 0, function* () {
152
- this.checkInitialized();
153
- this.checkPath(oldPath);
154
- this.checkPath(newPath);
155
- if (oldPath === deletionLogPath || newPath === deletionLogPath) {
156
- throw ApiError.EPERM('Cannot rename deletion log.');
138
+ async rename(oldPath, newPath, cred) {
139
+ this.checkInitialized();
140
+ this.checkPath(oldPath);
141
+ this.checkPath(newPath);
142
+ if (oldPath === deletionLogPath || newPath === deletionLogPath) {
143
+ throw ApiError.EPERM('Cannot rename deletion log.');
144
+ }
145
+ // Write newPath using oldPath's contents, delete oldPath.
146
+ const oldStats = await this.stat(oldPath, cred);
147
+ if (oldStats.isDirectory()) {
148
+ // Optimization: Don't bother moving if old === new.
149
+ if (oldPath === newPath) {
150
+ return;
157
151
  }
158
- // Write newPath using oldPath's contents, delete oldPath.
159
- const oldStats = yield this.stat(oldPath, cred);
160
- if (oldStats.isDirectory()) {
161
- // Optimization: Don't bother moving if old === new.
162
- if (oldPath === newPath) {
163
- return;
164
- }
165
- let mode = 0o777;
166
- if (yield this.exists(newPath, cred)) {
167
- const stats = yield this.stat(newPath, cred);
168
- mode = stats.mode;
169
- if (stats.isDirectory()) {
170
- if ((yield this.readdir(newPath, cred)).length > 0) {
171
- throw ApiError.ENOTEMPTY(newPath);
172
- }
173
- }
174
- else {
175
- throw ApiError.ENOTDIR(newPath);
152
+ let mode = 0o777;
153
+ if (await this.exists(newPath, cred)) {
154
+ const stats = await this.stat(newPath, cred);
155
+ mode = stats.mode;
156
+ if (stats.isDirectory()) {
157
+ if ((await this.readdir(newPath, cred)).length > 0) {
158
+ throw ApiError.ENOTEMPTY(newPath);
176
159
  }
177
160
  }
178
- // Take care of writable first. Move any files there, or create an empty directory
179
- // if it doesn't exist.
180
- if (yield this._writable.exists(oldPath, cred)) {
181
- yield this._writable.rename(oldPath, newPath, cred);
182
- }
183
- else if (!(yield this._writable.exists(newPath, cred))) {
184
- yield this._writable.mkdir(newPath, mode, cred);
185
- }
186
- // Need to move *every file/folder* currently stored on readable to its new location
187
- // on writable.
188
- if (yield this._readable.exists(oldPath, cred)) {
189
- for (const name of yield this._readable.readdir(oldPath, cred)) {
190
- // Recursion! Should work for any nested files / folders.
191
- yield this.rename(resolve(oldPath, name), resolve(newPath, name), cred);
192
- }
161
+ else {
162
+ throw ApiError.ENOTDIR(newPath);
193
163
  }
194
164
  }
195
- else {
196
- if ((yield this.exists(newPath, cred)) && (yield this.stat(newPath, cred)).isDirectory()) {
197
- throw ApiError.EISDIR(newPath);
165
+ // Take care of writable first. Move any files there, or create an empty directory
166
+ // if it doesn't exist.
167
+ if (await this._writable.exists(oldPath, cred)) {
168
+ await this._writable.rename(oldPath, newPath, cred);
169
+ }
170
+ else if (!(await this._writable.exists(newPath, cred))) {
171
+ await this._writable.mkdir(newPath, mode, cred);
172
+ }
173
+ // Need to move *every file/folder* currently stored on readable to its new location
174
+ // on writable.
175
+ if (await this._readable.exists(oldPath, cred)) {
176
+ for (const name of await this._readable.readdir(oldPath, cred)) {
177
+ // Recursion! Should work for any nested files / folders.
178
+ await this.rename(resolve(oldPath, name), resolve(newPath, name), cred);
198
179
  }
199
- yield this.writeFile(newPath, yield this.readFile(oldPath, getFlag('r'), cred), getFlag('w'), oldStats.mode, cred);
200
180
  }
201
- if (oldPath !== newPath && (yield this.exists(oldPath, cred))) {
202
- yield this.unlink(oldPath, cred);
181
+ }
182
+ else {
183
+ if ((await this.exists(newPath, cred)) && (await this.stat(newPath, cred)).isDirectory()) {
184
+ throw ApiError.EISDIR(newPath);
203
185
  }
204
- });
186
+ await this.writeFile(newPath, await this.readFile(oldPath, getFlag('r'), cred), getFlag('w'), oldStats.mode, cred);
187
+ }
188
+ if (oldPath !== newPath && (await this.exists(oldPath, cred))) {
189
+ await this.unlink(oldPath, cred);
190
+ }
205
191
  }
206
192
  renameSync(oldPath, newPath, cred) {
207
193
  this.checkInitialized();
@@ -257,23 +243,21 @@ export class UnlockedOverlayFS extends BaseFileSystem {
257
243
  this.unlinkSync(oldPath, cred);
258
244
  }
259
245
  }
260
- stat(p, cred) {
261
- return __awaiter(this, void 0, void 0, function* () {
262
- this.checkInitialized();
263
- try {
264
- return this._writable.stat(p, cred);
265
- }
266
- catch (e) {
267
- if (this._deletedFiles[p]) {
268
- throw ApiError.ENOENT(p);
269
- }
270
- const oldStat = Stats.clone(yield this._readable.stat(p, cred));
271
- // Make the oldStat's mode writable. Preserve the topmost part of the
272
- // mode, which specifies if it is a file or a directory.
273
- oldStat.mode = makeModeWritable(oldStat.mode);
274
- return oldStat;
246
+ async stat(p, cred) {
247
+ this.checkInitialized();
248
+ try {
249
+ return this._writable.stat(p, cred);
250
+ }
251
+ catch (e) {
252
+ if (this._deletedFiles[p]) {
253
+ throw ApiError.ENOENT(p);
275
254
  }
276
- });
255
+ const oldStat = Stats.clone(await this._readable.stat(p, cred));
256
+ // Make the oldStat's mode writable. Preserve the topmost part of the
257
+ // mode, which specifies if it is a file or a directory.
258
+ oldStat.mode = makeModeWritable(oldStat.mode);
259
+ return oldStat;
260
+ }
277
261
  }
278
262
  statSync(p, cred) {
279
263
  this.checkInitialized();
@@ -291,43 +275,41 @@ export class UnlockedOverlayFS extends BaseFileSystem {
291
275
  return oldStat;
292
276
  }
293
277
  }
294
- open(p, flag, mode, cred) {
295
- return __awaiter(this, void 0, void 0, function* () {
296
- this.checkInitialized();
297
- this.checkPath(p);
298
- if (p === deletionLogPath) {
299
- throw ApiError.EPERM('Cannot open deletion log.');
300
- }
301
- if (yield this.exists(p, cred)) {
302
- switch (flag.pathExistsAction()) {
303
- case ActionType.TRUNCATE_FILE:
304
- yield this.createParentDirectoriesAsync(p, cred);
278
+ async open(p, flag, mode, cred) {
279
+ this.checkInitialized();
280
+ this.checkPath(p);
281
+ if (p === deletionLogPath) {
282
+ throw ApiError.EPERM('Cannot open deletion log.');
283
+ }
284
+ if (await this.exists(p, cred)) {
285
+ switch (flag.pathExistsAction()) {
286
+ case ActionType.TRUNCATE_FILE:
287
+ await this.createParentDirectoriesAsync(p, cred);
288
+ return this._writable.open(p, flag, mode, cred);
289
+ case ActionType.NOP:
290
+ if (await this._writable.exists(p, cred)) {
305
291
  return this._writable.open(p, flag, mode, cred);
306
- case ActionType.NOP:
307
- if (yield this._writable.exists(p, cred)) {
308
- return this._writable.open(p, flag, mode, cred);
309
- }
310
- else {
311
- // Create an OverlayFile.
312
- const buf = yield this._readable.readFile(p, getFlag('r'), cred);
313
- const stats = Stats.clone(yield this._readable.stat(p, cred));
314
- stats.mode = mode;
315
- return new OverlayFile(this, p, flag, stats, buf);
316
- }
317
- default:
318
- throw ApiError.EEXIST(p);
319
- }
292
+ }
293
+ else {
294
+ // Create an OverlayFile.
295
+ const buf = await this._readable.readFile(p, getFlag('r'), cred);
296
+ const stats = Stats.clone(await this._readable.stat(p, cred));
297
+ stats.mode = mode;
298
+ return new OverlayFile(this, p, flag, stats, buf);
299
+ }
300
+ default:
301
+ throw ApiError.EEXIST(p);
320
302
  }
321
- else {
322
- switch (flag.pathNotExistsAction()) {
323
- case ActionType.CREATE_FILE:
324
- yield this.createParentDirectoriesAsync(p, cred);
325
- return this._writable.open(p, flag, mode, cred);
326
- default:
327
- throw ApiError.ENOENT(p);
328
- }
303
+ }
304
+ else {
305
+ switch (flag.pathNotExistsAction()) {
306
+ case ActionType.CREATE_FILE:
307
+ await this.createParentDirectoriesAsync(p, cred);
308
+ return this._writable.open(p, flag, mode, cred);
309
+ default:
310
+ throw ApiError.ENOENT(p);
329
311
  }
330
- });
312
+ }
331
313
  }
332
314
  openSync(p, flag, mode, cred) {
333
315
  this.checkInitialized();
@@ -365,23 +347,21 @@ export class UnlockedOverlayFS extends BaseFileSystem {
365
347
  }
366
348
  }
367
349
  }
368
- unlink(p, cred) {
369
- return __awaiter(this, void 0, void 0, function* () {
370
- this.checkInitialized();
371
- this.checkPath(p);
372
- if (yield this.exists(p, cred)) {
373
- if (yield this._writable.exists(p, cred)) {
374
- yield this._writable.unlink(p, cred);
375
- }
376
- // if it still exists add to the delete log
377
- if (yield this.exists(p, cred)) {
378
- this.deletePath(p, cred);
379
- }
350
+ async unlink(p, cred) {
351
+ this.checkInitialized();
352
+ this.checkPath(p);
353
+ if (await this.exists(p, cred)) {
354
+ if (await this._writable.exists(p, cred)) {
355
+ await this._writable.unlink(p, cred);
380
356
  }
381
- else {
382
- throw ApiError.ENOENT(p);
357
+ // if it still exists add to the delete log
358
+ if (await this.exists(p, cred)) {
359
+ this.deletePath(p, cred);
383
360
  }
384
- });
361
+ }
362
+ else {
363
+ throw ApiError.ENOENT(p);
364
+ }
385
365
  }
386
366
  unlinkSync(p, cred) {
387
367
  this.checkInitialized();
@@ -399,27 +379,25 @@ export class UnlockedOverlayFS extends BaseFileSystem {
399
379
  throw ApiError.ENOENT(p);
400
380
  }
401
381
  }
402
- rmdir(p, cred) {
403
- return __awaiter(this, void 0, void 0, function* () {
404
- this.checkInitialized();
405
- if (yield this.exists(p, cred)) {
406
- if (yield this._writable.exists(p, cred)) {
407
- yield this._writable.rmdir(p, cred);
382
+ async rmdir(p, cred) {
383
+ this.checkInitialized();
384
+ if (await this.exists(p, cred)) {
385
+ if (await this._writable.exists(p, cred)) {
386
+ await this._writable.rmdir(p, cred);
387
+ }
388
+ if (await this.exists(p, cred)) {
389
+ // Check if directory is empty.
390
+ if ((await this.readdir(p, cred)).length > 0) {
391
+ throw ApiError.ENOTEMPTY(p);
408
392
  }
409
- if (yield this.exists(p, cred)) {
410
- // Check if directory is empty.
411
- if ((yield this.readdir(p, cred)).length > 0) {
412
- throw ApiError.ENOTEMPTY(p);
413
- }
414
- else {
415
- this.deletePath(p, cred);
416
- }
393
+ else {
394
+ this.deletePath(p, cred);
417
395
  }
418
396
  }
419
- else {
420
- throw ApiError.ENOENT(p);
421
- }
422
- });
397
+ }
398
+ else {
399
+ throw ApiError.ENOENT(p);
400
+ }
423
401
  }
424
402
  rmdirSync(p, cred) {
425
403
  this.checkInitialized();
@@ -441,19 +419,17 @@ export class UnlockedOverlayFS extends BaseFileSystem {
441
419
  throw ApiError.ENOENT(p);
442
420
  }
443
421
  }
444
- mkdir(p, mode, cred) {
445
- return __awaiter(this, void 0, void 0, function* () {
446
- this.checkInitialized();
447
- if (yield this.exists(p, cred)) {
448
- throw ApiError.EEXIST(p);
449
- }
450
- else {
451
- // The below will throw should any of the parent directories fail to exist
452
- // on _writable.
453
- yield this.createParentDirectoriesAsync(p, cred);
454
- yield this._writable.mkdir(p, mode, cred);
455
- }
456
- });
422
+ async mkdir(p, mode, cred) {
423
+ this.checkInitialized();
424
+ if (await this.exists(p, cred)) {
425
+ throw ApiError.EEXIST(p);
426
+ }
427
+ else {
428
+ // The below will throw should any of the parent directories fail to exist
429
+ // on _writable.
430
+ await this.createParentDirectoriesAsync(p, cred);
431
+ await this._writable.mkdir(p, mode, cred);
432
+ }
457
433
  }
458
434
  mkdirSync(p, mode, cred) {
459
435
  this.checkInitialized();
@@ -467,33 +443,31 @@ export class UnlockedOverlayFS extends BaseFileSystem {
467
443
  this._writable.mkdirSync(p, mode, cred);
468
444
  }
469
445
  }
470
- readdir(p, cred) {
471
- return __awaiter(this, void 0, void 0, function* () {
472
- this.checkInitialized();
473
- const dirStats = yield this.stat(p, cred);
474
- if (!dirStats.isDirectory()) {
475
- throw ApiError.ENOTDIR(p);
476
- }
477
- // Readdir in both, check delete log on RO file system's listing, merge, return.
478
- let contents = [];
479
- try {
480
- contents = contents.concat(yield this._writable.readdir(p, cred));
481
- }
482
- catch (e) {
483
- // NOP.
484
- }
485
- try {
486
- contents = contents.concat((yield this._readable.readdir(p, cred)).filter((fPath) => !this._deletedFiles[`${p}/${fPath}`]));
487
- }
488
- catch (e) {
489
- // NOP.
490
- }
491
- const seenMap = {};
492
- return contents.filter((fileP) => {
493
- const result = !seenMap[fileP];
494
- seenMap[fileP] = true;
495
- return result;
496
- });
446
+ async readdir(p, cred) {
447
+ this.checkInitialized();
448
+ const dirStats = await this.stat(p, cred);
449
+ if (!dirStats.isDirectory()) {
450
+ throw ApiError.ENOTDIR(p);
451
+ }
452
+ // Readdir in both, check delete log on RO file system's listing, merge, return.
453
+ let contents = [];
454
+ try {
455
+ contents = contents.concat(await this._writable.readdir(p, cred));
456
+ }
457
+ catch (e) {
458
+ // NOP.
459
+ }
460
+ try {
461
+ contents = contents.concat((await this._readable.readdir(p, cred)).filter((fPath) => !this._deletedFiles[`${p}/${fPath}`]));
462
+ }
463
+ catch (e) {
464
+ // NOP.
465
+ }
466
+ const seenMap = {};
467
+ return contents.filter((fileP) => {
468
+ const result = !seenMap[fileP];
469
+ seenMap[fileP] = true;
470
+ return result;
497
471
  });
498
472
  }
499
473
  readdirSync(p, cred) {
@@ -523,46 +497,38 @@ export class UnlockedOverlayFS extends BaseFileSystem {
523
497
  return result;
524
498
  });
525
499
  }
526
- exists(p, cred) {
527
- return __awaiter(this, void 0, void 0, function* () {
528
- this.checkInitialized();
529
- return (yield this._writable.exists(p, cred)) || ((yield this._readable.exists(p, cred)) && this._deletedFiles[p] !== true);
530
- });
500
+ async exists(p, cred) {
501
+ this.checkInitialized();
502
+ return (await this._writable.exists(p, cred)) || ((await this._readable.exists(p, cred)) && this._deletedFiles[p] !== true);
531
503
  }
532
504
  existsSync(p, cred) {
533
505
  this.checkInitialized();
534
506
  return this._writable.existsSync(p, cred) || (this._readable.existsSync(p, cred) && this._deletedFiles[p] !== true);
535
507
  }
536
- chmod(p, mode, cred) {
537
- return __awaiter(this, void 0, void 0, function* () {
538
- this.checkInitialized();
539
- yield this.operateOnWritableAsync(p, cred);
540
- yield this._writable.chmod(p, mode, cred);
541
- });
508
+ async chmod(p, mode, cred) {
509
+ this.checkInitialized();
510
+ await this.operateOnWritableAsync(p, cred);
511
+ await this._writable.chmod(p, mode, cred);
542
512
  }
543
513
  chmodSync(p, mode, cred) {
544
514
  this.checkInitialized();
545
515
  this.operateOnWritable(p, cred);
546
516
  this._writable.chmodSync(p, mode, cred);
547
517
  }
548
- chown(p, new_uid, new_gid, cred) {
549
- return __awaiter(this, void 0, void 0, function* () {
550
- this.checkInitialized();
551
- yield this.operateOnWritableAsync(p, cred);
552
- yield this._writable.chown(p, new_uid, new_gid, cred);
553
- });
518
+ async chown(p, new_uid, new_gid, cred) {
519
+ this.checkInitialized();
520
+ await this.operateOnWritableAsync(p, cred);
521
+ await this._writable.chown(p, new_uid, new_gid, cred);
554
522
  }
555
523
  chownSync(p, new_uid, new_gid, cred) {
556
524
  this.checkInitialized();
557
525
  this.operateOnWritable(p, cred);
558
526
  this._writable.chownSync(p, new_uid, new_gid, cred);
559
527
  }
560
- utimes(p, atime, mtime, cred) {
561
- return __awaiter(this, void 0, void 0, function* () {
562
- this.checkInitialized();
563
- yield this.operateOnWritableAsync(p, cred);
564
- yield this._writable.utimes(p, atime, mtime, cred);
565
- });
528
+ async utimes(p, atime, mtime, cred) {
529
+ this.checkInitialized();
530
+ await this.operateOnWritableAsync(p, cred);
531
+ await this._writable.utimes(p, atime, mtime, cred);
566
532
  }
567
533
  utimesSync(p, atime, mtime, cred) {
568
534
  this.checkInitialized();
@@ -633,19 +599,17 @@ export class UnlockedOverlayFS extends BaseFileSystem {
633
599
  this._writable.mkdirSync(p, this.statSync(p, cred).mode, cred);
634
600
  }
635
601
  }
636
- createParentDirectoriesAsync(p, cred) {
637
- return __awaiter(this, void 0, void 0, function* () {
638
- let parent = dirname(p), toCreate = [];
639
- while (!(yield this._writable.exists(parent, cred))) {
640
- toCreate.push(parent);
641
- parent = dirname(parent);
642
- }
643
- toCreate = toCreate.reverse();
644
- for (const p of toCreate) {
645
- const stats = yield this.stat(p, cred);
646
- yield this._writable.mkdir(p, stats.mode, cred);
647
- }
648
- });
602
+ async createParentDirectoriesAsync(p, cred) {
603
+ let parent = dirname(p), toCreate = [];
604
+ while (!(await this._writable.exists(parent, cred))) {
605
+ toCreate.push(parent);
606
+ parent = dirname(parent);
607
+ }
608
+ toCreate = toCreate.reverse();
609
+ for (const p of toCreate) {
610
+ const stats = await this.stat(p, cred);
611
+ await this._writable.mkdir(p, stats.mode, cred);
612
+ }
649
613
  }
650
614
  /**
651
615
  * Helper function:
@@ -662,15 +626,13 @@ export class UnlockedOverlayFS extends BaseFileSystem {
662
626
  this.copyToWritable(p, cred);
663
627
  }
664
628
  }
665
- operateOnWritableAsync(p, cred) {
666
- return __awaiter(this, void 0, void 0, function* () {
667
- if (!(yield this.exists(p, cred))) {
668
- throw ApiError.ENOENT(p);
669
- }
670
- if (!(yield this._writable.exists(p, cred))) {
671
- return this.copyToWritableAsync(p, cred);
672
- }
673
- });
629
+ async operateOnWritableAsync(p, cred) {
630
+ if (!(await this.exists(p, cred))) {
631
+ throw ApiError.ENOENT(p);
632
+ }
633
+ if (!(await this._writable.exists(p, cred))) {
634
+ return this.copyToWritableAsync(p, cred);
635
+ }
674
636
  }
675
637
  /**
676
638
  * Copy from readable to writable storage.
@@ -685,16 +647,14 @@ export class UnlockedOverlayFS extends BaseFileSystem {
685
647
  this.writeFileSync(p, this._readable.readFileSync(p, getFlag('r'), cred), getFlag('w'), pStats.mode, cred);
686
648
  }
687
649
  }
688
- copyToWritableAsync(p, cred) {
689
- return __awaiter(this, void 0, void 0, function* () {
690
- const pStats = yield this.stat(p, cred);
691
- if (pStats.isDirectory()) {
692
- yield this._writable.mkdir(p, pStats.mode, cred);
693
- }
694
- else {
695
- yield this.writeFile(p, yield this._readable.readFile(p, getFlag('r'), cred), getFlag('w'), pStats.mode, cred);
696
- }
697
- });
650
+ async copyToWritableAsync(p, cred) {
651
+ const pStats = await this.stat(p, cred);
652
+ if (pStats.isDirectory()) {
653
+ await this._writable.mkdir(p, pStats.mode, cred);
654
+ }
655
+ else {
656
+ await this.writeFile(p, await this._readable.readFile(p, getFlag('r'), cred), getFlag('w'), pStats.mode, cred);
657
+ }
698
658
  }
699
659
  }
700
660
  /**
@@ -725,14 +685,9 @@ export class OverlayFS extends LockedFS {
725
685
  unwrap() {
726
686
  return super.fs;
727
687
  }
728
- _initialize() {
729
- const _super = Object.create(null, {
730
- fs: { get: () => super.fs }
731
- });
732
- return __awaiter(this, void 0, void 0, function* () {
733
- yield _super.fs._initialize();
734
- return this;
735
- });
688
+ async _initialize() {
689
+ await super.fs._initialize();
690
+ return this;
736
691
  }
737
692
  }
738
693
  _a = OverlayFS;