@zenfs/core 0.5.3 → 0.5.4
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/AsyncStore.js +12 -20
- package/dist/backends/SyncStore.d.ts +1 -1
- package/dist/backends/SyncStore.js +6 -11
- package/dist/browser.min.js +3 -3
- package/dist/browser.min.js.map +3 -3
- package/package.json +1 -1
- package/readme.md +2 -2
|
@@ -407,26 +407,18 @@ export class AsyncStoreFS extends Async(FileSystem) {
|
|
|
407
407
|
* Adds a new node under a random ID. Retries 5 times before giving up in
|
|
408
408
|
* the exceedingly unlikely chance that we try to reuse a random ino.
|
|
409
409
|
*/
|
|
410
|
-
async addNewNode(tx, data) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
return reroll();
|
|
423
|
-
}
|
|
424
|
-
else {
|
|
425
|
-
return ino;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
};
|
|
429
|
-
return reroll();
|
|
410
|
+
async addNewNode(tx, data, _maxAttempts = 5) {
|
|
411
|
+
if (_maxAttempts <= 0) {
|
|
412
|
+
// Max retries hit. Return with an error.
|
|
413
|
+
throw new ApiError(ErrorCode.EIO, 'Unable to commit data to key-value store.');
|
|
414
|
+
}
|
|
415
|
+
// Make an attempt
|
|
416
|
+
const ino = randomIno();
|
|
417
|
+
const isCommited = await tx.put(ino, data, false);
|
|
418
|
+
if (!isCommited) {
|
|
419
|
+
return await this.addNewNode(tx, data, --_maxAttempts);
|
|
420
|
+
}
|
|
421
|
+
return ino;
|
|
430
422
|
}
|
|
431
423
|
/**
|
|
432
424
|
* Commits a new file (well, a FILE or a DIRECTORY) to the file system with
|
|
@@ -202,7 +202,7 @@ export declare class SyncStoreFS extends SyncStoreFS_base {
|
|
|
202
202
|
* the exceedingly unlikely chance that we try to reuse a random GUID.
|
|
203
203
|
* @return The GUID that the data was stored under.
|
|
204
204
|
*/
|
|
205
|
-
protected addNewNode(tx: SyncTransaction, data: Uint8Array): Ino;
|
|
205
|
+
protected addNewNode(tx: SyncTransaction, data: Uint8Array, _maxAttempts?: number): Ino;
|
|
206
206
|
/**
|
|
207
207
|
* Commits a new file (well, a FILE or a DIRECTORY) to the file system with the given mode.
|
|
208
208
|
* Note: This will commit the transaction.
|
|
@@ -371,18 +371,13 @@ export class SyncStoreFS extends Sync(FileSystem) {
|
|
|
371
371
|
* the exceedingly unlikely chance that we try to reuse a random GUID.
|
|
372
372
|
* @return The GUID that the data was stored under.
|
|
373
373
|
*/
|
|
374
|
-
addNewNode(tx, data) {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
ino = randomIno();
|
|
380
|
-
tx.put(ino, data, false);
|
|
381
|
-
return ino;
|
|
382
|
-
}
|
|
383
|
-
catch (e) {
|
|
384
|
-
// Ignore and reroll.
|
|
374
|
+
addNewNode(tx, data, _maxAttempts = 5) {
|
|
375
|
+
for (let i = 0; i < _maxAttempts; i++) {
|
|
376
|
+
const ino = randomIno();
|
|
377
|
+
if (!tx.put(ino, data, false)) {
|
|
378
|
+
continue;
|
|
385
379
|
}
|
|
380
|
+
return ino;
|
|
386
381
|
}
|
|
387
382
|
throw new ApiError(ErrorCode.EIO, 'Unable to commit data to key-value store.');
|
|
388
383
|
}
|