core-3nweb-client-lib 0.53.17 → 0.53.19

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,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2016 - 2020, 2022 3NSoft Inc.
3
+ Copyright (C) 2016 - 2020, 2022, 2026 3NSoft Inc.
4
4
 
5
5
  This program is free software: you can redistribute it and/or modify it under
6
6
  the terms of the GNU General Public License as published by the Free Software
@@ -139,6 +139,7 @@ class LocalObj {
139
139
  throw new Error(`Version ${version} already exists in object ${this.objId}`);
140
140
  }
141
141
  const fPath = this.path(version);
142
+ // write$ process creates version file, and removes it when error happens
142
143
  const { obj, write$ } = await obj_on_disk_1.ObjOnDisk.createFileForWriteOfNewVersion(this.objId, version, fPath, encSub, undefined, this.objSegsGetterFromDisk);
143
144
  try {
144
145
  await (0, rxjs_1.lastValueFrom)(write$);
@@ -38,7 +38,6 @@ export declare class ObjFiles {
38
38
  fileWrite$: Observable<FileWrite[]>;
39
39
  newObj: SyncedObj;
40
40
  }>;
41
- findObjsToRemoveOnRemote(): Observable<ObjId>;
42
41
  scheduleGC(obj: SyncedObj): void;
43
42
  }
44
43
  export type SynchronizerOnObjId = <T>(objId: ObjId, action: () => Promise<T>) => Promise<T>;
@@ -17,7 +17,6 @@
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.SyncedObj = exports.ObjFiles = exports.REMOTE_FILE_NAME_EXT = exports.UNSYNCED_FILE_NAME_EXT = void 0;
20
- const rxjs_1 = require("rxjs");
21
20
  const synced_1 = require("../../../lib-common/processes/synced");
22
21
  const obj_folders_1 = require("../../../lib-client/objs-on-disk/obj-folders");
23
22
  const fs = require("../../../lib-common/async-fs-node");
@@ -137,24 +136,6 @@ class ObjFiles {
137
136
  .pipe((0, utils_for_observables_1.flatTap)(undefined, err => this.removeFailedNewObj(newObj)));
138
137
  return { fileWrite$, newObj };
139
138
  }
140
- findObjsToRemoveOnRemote() {
141
- return (0, rxjs_1.from)([undefined])
142
- .pipe(
143
- // listing recent folders, exactly once
144
- (0, operators_1.mergeMap)(() => this.folders.listRecent()),
145
- // flatten array and space it in time, to process folders one by one
146
- (0, operators_1.mergeMap)(objsAndPaths => objsAndPaths), (0, operators_1.mergeMap)(async ({ objId, path }) => {
147
- const obj = this.objs.get(objId);
148
- if (obj) {
149
- return (obj.statusObj().needsRemovalOnRemote() ?
150
- objId : undefined);
151
- }
152
- else {
153
- const needsRm = await obj_status_1.ObjStatus.fileShowsObjNeedsRemovalOnRemote(path, objId);
154
- return (needsRm ? objId : undefined);
155
- }
156
- }, 1), (0, operators_1.filter)(objId => (objId !== undefined)));
157
- }
158
139
  scheduleGC(obj) {
159
140
  this.gc.scheduleCollection(obj);
160
141
  }
@@ -293,6 +274,7 @@ class SyncedObj {
293
274
  throw new Error(`Version ${version} already exists in object ${this.objId}`);
294
275
  }
295
276
  const fPath = this.localVerPath(version);
277
+ // write$ process creates version file, and removes it when error happens
296
278
  const { obj, write$ } = await obj_on_disk_1.ObjOnDisk.createFileForWriteOfNewVersion(this.objId, version, fPath, encSub, this.downloader, this.localAndSyncedObjSegsGetterFromDisk);
297
279
  this.localVers.set(version, obj);
298
280
  const fileWrite$ = write$.pipe((0, operators_1.tap)({
@@ -101,7 +101,6 @@ export declare class FolderNode extends NodeInFS<FolderPersistance> {
101
101
  getFolder(name: string, undefOnMissing?: boolean): Promise<FolderNode | undefined>;
102
102
  getFile(name: string, undefOnMissing?: boolean): Promise<FileNode | undefined>;
103
103
  getLink(name: string, undefOnMissing?: boolean): Promise<LinkNode | undefined>;
104
- private fixMissingChildAndThrow;
105
104
  /**
106
105
  * If no initial local version given, then this performs like doTransition(change) method.
107
106
  * When initial local version is given and check, exceptions are thrown if versions mismatch,
@@ -303,7 +303,17 @@ class FolderNode extends node_in_fs_1.NodeInFS {
303
303
  throw (0, file_1.makeFileException)('notLink', childInfo.name);
304
304
  }
305
305
  }
306
- return this.getOrMakeChildNodeForInfo(childInfo);
306
+ try {
307
+ return await this.getOrMakeChildNodeForInfo(childInfo);
308
+ }
309
+ catch (exc) {
310
+ if (undefOnMissing && exc.notFound) {
311
+ return;
312
+ }
313
+ else {
314
+ throw exc;
315
+ }
316
+ }
307
317
  }
308
318
  async getOrMakeChildNodeForInfo(info, fromCurrentNodes = true) {
309
319
  const { node, nodePromise } = this.storage.nodes.getNodeOrPromise(info.objId);
@@ -335,13 +345,10 @@ class FolderNode extends node_in_fs_1.NodeInFS {
335
345
  }
336
346
  else if (exc.objNotFound) {
337
347
  if (fromCurrentNodes) {
338
- try {
339
- await this.fixMissingChildAndThrow(exc, info);
340
- }
341
- catch (exc) {
342
- deferred.reject(exc);
343
- return;
344
- }
348
+ // XXX this.fixMissingChildAndThrow() was removing object that has been moved on other device
349
+ // Should we label found inconsistency, sot that it can be fixed later? Should we have lost&found?
350
+ deferred.reject((0, file_1.makeFileException)('notFound', info.name, exc));
351
+ return;
345
352
  }
346
353
  else {
347
354
  try {
@@ -395,19 +402,20 @@ class FolderNode extends node_in_fs_1.NodeInFS {
395
402
  getLink(name, undefOnMissing = false) {
396
403
  return this.getNode('link', name, undefOnMissing);
397
404
  }
398
- async fixMissingChildAndThrow(exc, childInfo) {
399
- await this.doTransition(async (state, version) => {
400
- const presentChild = state.nodes[childInfo.name];
401
- if (!presentChild || (presentChild.objId !== childInfo.objId)) {
402
- return [];
403
- }
404
- delete state.nodes[childInfo.name];
405
- return this.makeEntryRemovalEvent(version, 'local', childInfo);
406
- }).catch(noop);
407
- const fileExc = (0, file_1.makeFileException)('notFound', childInfo.name, exc);
408
- fileExc.inconsistentStateOfFS = true;
409
- throw fileExc;
410
- }
405
+ // XXX apparently this causes a problem on moves received on other devices via sync
406
+ // private async fixMissingChildAndThrow(exc: StorageException, childInfo: NodeInfo): Promise<never> {
407
+ // await this.doTransition(async (state, version) => {
408
+ // const presentChild = state.nodes[childInfo.name];
409
+ // if (!presentChild || (presentChild.objId !== childInfo.objId)) {
410
+ // return [];
411
+ // }
412
+ // delete state.nodes[childInfo.name];
413
+ // return this.makeEntryRemovalEvent(version, 'local', childInfo);
414
+ // }).catch(noop);
415
+ // const fileExc = makeFileException('notFound', childInfo.name, exc);
416
+ // fileExc.inconsistentStateOfFS = true;
417
+ // throw fileExc;
418
+ // }
411
419
  /**
412
420
  * If no initial local version given, then this performs like doTransition(change) method.
413
421
  * When initial local version is given and check, exceptions are thrown if versions mismatch,
@@ -1192,7 +1200,7 @@ function diffNodes(current, remote, synced) {
1192
1200
  }
1193
1201
  else {
1194
1202
  const syncedNode = syncedNodesById.get(remoteNode.objId);
1195
- (0, assert_1.assert)(!!synced);
1203
+ (0, assert_1.assert)(!!syncedNode);
1196
1204
  const localChanged = (syncedNode.name !== localNode.name);
1197
1205
  const remoteChanged = (syncedNode.name !== remoteNode.name);
1198
1206
  renamed.push({
@@ -1206,7 +1214,7 @@ function diffNodes(current, remote, synced) {
1206
1214
  }
1207
1215
  if (!(0, node_in_fs_1.areBytesEqual)(localNode.key, remoteNode.key)) {
1208
1216
  const syncedNode = syncedNodesById.get(remoteNode.objId);
1209
- (0, assert_1.assert)(!!synced);
1217
+ (0, assert_1.assert)(!!syncedNode);
1210
1218
  const localChanged = !(0, node_in_fs_1.areBytesEqual)(localNode.key, syncedNode.key);
1211
1219
  const remoteChanged = !(0, node_in_fs_1.areBytesEqual)(localNode.key, syncedNode.key);
1212
1220
  rekeyed.push({
@@ -345,7 +345,7 @@ async function createNewV1File(path) {
345
345
  const initContent = Buffer.alloc(v1_obj_file_format_1.V1_FILE_START.length + 8, 0);
346
346
  initContent.set(v1_obj_file_format_1.V1_FILE_START);
347
347
  // note that all 8 bytes of layout offset are zeros
348
- await fs.writeFile(path, initContent, { flag: 'wx' });
348
+ await fs.writeFile(path, initContent, { flag: 'w' });
349
349
  }
350
350
  async function recordLayoutOffsetInV1(fd, ofs) {
351
351
  const ofsInBytes = Buffer.allocUnsafe(8);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.53.17",
3
+ "version": "0.53.19",
4
4
  "description": "3NWeb client core library, embeddable into different environments",
5
5
  "main": "build/lib-index.js",
6
6
  "types": "build/lib-index.d.ts",