* Creates a new node under a random ID. Retries 5 times before giving up in * the exceedingly unlikely chance that we try to reuse a random GUID. * @return The GUID that the data was stored under.
(tx: SyncKeyValueRWTransaction, data: Buffer)
| 518 | * @return The GUID that the data was stored under. |
| 519 | */ |
| 520 | private addNewNode(tx: SyncKeyValueRWTransaction, data: Buffer): string { |
| 521 | const retries = 0; |
| 522 | let currId: string; |
| 523 | while (retries < 5) { |
| 524 | try { |
| 525 | currId = GenerateRandomID(); |
| 526 | tx.put(currId, data, false); |
| 527 | return currId; |
| 528 | } catch (e) { |
| 529 | // Ignore and reroll. |
| 530 | } |
| 531 | } |
| 532 | throw new ApiError(ErrorCode.EIO, 'Unable to commit data to key-value store.'); |
| 533 | } |
| 534 | |
| 535 | /** |
| 536 | * Commits a new file (well, a FILE or a DIRECTORY) to the file system with |
no test coverage detected