@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.
- package/dist/ApiError.d.ts +1 -1
- package/dist/ApiError.js +17 -16
- package/dist/backends/AsyncMirror.js +40 -46
- package/dist/backends/AsyncStore.js +326 -383
- package/dist/backends/FolderAdapter.js +8 -19
- package/dist/backends/Locked.js +91 -137
- package/dist/backends/OverlayFS.js +234 -279
- package/dist/backends/SyncStore.js +2 -2
- package/dist/backends/backend.d.ts +6 -6
- package/dist/browser.min.js +23 -6
- package/dist/browser.min.js.map +4 -4
- package/dist/emulation/callbacks.d.ts +109 -72
- package/dist/emulation/callbacks.js +40 -47
- package/dist/emulation/dir.d.ts +55 -0
- package/dist/emulation/dir.js +104 -0
- package/dist/emulation/fs.d.ts +1 -2
- package/dist/emulation/fs.js +0 -1
- package/dist/emulation/index.d.ts +3 -0
- package/dist/emulation/index.js +3 -0
- package/dist/emulation/promises.d.ts +71 -50
- package/dist/emulation/promises.js +243 -342
- package/dist/emulation/shared.d.ts +14 -0
- package/dist/emulation/shared.js +4 -3
- package/dist/emulation/streams.d.ts +102 -0
- package/dist/emulation/streams.js +55 -0
- package/dist/emulation/sync.d.ts +81 -52
- package/dist/emulation/sync.js +98 -65
- package/dist/file.d.ts +11 -5
- package/dist/file.js +79 -76
- package/dist/filesystem.d.ts +3 -3
- package/dist/filesystem.js +181 -262
- package/dist/index.d.ts +3 -3
- package/dist/index.js +39 -53
- package/dist/stats.d.ts +80 -27
- package/dist/stats.js +142 -93
- package/dist/utils.d.ts +2 -6
- package/dist/utils.js +79 -78
- package/package.json +4 -2
- package/readme.md +2 -40
|
@@ -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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
139
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (
|
|
163
|
-
|
|
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
|
-
|
|
179
|
-
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
202
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
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
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
if (
|
|
373
|
-
|
|
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
|
-
|
|
382
|
-
|
|
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
|
-
|
|
404
|
-
|
|
405
|
-
if (
|
|
406
|
-
|
|
407
|
-
|
|
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
|
-
|
|
410
|
-
|
|
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
|
-
|
|
420
|
-
|
|
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
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
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
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
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
|
-
|
|
528
|
-
|
|
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
|
-
|
|
538
|
-
|
|
539
|
-
|
|
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
|
-
|
|
550
|
-
|
|
551
|
-
|
|
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
|
-
|
|
562
|
-
|
|
563
|
-
|
|
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
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
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
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
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
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
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
|
-
|
|
730
|
-
|
|
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;
|