@zenfs/core 0.17.0 → 0.18.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/backends/backend.d.ts +2 -3
- package/dist/backends/fetch.js +2 -2
- package/dist/backends/file_index.d.ts +14 -15
- package/dist/backends/file_index.js +3 -9
- package/dist/backends/overlay.d.ts +21 -22
- package/dist/backends/overlay.js +111 -114
- package/dist/backends/port/fs.d.ts +21 -22
- package/dist/backends/port/fs.js +23 -23
- package/dist/backends/store/fs.d.ts +20 -21
- package/dist/backends/store/fs.js +70 -138
- package/dist/browser.min.js +4 -4
- package/dist/browser.min.js.map +4 -4
- package/dist/config.js +2 -2
- package/dist/{cred.d.ts → credentials.d.ts} +3 -2
- package/dist/credentials.js +16 -0
- package/dist/emulation/async.d.ts +20 -5
- package/dist/emulation/async.js +57 -9
- package/dist/emulation/dir.d.ts +4 -7
- package/dist/emulation/dir.js +16 -24
- package/dist/emulation/promises.d.ts +3 -3
- package/dist/emulation/promises.js +103 -46
- package/dist/emulation/shared.d.ts +0 -3
- package/dist/emulation/shared.js +0 -6
- package/dist/emulation/sync.d.ts +3 -4
- package/dist/emulation/sync.js +107 -65
- package/dist/emulation/watchers.d.ts +40 -3
- package/dist/emulation/watchers.js +115 -9
- package/dist/error.d.ts +1 -1
- package/dist/error.js +1 -1
- package/dist/filesystem.d.ts +23 -24
- package/dist/filesystem.js +6 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/mixins/async.d.ts +13 -14
- package/dist/mixins/async.js +45 -47
- package/dist/mixins/index.d.ts +4 -0
- package/dist/mixins/index.js +4 -0
- package/dist/mixins/mutexed.d.ts +1 -1
- package/dist/mixins/mutexed.js +61 -53
- package/dist/mixins/readonly.d.ts +14 -15
- package/dist/mixins/readonly.js +12 -12
- package/dist/mixins/sync.js +20 -20
- package/dist/stats.d.ts +12 -5
- package/dist/stats.js +11 -2
- package/dist/utils.d.ts +3 -9
- package/dist/utils.js +7 -24
- package/package.json +4 -3
- package/src/backends/backend.ts +2 -3
- package/src/backends/fetch.ts +2 -2
- package/src/backends/file_index.ts +3 -12
- package/src/backends/overlay.ts +112 -116
- package/src/backends/port/fs.ts +25 -26
- package/src/backends/store/fs.ts +72 -151
- package/src/config.ts +3 -2
- package/src/{cred.ts → credentials.ts} +11 -2
- package/src/emulation/async.ts +76 -18
- package/src/emulation/dir.ts +21 -29
- package/src/emulation/promises.ts +107 -46
- package/src/emulation/shared.ts +0 -8
- package/src/emulation/sync.ts +109 -66
- package/src/emulation/watchers.ts +140 -10
- package/src/error.ts +1 -1
- package/src/filesystem.ts +25 -26
- package/src/index.ts +2 -1
- package/src/mixins/async.ts +54 -55
- package/src/mixins/index.ts +4 -0
- package/src/mixins/mutexed.ts +62 -55
- package/src/mixins/readonly.ts +26 -27
- package/src/mixins/sync.ts +22 -23
- package/src/stats.ts +15 -5
- package/src/utils.ts +9 -34
- package/dist/cred.js +0 -8
|
@@ -43,10 +43,11 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
43
43
|
var e = new Error(message);
|
|
44
44
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
45
45
|
});
|
|
46
|
-
import {
|
|
46
|
+
import { credentials } from '../../credentials.js';
|
|
47
|
+
import { S_IFDIR, S_IFREG } from '../../emulation/constants.js';
|
|
47
48
|
import { basename, dirname, join, resolve } from '../../emulation/path.js';
|
|
48
49
|
import { Errno, ErrnoError } from '../../error.js';
|
|
49
|
-
import { PreloadFile
|
|
50
|
+
import { PreloadFile } from '../../file.js';
|
|
50
51
|
import { FileSystem } from '../../filesystem.js';
|
|
51
52
|
import { Inode, randomIno, rootIno } from '../../inode.js';
|
|
52
53
|
import { decodeDirListing, encode, encodeDirListing } from '../../utils.js';
|
|
@@ -99,16 +100,13 @@ export class StoreFS extends FileSystem {
|
|
|
99
100
|
/**
|
|
100
101
|
* @todo Make rename compatible with the cache.
|
|
101
102
|
*/
|
|
102
|
-
async rename(oldPath, newPath
|
|
103
|
+
async rename(oldPath, newPath) {
|
|
103
104
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
104
105
|
try {
|
|
105
106
|
const tx = __addDisposableResource(env_1, this.store.transaction(), true);
|
|
106
107
|
const oldParent = dirname(oldPath), oldName = basename(oldPath), newParent = dirname(newPath), newName = basename(newPath),
|
|
107
108
|
// Remove oldPath from parent's directory listing.
|
|
108
109
|
oldDirNode = await this.findINode(tx, oldParent), oldDirList = await this.getDirListing(tx, oldDirNode, oldParent);
|
|
109
|
-
if (!oldDirNode.toStats().hasAccess(W_OK, cred)) {
|
|
110
|
-
throw ErrnoError.With('EACCES', oldPath, 'rename');
|
|
111
|
-
}
|
|
112
110
|
if (!oldDirList[oldName]) {
|
|
113
111
|
throw ErrnoError.With('ENOENT', oldPath, 'rename');
|
|
114
112
|
}
|
|
@@ -134,16 +132,13 @@ export class StoreFS extends FileSystem {
|
|
|
134
132
|
newDirList = await this.getDirListing(tx, newDirNode, newParent);
|
|
135
133
|
}
|
|
136
134
|
if (newDirList[newName]) {
|
|
137
|
-
// If it's a file, delete it.
|
|
135
|
+
// If it's a file, delete it, if it's a directory, throw a permissions error.
|
|
138
136
|
const newNameNode = await this.getINode(tx, newDirList[newName], newPath);
|
|
139
|
-
if (newNameNode.toStats().isFile()) {
|
|
140
|
-
await tx.remove(newNameNode.ino);
|
|
141
|
-
await tx.remove(newDirList[newName]);
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
// If it's a directory, throw a permissions error.
|
|
137
|
+
if (!newNameNode.toStats().isFile()) {
|
|
145
138
|
throw ErrnoError.With('EPERM', newPath, 'rename');
|
|
146
139
|
}
|
|
140
|
+
await tx.remove(newNameNode.ino);
|
|
141
|
+
await tx.remove(newDirList[newName]);
|
|
147
142
|
}
|
|
148
143
|
newDirList[newName] = nodeId;
|
|
149
144
|
// Commit the two changed directory listings.
|
|
@@ -161,16 +156,13 @@ export class StoreFS extends FileSystem {
|
|
|
161
156
|
await result_1;
|
|
162
157
|
}
|
|
163
158
|
}
|
|
164
|
-
renameSync(oldPath, newPath
|
|
159
|
+
renameSync(oldPath, newPath) {
|
|
165
160
|
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
166
161
|
try {
|
|
167
162
|
const tx = __addDisposableResource(env_2, this.store.transaction(), false);
|
|
168
163
|
const oldParent = dirname(oldPath), oldName = basename(oldPath), newParent = dirname(newPath), newName = basename(newPath),
|
|
169
164
|
// Remove oldPath from parent's directory listing.
|
|
170
165
|
oldDirNode = this.findINodeSync(tx, oldParent), oldDirList = this.getDirListingSync(tx, oldDirNode, oldParent);
|
|
171
|
-
if (!oldDirNode.toStats().hasAccess(W_OK, cred)) {
|
|
172
|
-
throw ErrnoError.With('EACCES', oldPath, 'rename');
|
|
173
|
-
}
|
|
174
166
|
if (!oldDirList[oldName]) {
|
|
175
167
|
throw ErrnoError.With('ENOENT', oldPath, 'rename');
|
|
176
168
|
}
|
|
@@ -196,16 +188,13 @@ export class StoreFS extends FileSystem {
|
|
|
196
188
|
newDirList = this.getDirListingSync(tx, newDirNode, newParent);
|
|
197
189
|
}
|
|
198
190
|
if (newDirList[newName]) {
|
|
199
|
-
// If it's a file, delete it.
|
|
191
|
+
// If it's a file, delete it, if it's a directory, throw a permissions error.
|
|
200
192
|
const newNameNode = this.getINodeSync(tx, newDirList[newName], newPath);
|
|
201
|
-
if (newNameNode.toStats().isFile()) {
|
|
202
|
-
tx.removeSync(newNameNode.ino);
|
|
203
|
-
tx.removeSync(newDirList[newName]);
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
// If it's a directory, throw a permissions error.
|
|
193
|
+
if (!newNameNode.toStats().isFile()) {
|
|
207
194
|
throw ErrnoError.With('EPERM', newPath, 'rename');
|
|
208
195
|
}
|
|
196
|
+
tx.removeSync(newNameNode.ino);
|
|
197
|
+
tx.removeSync(newDirList[newName]);
|
|
209
198
|
}
|
|
210
199
|
newDirList[newName] = ino;
|
|
211
200
|
// Commit the two changed directory listings.
|
|
@@ -221,7 +210,7 @@ export class StoreFS extends FileSystem {
|
|
|
221
210
|
__disposeResources(env_2);
|
|
222
211
|
}
|
|
223
212
|
}
|
|
224
|
-
async stat(path
|
|
213
|
+
async stat(path) {
|
|
225
214
|
const env_3 = { stack: [], error: void 0, hasError: false };
|
|
226
215
|
try {
|
|
227
216
|
const tx = __addDisposableResource(env_3, this.store.transaction(), true);
|
|
@@ -229,11 +218,7 @@ export class StoreFS extends FileSystem {
|
|
|
229
218
|
if (!inode) {
|
|
230
219
|
throw ErrnoError.With('ENOENT', path, 'stat');
|
|
231
220
|
}
|
|
232
|
-
|
|
233
|
-
if (!stats.hasAccess(R_OK, cred)) {
|
|
234
|
-
throw ErrnoError.With('EACCES', path, 'stat');
|
|
235
|
-
}
|
|
236
|
-
return stats;
|
|
221
|
+
return inode.toStats();
|
|
237
222
|
}
|
|
238
223
|
catch (e_3) {
|
|
239
224
|
env_3.error = e_3;
|
|
@@ -245,16 +230,12 @@ export class StoreFS extends FileSystem {
|
|
|
245
230
|
await result_2;
|
|
246
231
|
}
|
|
247
232
|
}
|
|
248
|
-
statSync(path
|
|
233
|
+
statSync(path) {
|
|
249
234
|
const env_4 = { stack: [], error: void 0, hasError: false };
|
|
250
235
|
try {
|
|
251
236
|
const tx = __addDisposableResource(env_4, this.store.transaction(), false);
|
|
252
237
|
// Get the inode to the item, convert it into a Stats object.
|
|
253
|
-
|
|
254
|
-
if (!stats.hasAccess(R_OK, cred)) {
|
|
255
|
-
throw ErrnoError.With('EACCES', path, 'stat');
|
|
256
|
-
}
|
|
257
|
-
return stats;
|
|
238
|
+
return this.findINodeSync(tx, path).toStats();
|
|
258
239
|
}
|
|
259
240
|
catch (e_4) {
|
|
260
241
|
env_4.error = e_4;
|
|
@@ -264,22 +245,19 @@ export class StoreFS extends FileSystem {
|
|
|
264
245
|
__disposeResources(env_4);
|
|
265
246
|
}
|
|
266
247
|
}
|
|
267
|
-
async createFile(path, flag, mode
|
|
268
|
-
const node = await this.commitNew(path, S_IFREG, mode,
|
|
248
|
+
async createFile(path, flag, mode) {
|
|
249
|
+
const node = await this.commitNew(path, S_IFREG, mode, new Uint8Array(0));
|
|
269
250
|
return new PreloadFile(this, path, flag, node.toStats(), new Uint8Array(0));
|
|
270
251
|
}
|
|
271
|
-
createFileSync(path, flag, mode
|
|
272
|
-
this.commitNewSync(path, S_IFREG, mode
|
|
273
|
-
return this.openFileSync(path, flag
|
|
252
|
+
createFileSync(path, flag, mode) {
|
|
253
|
+
this.commitNewSync(path, S_IFREG, mode);
|
|
254
|
+
return this.openFileSync(path, flag);
|
|
274
255
|
}
|
|
275
|
-
async openFile(path, flag
|
|
256
|
+
async openFile(path, flag) {
|
|
276
257
|
const env_5 = { stack: [], error: void 0, hasError: false };
|
|
277
258
|
try {
|
|
278
259
|
const tx = __addDisposableResource(env_5, this.store.transaction(), true);
|
|
279
260
|
const node = await this.findINode(tx, path), data = await tx.get(node.ino);
|
|
280
|
-
if (!node.toStats().hasAccess(flagToMode(flag), cred)) {
|
|
281
|
-
throw ErrnoError.With('EACCES', path, 'openFile');
|
|
282
|
-
}
|
|
283
261
|
if (!data) {
|
|
284
262
|
throw ErrnoError.With('ENOENT', path, 'openFile');
|
|
285
263
|
}
|
|
@@ -295,14 +273,11 @@ export class StoreFS extends FileSystem {
|
|
|
295
273
|
await result_3;
|
|
296
274
|
}
|
|
297
275
|
}
|
|
298
|
-
openFileSync(path, flag
|
|
276
|
+
openFileSync(path, flag) {
|
|
299
277
|
const env_6 = { stack: [], error: void 0, hasError: false };
|
|
300
278
|
try {
|
|
301
279
|
const tx = __addDisposableResource(env_6, this.store.transaction(), false);
|
|
302
280
|
const node = this.findINodeSync(tx, path), data = tx.getSync(node.ino);
|
|
303
|
-
if (!node.toStats().hasAccess(flagToMode(flag), cred)) {
|
|
304
|
-
throw ErrnoError.With('EACCES', path, 'openFile');
|
|
305
|
-
}
|
|
306
281
|
if (!data) {
|
|
307
282
|
throw ErrnoError.With('ENOENT', path, 'openFile');
|
|
308
283
|
}
|
|
@@ -316,43 +291,37 @@ export class StoreFS extends FileSystem {
|
|
|
316
291
|
__disposeResources(env_6);
|
|
317
292
|
}
|
|
318
293
|
}
|
|
319
|
-
async unlink(path
|
|
320
|
-
return this.remove(path, false
|
|
294
|
+
async unlink(path) {
|
|
295
|
+
return this.remove(path, false);
|
|
321
296
|
}
|
|
322
|
-
unlinkSync(path
|
|
323
|
-
this.removeSync(path, false
|
|
297
|
+
unlinkSync(path) {
|
|
298
|
+
this.removeSync(path, false);
|
|
324
299
|
}
|
|
325
|
-
async rmdir(path
|
|
300
|
+
async rmdir(path) {
|
|
326
301
|
// Check first if directory is empty.
|
|
327
|
-
|
|
328
|
-
if (list.length > 0) {
|
|
302
|
+
if ((await this.readdir(path)).length) {
|
|
329
303
|
throw ErrnoError.With('ENOTEMPTY', path, 'rmdir');
|
|
330
304
|
}
|
|
331
|
-
await this.remove(path, true
|
|
305
|
+
await this.remove(path, true);
|
|
332
306
|
}
|
|
333
|
-
rmdirSync(path
|
|
307
|
+
rmdirSync(path) {
|
|
334
308
|
// Check first if directory is empty.
|
|
335
|
-
if (this.readdirSync(path
|
|
309
|
+
if (this.readdirSync(path).length) {
|
|
336
310
|
throw ErrnoError.With('ENOTEMPTY', path, 'rmdir');
|
|
337
311
|
}
|
|
338
|
-
|
|
339
|
-
this.removeSync(path, true, cred);
|
|
340
|
-
}
|
|
312
|
+
this.removeSync(path, true);
|
|
341
313
|
}
|
|
342
|
-
async mkdir(path, mode
|
|
343
|
-
await this.commitNew(path, S_IFDIR, mode,
|
|
314
|
+
async mkdir(path, mode) {
|
|
315
|
+
await this.commitNew(path, S_IFDIR, mode, encode('{}'));
|
|
344
316
|
}
|
|
345
|
-
mkdirSync(path, mode
|
|
346
|
-
this.commitNewSync(path, S_IFDIR, mode,
|
|
317
|
+
mkdirSync(path, mode) {
|
|
318
|
+
this.commitNewSync(path, S_IFDIR, mode, encode('{}'));
|
|
347
319
|
}
|
|
348
|
-
async readdir(path
|
|
320
|
+
async readdir(path) {
|
|
349
321
|
const env_7 = { stack: [], error: void 0, hasError: false };
|
|
350
322
|
try {
|
|
351
323
|
const tx = __addDisposableResource(env_7, this.store.transaction(), true);
|
|
352
324
|
const node = await this.findINode(tx, path);
|
|
353
|
-
if (!node.toStats().hasAccess(R_OK, cred)) {
|
|
354
|
-
throw ErrnoError.With('EACCES', path, 'readdur');
|
|
355
|
-
}
|
|
356
325
|
return Object.keys(await this.getDirListing(tx, node, path));
|
|
357
326
|
}
|
|
358
327
|
catch (e_7) {
|
|
@@ -365,14 +334,11 @@ export class StoreFS extends FileSystem {
|
|
|
365
334
|
await result_4;
|
|
366
335
|
}
|
|
367
336
|
}
|
|
368
|
-
readdirSync(path
|
|
337
|
+
readdirSync(path) {
|
|
369
338
|
const env_8 = { stack: [], error: void 0, hasError: false };
|
|
370
339
|
try {
|
|
371
340
|
const tx = __addDisposableResource(env_8, this.store.transaction(), false);
|
|
372
341
|
const node = this.findINodeSync(tx, path);
|
|
373
|
-
if (!node.toStats().hasAccess(R_OK, cred)) {
|
|
374
|
-
throw ErrnoError.With('EACCES', path, 'readdir');
|
|
375
|
-
}
|
|
376
342
|
return Object.keys(this.getDirListingSync(tx, node, path));
|
|
377
343
|
}
|
|
378
344
|
catch (e_8) {
|
|
@@ -437,27 +403,17 @@ export class StoreFS extends FileSystem {
|
|
|
437
403
|
__disposeResources(env_10);
|
|
438
404
|
}
|
|
439
405
|
}
|
|
440
|
-
async link(
|
|
406
|
+
async link(target, link) {
|
|
441
407
|
const env_11 = { stack: [], error: void 0, hasError: false };
|
|
442
408
|
try {
|
|
443
409
|
const tx = __addDisposableResource(env_11, this.store.transaction(), true);
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
}
|
|
448
|
-
const newDir = dirname(newpath), newDirNode = await this.findINode(tx, newDir), newListing = await this.getDirListing(tx, newDirNode, newDir);
|
|
449
|
-
if (!newDirNode.toStats().hasAccess(W_OK, cred)) {
|
|
450
|
-
throw ErrnoError.With('EACCES', newDir, 'link');
|
|
451
|
-
}
|
|
452
|
-
const ino = await this._findINode(tx, existingDir, basename(existing));
|
|
453
|
-
const node = await this.getINode(tx, ino, existing);
|
|
454
|
-
if (!node.toStats().hasAccess(W_OK, cred)) {
|
|
455
|
-
throw ErrnoError.With('EACCES', newpath, 'link');
|
|
456
|
-
}
|
|
410
|
+
const newDir = dirname(link), newDirNode = await this.findINode(tx, newDir), listing = await this.getDirListing(tx, newDirNode, newDir);
|
|
411
|
+
const ino = await this._findINode(tx, dirname(target), basename(target));
|
|
412
|
+
const node = await this.getINode(tx, ino, target);
|
|
457
413
|
node.nlink++;
|
|
458
|
-
|
|
414
|
+
listing[basename(link)] = ino;
|
|
459
415
|
tx.setSync(ino, node.data);
|
|
460
|
-
tx.setSync(newDirNode.ino, encodeDirListing(
|
|
416
|
+
tx.setSync(newDirNode.ino, encodeDirListing(listing));
|
|
461
417
|
tx.commitSync();
|
|
462
418
|
}
|
|
463
419
|
catch (e_11) {
|
|
@@ -470,27 +426,17 @@ export class StoreFS extends FileSystem {
|
|
|
470
426
|
await result_6;
|
|
471
427
|
}
|
|
472
428
|
}
|
|
473
|
-
linkSync(
|
|
429
|
+
linkSync(target, link) {
|
|
474
430
|
const env_12 = { stack: [], error: void 0, hasError: false };
|
|
475
431
|
try {
|
|
476
432
|
const tx = __addDisposableResource(env_12, this.store.transaction(), false);
|
|
477
|
-
const
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
}
|
|
481
|
-
const newDir = dirname(newpath), newDirNode = this.findINodeSync(tx, newDir), newListing = this.getDirListingSync(tx, newDirNode, newDir);
|
|
482
|
-
if (!newDirNode.toStats().hasAccess(W_OK, cred)) {
|
|
483
|
-
throw ErrnoError.With('EACCES', newDir, 'link');
|
|
484
|
-
}
|
|
485
|
-
const ino = this._findINodeSync(tx, existingDir, basename(existing));
|
|
486
|
-
const node = this.getINodeSync(tx, ino, existing);
|
|
487
|
-
if (!node.toStats().hasAccess(W_OK, cred)) {
|
|
488
|
-
throw ErrnoError.With('EACCES', newpath, 'link');
|
|
489
|
-
}
|
|
433
|
+
const newDir = dirname(link), newDirNode = this.findINodeSync(tx, newDir), listing = this.getDirListingSync(tx, newDirNode, newDir);
|
|
434
|
+
const ino = this._findINodeSync(tx, dirname(target), basename(target));
|
|
435
|
+
const node = this.getINodeSync(tx, ino, target);
|
|
490
436
|
node.nlink++;
|
|
491
|
-
|
|
437
|
+
listing[basename(link)] = ino;
|
|
492
438
|
tx.setSync(ino, node.data);
|
|
493
|
-
tx.setSync(newDirNode.ino, encodeDirListing(
|
|
439
|
+
tx.setSync(newDirNode.ino, encodeDirListing(listing));
|
|
494
440
|
tx.commitSync();
|
|
495
441
|
}
|
|
496
442
|
catch (e_12) {
|
|
@@ -719,15 +665,11 @@ export class StoreFS extends FileSystem {
|
|
|
719
665
|
* @param cred The UID/GID to create the file with
|
|
720
666
|
* @param data The data to store at the file's data node.
|
|
721
667
|
*/
|
|
722
|
-
async commitNew(path, type, mode,
|
|
668
|
+
async commitNew(path, type, mode, data) {
|
|
723
669
|
const env_15 = { stack: [], error: void 0, hasError: false };
|
|
724
670
|
try {
|
|
725
671
|
const tx = __addDisposableResource(env_15, this.store.transaction(), true);
|
|
726
672
|
const parentPath = dirname(path), parent = await this.findINode(tx, parentPath);
|
|
727
|
-
//Check that the creater has correct access
|
|
728
|
-
if (!parent.toStats().hasAccess(W_OK, cred)) {
|
|
729
|
-
throw ErrnoError.With('EACCES', path, 'commitNewFile');
|
|
730
|
-
}
|
|
731
673
|
const fname = basename(path), listing = await this.getDirListing(tx, parent, parentPath);
|
|
732
674
|
/*
|
|
733
675
|
The root always exists.
|
|
@@ -735,19 +677,19 @@ export class StoreFS extends FileSystem {
|
|
|
735
677
|
we will create a file with name '' in root should path == '/'.
|
|
736
678
|
*/
|
|
737
679
|
if (path === '/') {
|
|
738
|
-
throw ErrnoError.With('EEXIST', path, '
|
|
680
|
+
throw ErrnoError.With('EEXIST', path, 'commitNew');
|
|
739
681
|
}
|
|
740
682
|
// Check if file already exists.
|
|
741
683
|
if (listing[fname]) {
|
|
742
684
|
await tx.abort();
|
|
743
|
-
throw ErrnoError.With('EEXIST', path, '
|
|
685
|
+
throw ErrnoError.With('EEXIST', path, 'commitNew');
|
|
744
686
|
}
|
|
745
687
|
// Commit data.
|
|
746
688
|
const inode = new Inode();
|
|
747
689
|
inode.ino = await this.addNew(tx, data, path);
|
|
748
690
|
inode.mode = mode | type;
|
|
749
|
-
inode.uid =
|
|
750
|
-
inode.gid =
|
|
691
|
+
inode.uid = credentials.uid;
|
|
692
|
+
inode.gid = credentials.gid;
|
|
751
693
|
inode.size = data.length;
|
|
752
694
|
// Update and commit parent directory listing.
|
|
753
695
|
listing[fname] = await this.addNew(tx, inode.data, path);
|
|
@@ -774,15 +716,11 @@ export class StoreFS extends FileSystem {
|
|
|
774
716
|
* @param data The data to store at the file's data node.
|
|
775
717
|
* @return The Inode for the new file.
|
|
776
718
|
*/
|
|
777
|
-
commitNewSync(path, type, mode,
|
|
719
|
+
commitNewSync(path, type, mode, data = new Uint8Array()) {
|
|
778
720
|
const env_16 = { stack: [], error: void 0, hasError: false };
|
|
779
721
|
try {
|
|
780
722
|
const tx = __addDisposableResource(env_16, this.store.transaction(), false);
|
|
781
723
|
const parentPath = dirname(path), parent = this.findINodeSync(tx, parentPath);
|
|
782
|
-
//Check that the creater has correct access
|
|
783
|
-
if (!parent.toStats().hasAccess(W_OK, cred)) {
|
|
784
|
-
throw ErrnoError.With('EACCES', path, 'commitNewFile');
|
|
785
|
-
}
|
|
786
724
|
const fname = basename(path), listing = this.getDirListingSync(tx, parent, parentPath);
|
|
787
725
|
/*
|
|
788
726
|
The root always exists.
|
|
@@ -790,19 +728,19 @@ export class StoreFS extends FileSystem {
|
|
|
790
728
|
we will create a file with name '' in root should p == '/'.
|
|
791
729
|
*/
|
|
792
730
|
if (path === '/') {
|
|
793
|
-
throw ErrnoError.With('EEXIST', path, '
|
|
731
|
+
throw ErrnoError.With('EEXIST', path, 'commitNew');
|
|
794
732
|
}
|
|
795
733
|
// Check if file already exists.
|
|
796
734
|
if (listing[fname]) {
|
|
797
|
-
throw ErrnoError.With('EEXIST', path, '
|
|
735
|
+
throw ErrnoError.With('EEXIST', path, 'commitNew');
|
|
798
736
|
}
|
|
799
737
|
// Commit data.
|
|
800
738
|
const node = new Inode();
|
|
801
739
|
node.ino = this.addNewSync(tx, data, path);
|
|
802
740
|
node.size = data.length;
|
|
803
741
|
node.mode = mode | type;
|
|
804
|
-
node.uid =
|
|
805
|
-
node.gid =
|
|
742
|
+
node.uid = credentials.uid;
|
|
743
|
+
node.gid = credentials.gid;
|
|
806
744
|
// Update and commit parent directory listing.
|
|
807
745
|
listing[fname] = this.addNewSync(tx, node.data, path);
|
|
808
746
|
tx.setSync(parent.ino, encodeDirListing(listing));
|
|
@@ -823,27 +761,24 @@ export class StoreFS extends FileSystem {
|
|
|
823
761
|
* @param isDir Does the path belong to a directory, or a file?
|
|
824
762
|
* @todo Update mtime.
|
|
825
763
|
*/
|
|
826
|
-
async remove(path, isDir
|
|
764
|
+
async remove(path, isDir) {
|
|
827
765
|
const env_17 = { stack: [], error: void 0, hasError: false };
|
|
828
766
|
try {
|
|
829
767
|
const tx = __addDisposableResource(env_17, this.store.transaction(), true);
|
|
830
768
|
const parent = dirname(path), parentNode = await this.findINode(tx, parent), listing = await this.getDirListing(tx, parentNode, parent), fileName = basename(path);
|
|
831
769
|
if (!listing[fileName]) {
|
|
832
|
-
throw ErrnoError.With('ENOENT', path, '
|
|
770
|
+
throw ErrnoError.With('ENOENT', path, 'remove');
|
|
833
771
|
}
|
|
834
772
|
const fileIno = listing[fileName];
|
|
835
773
|
// Get file inode.
|
|
836
774
|
const fileNode = await this.getINode(tx, fileIno, path);
|
|
837
|
-
if (!fileNode.toStats().hasAccess(W_OK, cred)) {
|
|
838
|
-
throw ErrnoError.With('EACCES', path, 'removeEntry');
|
|
839
|
-
}
|
|
840
775
|
// Remove from directory listing of parent.
|
|
841
776
|
delete listing[fileName];
|
|
842
777
|
if (!isDir && fileNode.toStats().isDirectory()) {
|
|
843
|
-
throw ErrnoError.With('EISDIR', path, '
|
|
778
|
+
throw ErrnoError.With('EISDIR', path, 'remove');
|
|
844
779
|
}
|
|
845
780
|
if (isDir && !fileNode.toStats().isDirectory()) {
|
|
846
|
-
throw ErrnoError.With('ENOTDIR', path, '
|
|
781
|
+
throw ErrnoError.With('ENOTDIR', path, 'remove');
|
|
847
782
|
}
|
|
848
783
|
await tx.set(parentNode.ino, encodeDirListing(listing));
|
|
849
784
|
if (--fileNode.nlink < 1) {
|
|
@@ -870,26 +805,23 @@ export class StoreFS extends FileSystem {
|
|
|
870
805
|
* @param isDir Does the path belong to a directory, or a file?
|
|
871
806
|
* @todo Update mtime.
|
|
872
807
|
*/
|
|
873
|
-
removeSync(path, isDir
|
|
808
|
+
removeSync(path, isDir) {
|
|
874
809
|
const env_18 = { stack: [], error: void 0, hasError: false };
|
|
875
810
|
try {
|
|
876
811
|
const tx = __addDisposableResource(env_18, this.store.transaction(), false);
|
|
877
812
|
const parent = dirname(path), parentNode = this.findINodeSync(tx, parent), listing = this.getDirListingSync(tx, parentNode, parent), fileName = basename(path), fileIno = listing[fileName];
|
|
878
813
|
if (!fileIno) {
|
|
879
|
-
throw ErrnoError.With('ENOENT', path, '
|
|
814
|
+
throw ErrnoError.With('ENOENT', path, 'remove');
|
|
880
815
|
}
|
|
881
816
|
// Get file inode.
|
|
882
817
|
const fileNode = this.getINodeSync(tx, fileIno, path);
|
|
883
|
-
if (!fileNode.toStats().hasAccess(W_OK, cred)) {
|
|
884
|
-
throw ErrnoError.With('EACCES', path, 'removeEntry');
|
|
885
|
-
}
|
|
886
818
|
// Remove from directory listing of parent.
|
|
887
819
|
delete listing[fileName];
|
|
888
820
|
if (!isDir && fileNode.toStats().isDirectory()) {
|
|
889
|
-
throw ErrnoError.With('EISDIR', path, '
|
|
821
|
+
throw ErrnoError.With('EISDIR', path, 'remove');
|
|
890
822
|
}
|
|
891
823
|
if (isDir && !fileNode.toStats().isDirectory()) {
|
|
892
|
-
throw ErrnoError.With('ENOTDIR', path, '
|
|
824
|
+
throw ErrnoError.With('ENOTDIR', path, 'remove');
|
|
893
825
|
}
|
|
894
826
|
// Update directory listing.
|
|
895
827
|
tx.setSync(parentNode.ino, encodeDirListing(listing));
|