core-3nweb-client-lib 0.53.20 → 0.53.22
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/build/api-defs/files.d.ts +11 -2
- package/build/core/asmail/inbox/inbox-events.js +1 -0
- package/build/core/keyring/peer-keys/dataset/v2/peer-keys-db.d.ts +2 -3
- package/build/core/keyring/peer-keys/dataset/v2/peer-keys-db.js +55 -42
- package/build/core/keyring/peer-keys/index.js +1 -1
- package/build/core/storage/synced/remote-events.js +1 -0
- package/build/core/storage/synced/upsyncer.js +7 -1
- package/build/core-ipc/fs.js +23 -0
- package/build/lib-client/fs-utils/files.js +1 -0
- package/build/lib-client/local-files/device-fs.d.ts +1 -0
- package/build/lib-client/local-files/device-fs.js +3 -0
- package/build/lib-client/xsp-fs/folder-node.js +1 -1
- package/build/lib-client/xsp-fs/fs.d.ts +1 -0
- package/build/lib-client/xsp-fs/fs.js +24 -2
- package/build/lib-common/canonical-address.d.ts +1 -0
- package/build/lib-common/canonical-address.js +11 -4
- package/build/lib-sqlite-on-3nstorage/for-sqlite.d.ts +1 -0
- package/build/lib-sqlite-on-3nstorage/for-sqlite.js +6 -0
- package/build/protos/asmail.proto.js +306 -0
- package/build/protos/fs.proto.js +306 -0
- package/build/tests/caps-api/fs-checks/not-versioned/copyFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/copyFile.js +73 -0
- package/build/tests/caps-api/fs-checks/not-versioned/copyXAttrs.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/copyXAttrs.js +85 -0
- package/package.json +1 -1
- package/protos/fs.proto +8 -0
|
@@ -995,7 +995,7 @@ declare namespace web3n.files {
|
|
|
995
995
|
move(src: string, dst: string): Promise<void>;
|
|
996
996
|
|
|
997
997
|
/**
|
|
998
|
-
* This returns a promise, resolvable when file has been copied.
|
|
998
|
+
* This returns a promise, resolvable when file's contenet has been copied.
|
|
999
999
|
* @param src is an initial path of a file
|
|
1000
1000
|
* @param dst is a path of a file
|
|
1001
1001
|
* @param overwrite is a flag that with a true value allows
|
|
@@ -1019,7 +1019,16 @@ declare namespace web3n.files {
|
|
|
1019
1019
|
): Promise<void>;
|
|
1020
1020
|
|
|
1021
1021
|
/**
|
|
1022
|
-
* This returns a promise, resolvable when
|
|
1022
|
+
* This returns a promise, resolvable when source item's xattrs are copied
|
|
1023
|
+
* to destination item
|
|
1024
|
+
* @param src is source item
|
|
1025
|
+
* @param dst is destination item
|
|
1026
|
+
* @param filter is a
|
|
1027
|
+
*/
|
|
1028
|
+
copyXAttrs(src: string, dst: string, filter?: string[]): Promise<void>;
|
|
1029
|
+
|
|
1030
|
+
/**
|
|
1031
|
+
* This returns a promise, resolvable when file's content has been saved.
|
|
1023
1032
|
* @param file is a file to save
|
|
1024
1033
|
* @param dst is a path where to save given file
|
|
1025
1034
|
* @param overwrite is a flag that with a true value allows
|
|
@@ -3,6 +3,7 @@ import { AsyncRNG } from "../../../../../lib-common/rng-def";
|
|
|
3
3
|
import { PairEvent } from "./logs";
|
|
4
4
|
import { SingleProc } from "../../../../../lib-common/processes/synced";
|
|
5
5
|
import { LogEntry } from "../../../../../lib-common/dataset-sync/per-device-json-array-logs";
|
|
6
|
+
import { LogError } from "../../../../../lib-client/logging/log-to-file";
|
|
6
7
|
type WritableFS = web3n.files.WritableFS;
|
|
7
8
|
type JsonKey = web3n.keys.JsonKey;
|
|
8
9
|
type CorrespondentKeysInfo = web3n.keys.CorrespondentKeysInfo;
|
|
@@ -38,7 +39,7 @@ export interface RecipientKeyPairDbEntry {
|
|
|
38
39
|
msgMasterKeyAlg: string;
|
|
39
40
|
msgMasterKey: Uint8Array;
|
|
40
41
|
}
|
|
41
|
-
export declare function makePeerKeysDB(peerKeysFS: WritableFS, random: AsyncRNG): Promise<{
|
|
42
|
+
export declare function makePeerKeysDB(peerKeysFS: WritableFS, random: AsyncRNG, logError: LogError): Promise<{
|
|
42
43
|
saveIfNeeded: () => Promise<void>;
|
|
43
44
|
generateSuggestedPairOnPeerIntroKey: (peerCAddr: string, peerIntroPKey: JsonKey) => Promise<{
|
|
44
45
|
nextCrypto: SuggestedNextKeyPair;
|
|
@@ -59,10 +60,8 @@ export declare function makePeerKeysDB(peerKeysFS: WritableFS, random: AsyncRNG)
|
|
|
59
60
|
pkey: string;
|
|
60
61
|
pairAlg: string;
|
|
61
62
|
} | undefined;
|
|
62
|
-
addReceptionPair: (pair: RecipientKeyPairDbEntry) => void;
|
|
63
63
|
markPairAsInUse: (peerCAddr: string, peerKId: string, recipientKId: string) => boolean;
|
|
64
64
|
findReceptionPairsForPId: (pid: string) => Pick<RecipientKeyPairDbEntry, "peerCAddr" | "peerKId" | "recipientKId" | "msgMasterKey" | "ratchetStage" | "pairAlg">[] | undefined;
|
|
65
|
-
absorbV1DataIfPresent: (keyringFS: WritableFS) => Promise<void>;
|
|
66
65
|
getPeerAddressForCanonical: (peerCAddr: string) => string | undefined;
|
|
67
66
|
updateReceivedMsgCountIn: (peerCAddr: string, peerKId: string, recipientKId: string, msgCount: number, msgTS: number) => void;
|
|
68
67
|
absorbOpsFromOtherDevices: (changeProc: SingleProc, ops: LogEntry<PairEvent>[]) => Promise<void>;
|
|
@@ -191,7 +191,7 @@ async function generatePids(random) {
|
|
|
191
191
|
}
|
|
192
192
|
return pids;
|
|
193
193
|
}
|
|
194
|
-
async function makePeerKeysDB(peerKeysFS, random) {
|
|
194
|
+
async function makePeerKeysDB(peerKeysFS, random, logError) {
|
|
195
195
|
const keys = await readOrInitializeDB(peerKeysFS);
|
|
196
196
|
let needToSave = false;
|
|
197
197
|
function noteDbMotificationForFileSaving() {
|
|
@@ -263,7 +263,10 @@ async function makePeerKeysDB(peerKeysFS, random) {
|
|
|
263
263
|
return ((res.length > 0) ? (0, lib_sqlite_on_3nstorage_1.objectFromQueryExecResult)(res[0])[0].peerAddr : undefined);
|
|
264
264
|
}
|
|
265
265
|
function addReceptionPair(pair) {
|
|
266
|
-
(0, for_sqlite_1.
|
|
266
|
+
const added = (0, for_sqlite_1.performTableInsertOrNothingOnConflict)(keys.db, 'reception_key_pairs', pair, receptionKeyPairsTabFields);
|
|
267
|
+
if (!added) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
267
270
|
const { peerCAddr, peerKId, pids, recipientKId } = pair;
|
|
268
271
|
for (const pid of pids) {
|
|
269
272
|
(0, for_sqlite_1.performTableInsert)(keys.db, 'reception_key_pairs_pids', { peerCAddr, peerKId, pid, recipientKId }, pidsIndexTabFields);
|
|
@@ -357,6 +360,10 @@ async function makePeerKeysDB(peerKeysFS, random) {
|
|
|
357
360
|
senderKid: peerKId
|
|
358
361
|
};
|
|
359
362
|
}
|
|
363
|
+
function findReceptionPairStage({ peerCAddr, peerKId, recipientKId }) {
|
|
364
|
+
const pairs = (0, for_sqlite_1.selectFromTable)(keys.db, 'reception_key_pairs', ['ratchetStage'], { peerCAddr, peerKId, recipientKId }, receptionKeyPairsTabFields);
|
|
365
|
+
return (pairs ? pairs[0].ratchetStage : undefined);
|
|
366
|
+
}
|
|
360
367
|
async function generateSuggestedPairOnPeerIntroKey(peerCAddr, peerIntroPKey) {
|
|
361
368
|
const { kid: peerKId, k: peerPKey } = peerIntroPKey;
|
|
362
369
|
return await generateAndAddSuggestedPair(peerCAddr, peerKId, buffer_utils_1.base64.open(peerPKey), false);
|
|
@@ -467,53 +474,61 @@ async function makePeerKeysDB(peerKeysFS, random) {
|
|
|
467
474
|
async function absorbOpsFromOtherDevices(changeProc, ops) {
|
|
468
475
|
await changeProc.startOrChain(async () => {
|
|
469
476
|
for (const op of ops) {
|
|
470
|
-
|
|
471
|
-
if (op.p
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
if (existingPair
|
|
476
|
-
|
|
477
|
+
try {
|
|
478
|
+
if (op.p) {
|
|
479
|
+
if (op.p.opType === 'pair-from-peer') {
|
|
480
|
+
const { peerAddr, sendingPairRecord: inJSON } = op.p;
|
|
481
|
+
const existingPair = getSendingPair(inJSON.peerCAddr);
|
|
482
|
+
if (existingPair) {
|
|
483
|
+
if (existingPair.pairTS < inJSON.pairTS) {
|
|
484
|
+
updateSendingPair((0, logs_1.sendingPairEntryFromJSON)(inJSON));
|
|
485
|
+
}
|
|
477
486
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
487
|
+
else {
|
|
488
|
+
if (!getPeerAddressForCanonical(inJSON.peerCAddr)) {
|
|
489
|
+
addPeer(peerAddr);
|
|
490
|
+
}
|
|
491
|
+
addSendingPair((0, logs_1.sendingPairEntryFromJSON)(inJSON));
|
|
482
492
|
}
|
|
483
|
-
addSendingPair((0, logs_1.sendingPairEntryFromJSON)(inJSON));
|
|
484
493
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
494
|
+
else if (op.p.opType === 'pair-suggested-to-peer') {
|
|
495
|
+
const { peerAddr, receivingPairRecord: inJSON } = op.p;
|
|
496
|
+
const existingPair = getPairSuggestedToPeer(inJSON.peerCAddr);
|
|
497
|
+
if (existingPair) {
|
|
498
|
+
if (existingPair.timestamp < inJSON.pairTS) {
|
|
499
|
+
// XXX replace existingPair with one from inJSON
|
|
500
|
+
// let's note that in broken situation we may suggest fixing moves
|
|
501
|
+
if (!findReceptionPairStage(op.p.receivingPairRecord)) {
|
|
502
|
+
addReceptionPair((0, logs_1.recipientPairEntryFromJSON)(inJSON));
|
|
503
|
+
}
|
|
504
|
+
}
|
|
493
505
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
506
|
+
else if (!findReceptionPairStage(op.p.receivingPairRecord)) {
|
|
507
|
+
if (!getPeerAddressForCanonical(inJSON.peerCAddr)) {
|
|
508
|
+
addPeer(peerAddr);
|
|
509
|
+
}
|
|
510
|
+
addReceptionPair((0, logs_1.recipientPairEntryFromJSON)(inJSON));
|
|
498
511
|
}
|
|
499
|
-
|
|
512
|
+
}
|
|
513
|
+
else if (op.p.opType === 'peer-started-using-pair') {
|
|
514
|
+
const { peerCAddr, peerKId, recipientKId } = op.p;
|
|
515
|
+
markPairAsInUse(peerCAddr, peerKId, recipientKId);
|
|
516
|
+
}
|
|
517
|
+
else if (op.p.opType === 'remove-peer-at-address') {
|
|
518
|
+
const { peerCAddr } = op.p;
|
|
519
|
+
forgetCorrespondentAt(peerCAddr);
|
|
520
|
+
}
|
|
521
|
+
else if (op.p.opType === 'remove-all-peers-at-domain') {
|
|
522
|
+
const { domain } = op.p;
|
|
523
|
+
forgetAllCorrespondentsAtDomain(domain);
|
|
500
524
|
}
|
|
501
525
|
}
|
|
502
|
-
else if (op.
|
|
503
|
-
|
|
504
|
-
markPairAsInUse(peerCAddr, peerKId, recipientKId);
|
|
505
|
-
}
|
|
506
|
-
else if (op.p.opType === 'remove-peer-at-address') {
|
|
507
|
-
const { peerCAddr } = op.p;
|
|
508
|
-
forgetCorrespondentAt(peerCAddr);
|
|
509
|
-
}
|
|
510
|
-
else if (op.p.opType === 'remove-all-peers-at-domain') {
|
|
511
|
-
const { domain } = op.p;
|
|
512
|
-
forgetAllCorrespondentsAtDomain(domain);
|
|
526
|
+
else if (op.syncPoint) {
|
|
527
|
+
// XXX
|
|
513
528
|
}
|
|
514
529
|
}
|
|
515
|
-
|
|
516
|
-
|
|
530
|
+
catch (err) {
|
|
531
|
+
logError(`Error while absorbing peer key operation in keyring from other device`, err);
|
|
517
532
|
}
|
|
518
533
|
}
|
|
519
534
|
await saveIfNeeded();
|
|
@@ -541,10 +556,8 @@ async function makePeerKeysDB(peerKeysFS, random) {
|
|
|
541
556
|
addSendingPairFromSuggested,
|
|
542
557
|
updateSendingPairFromSuggested,
|
|
543
558
|
findKeyToMatchSuggestedForSendingPair,
|
|
544
|
-
addReceptionPair,
|
|
545
559
|
markPairAsInUse,
|
|
546
560
|
findReceptionPairsForPId,
|
|
547
|
-
absorbV1DataIfPresent,
|
|
548
561
|
getPeerAddressForCanonical,
|
|
549
562
|
updateReceivedMsgCountIn,
|
|
550
563
|
absorbOpsFromOtherDevices,
|
|
@@ -39,7 +39,7 @@ async function makePeersKeyring(keyringFS, localFS, random, logger) {
|
|
|
39
39
|
// - we want to save and log crypto material, more so, we generate and log new crypto first, then send message
|
|
40
40
|
// - logging and saving of marking pair as in use also doesn't have to be immediate (should it be logged?)
|
|
41
41
|
const logs = await (0, logs_1.makePeerKeysChangeLogs)(logsFS, logsLocalFS, logger.logError);
|
|
42
|
-
const keysDB = await (0, peer_keys_db_1.makePeerKeysDB)(peerKeysFS, random);
|
|
42
|
+
const keysDB = await (0, peer_keys_db_1.makePeerKeysDB)(peerKeysFS, random, logger.logError);
|
|
43
43
|
async function suggestPairForPeerIntroKey(peerAddr, peerIntroPKey) {
|
|
44
44
|
const peerCAddr = (0, canonical_address_1.toCanonicalAddress)(peerAddr);
|
|
45
45
|
const alreadySuggested = keysDB.getPairSuggestedToPeer(peerCAddr);
|
|
@@ -245,7 +245,7 @@ class UploadTask {
|
|
|
245
245
|
uploadVersion: this.info.uploadVersion,
|
|
246
246
|
cause: exc
|
|
247
247
|
}));
|
|
248
|
-
await this.objStatus.recordUploadCancellation(this.info);
|
|
248
|
+
await this.objStatus.recordUploadCancellation(this.info).catch(noop);
|
|
249
249
|
this.rmTask(this);
|
|
250
250
|
this.emitUploadEvent('upload-erred', {
|
|
251
251
|
error: (exc.runtimeException ? exc : (0, error_1.stringifyErr)(exc))
|
|
@@ -353,6 +353,12 @@ class UploadTask {
|
|
|
353
353
|
await this.remoteStorage.cancelTransaction(this.objId, transactionId).catch(noop);
|
|
354
354
|
}
|
|
355
355
|
await this.objStatus.recordUploadCancellation(this.info).catch(noop);
|
|
356
|
+
this.uploadCompletion.reject((0, exceptions_1.makeFSSyncException)(`obj-upload`, {
|
|
357
|
+
message: `Upload cancelled`,
|
|
358
|
+
localVersion: this.info.localVersion,
|
|
359
|
+
uploadVersion: this.info.uploadVersion,
|
|
360
|
+
cause: `Upload canacelled`
|
|
361
|
+
}));
|
|
356
362
|
this.rmTask(this);
|
|
357
363
|
this.emitUploadEvent('upload-cancelled', {});
|
|
358
364
|
}
|
package/build/core-ipc/fs.js
CHANGED
|
@@ -61,6 +61,7 @@ function makeFSCaller(caller, fsMsg) {
|
|
|
61
61
|
if (fsMsg.writable) {
|
|
62
62
|
fs.copyFile = copyFile.makeCaller(caller, objPath);
|
|
63
63
|
fs.copyFolder = copyFolder.makeCaller(caller, objPath);
|
|
64
|
+
fs.copyXAttrs = copyXAttrs.makeCaller(caller, objPath);
|
|
64
65
|
fs.deleteFile = deleteFile.makeCaller(caller, objPath);
|
|
65
66
|
fs.deleteFolder = deleteFolder.makeCaller(caller, objPath);
|
|
66
67
|
fs.deleteLink = deleteLink.makeCaller(caller, objPath);
|
|
@@ -149,6 +150,7 @@ function exposeFSService(fs, expServices) {
|
|
|
149
150
|
if (fs.writable) {
|
|
150
151
|
implExp.copyFile = copyFile.wrapService(fs.copyFile);
|
|
151
152
|
implExp.copyFolder = copyFolder.wrapService(fs.copyFolder);
|
|
153
|
+
implExp.copyXAttrs = copyXAttrs.wrapService(fs.copyXAttrs);
|
|
152
154
|
implExp.deleteFile = deleteFile.wrapService(fs.deleteFile);
|
|
153
155
|
implExp.deleteFolder = deleteFolder.wrapService(fs.deleteFolder);
|
|
154
156
|
implExp.deleteLink = deleteLink.wrapService(fs.deleteLink);
|
|
@@ -1443,6 +1445,27 @@ var copyFolder;
|
|
|
1443
1445
|
copyFolder.makeCaller = makeCaller;
|
|
1444
1446
|
})(copyFolder || (copyFolder = {}));
|
|
1445
1447
|
Object.freeze(copyFolder);
|
|
1448
|
+
var copyXAttrs;
|
|
1449
|
+
(function (copyXAttrs) {
|
|
1450
|
+
const requestType = protobuf_type_1.ProtoType.for(fs_proto_1.fs.CopyXAttrsRequestBody);
|
|
1451
|
+
function wrapService(fn) {
|
|
1452
|
+
return buf => {
|
|
1453
|
+
const { src, dst, filter } = requestType.unpack(buf);
|
|
1454
|
+
const promise = fn(src, dst, filter);
|
|
1455
|
+
return { promise };
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
copyXAttrs.wrapService = wrapService;
|
|
1459
|
+
function makeCaller(caller, objPath) {
|
|
1460
|
+
const ipcPath = (0, protobuf_msg_1.methodPathFor)(objPath, 'copyXAttrs');
|
|
1461
|
+
return (src, dst, filter) => caller
|
|
1462
|
+
.startPromiseCall(ipcPath, requestType.pack({
|
|
1463
|
+
src, dst, filter: filter !== null && filter !== void 0 ? filter : []
|
|
1464
|
+
}));
|
|
1465
|
+
}
|
|
1466
|
+
copyXAttrs.makeCaller = makeCaller;
|
|
1467
|
+
})(copyXAttrs || (copyXAttrs = {}));
|
|
1468
|
+
Object.freeze(copyXAttrs);
|
|
1446
1469
|
var saveFile;
|
|
1447
1470
|
(function (saveFile) {
|
|
1448
1471
|
const requestType = protobuf_type_1.ProtoType.for(fs_proto_1.fs.SaveFileRequestBody);
|
|
@@ -184,6 +184,7 @@ function wrapWritableFS(fsImpl) {
|
|
|
184
184
|
move: fsImpl.move.bind(fsImpl),
|
|
185
185
|
copyFile: fsImpl.copyFile.bind(fsImpl),
|
|
186
186
|
copyFolder: fsImpl.copyFolder.bind(fsImpl),
|
|
187
|
+
copyXAttrs: fsImpl.copyXAttrs.bind(fsImpl),
|
|
187
188
|
writableFile: fsImpl.writableFile.bind(fsImpl),
|
|
188
189
|
writableSubRoot: fsImpl.writableSubRoot.bind(fsImpl),
|
|
189
190
|
saveFile: fsImpl.saveFile.bind(fsImpl),
|
|
@@ -85,6 +85,7 @@ export declare class DeviceFS implements WritableFS, Linkable {
|
|
|
85
85
|
watchTree(path: string, depth: number | undefined, observer: Observer<FolderEvent | FileEvent>): () => void;
|
|
86
86
|
copyFile(src: string, dst: string, overwrite?: boolean): Promise<void>;
|
|
87
87
|
copyFolder(src: string, dst: string, mergeAndOverwrite?: boolean): Promise<void>;
|
|
88
|
+
copyXAttrs(src: string, dst: string, filter?: string[]): Promise<void>;
|
|
88
89
|
saveFile(file: File, dst: string, overwrite?: boolean): Promise<void>;
|
|
89
90
|
saveFolder(folder: FS, dst: string, mergeAndOverwrite?: boolean): Promise<void>;
|
|
90
91
|
}
|
|
@@ -1213,7 +1213,7 @@ function diffNodes(current, remote, synced) {
|
|
|
1213
1213
|
const syncedNode = syncedNodesById.get(remoteNode.objId);
|
|
1214
1214
|
(0, assert_1.assert)(!!syncedNode);
|
|
1215
1215
|
const localChanged = !(0, node_in_fs_1.areBytesEqual)(localNode.key, syncedNode.key);
|
|
1216
|
-
const remoteChanged = !(0, node_in_fs_1.areBytesEqual)(
|
|
1216
|
+
const remoteChanged = !(0, node_in_fs_1.areBytesEqual)(remoteNode.key, syncedNode.key);
|
|
1217
1217
|
rekeyed.push({
|
|
1218
1218
|
local: localNode.name,
|
|
1219
1219
|
remote: remoteNode.name,
|
|
@@ -95,6 +95,7 @@ export declare class XspFS implements WritableFS {
|
|
|
95
95
|
readonlyFile(path: string): Promise<ReadonlyFile>;
|
|
96
96
|
writableFile(path: string, flags?: web3n.files.VersionedFileWriteFlags): Promise<WritableFile>;
|
|
97
97
|
copyFile(src: string, dst: string, overwrite?: boolean): Promise<void>;
|
|
98
|
+
copyXAttrs(src: string, dst: string, filter?: string[]): Promise<void>;
|
|
98
99
|
saveFile(file: File, dst: string, overwrite?: boolean): Promise<void>;
|
|
99
100
|
listFolder(folder: string): Promise<ListingEntry[]>;
|
|
100
101
|
readJSONFile<T>(path: string): Promise<T>;
|
|
@@ -448,9 +448,31 @@ class XspFS {
|
|
|
448
448
|
const sink = await this.getByteSink(dst, flags);
|
|
449
449
|
await (0, pipe_1.pipe)(srcBytes, sink);
|
|
450
450
|
}
|
|
451
|
+
async copyXAttrs(src, dst, filter) {
|
|
452
|
+
const srcAttrs = await this.listXAttrs(src);
|
|
453
|
+
if (srcAttrs.length === 0) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (filter && (filter.length > 0)) {
|
|
457
|
+
for (let i = 0; i <= srcAttrs.length; i += 1) {
|
|
458
|
+
const attr = srcAttrs[i];
|
|
459
|
+
if (!filter.includes(attr)) {
|
|
460
|
+
srcAttrs.splice(i, 1);
|
|
461
|
+
i -= 1;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if (srcAttrs.length === 0) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
const attrsToCopy = {};
|
|
469
|
+
for (const attr of srcAttrs) {
|
|
470
|
+
attrsToCopy[attr] = await this.getXAttr(src, attr);
|
|
471
|
+
}
|
|
472
|
+
await this.updateXAttrs(dst, { set: attrsToCopy });
|
|
473
|
+
}
|
|
451
474
|
async saveFile(file, dst, overwrite = false) {
|
|
452
|
-
const src = (file.v ?
|
|
453
|
-
(await file.v.getByteSource()).src : await file.getByteSource());
|
|
475
|
+
const src = (file.v ? (await file.v.getByteSource()).src : await file.getByteSource());
|
|
454
476
|
const flags = {
|
|
455
477
|
create: true,
|
|
456
478
|
exclusive: !overwrite,
|
|
@@ -15,3 +15,4 @@ export declare function areAddressesEqual(a: string, b: string): boolean;
|
|
|
15
15
|
* Otherwise, undefined is returned.
|
|
16
16
|
*/
|
|
17
17
|
export declare function checkAndTransformAddress(address: string): string | undefined;
|
|
18
|
+
export declare function includesAddress(arr: string[], address: string): boolean;
|
|
@@ -19,6 +19,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
exports.toCanonicalAddress = toCanonicalAddress;
|
|
20
20
|
exports.areAddressesEqual = areAddressesEqual;
|
|
21
21
|
exports.checkAndTransformAddress = checkAndTransformAddress;
|
|
22
|
+
exports.includesAddress = includesAddress;
|
|
22
23
|
const punycode_1 = require("punycode/");
|
|
23
24
|
/**
|
|
24
25
|
* @param address
|
|
@@ -30,8 +31,7 @@ function toCanonicalAddress(address) {
|
|
|
30
31
|
let user;
|
|
31
32
|
let domain;
|
|
32
33
|
if (indOfAt < 0) {
|
|
33
|
-
|
|
34
|
-
user = '';
|
|
34
|
+
throw makeParseExc(address, `No @ in given string`);
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
37
37
|
domain = address.substring(indOfAt + 1);
|
|
@@ -73,11 +73,11 @@ function makeParseExc(address, cause) {
|
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
function areAddressesEqual(a, b) {
|
|
76
|
-
const canonicalA =
|
|
76
|
+
const canonicalA = checkAndTransformAddress(a);
|
|
77
77
|
if (!canonicalA) {
|
|
78
78
|
return false;
|
|
79
79
|
}
|
|
80
|
-
const canonicalB =
|
|
80
|
+
const canonicalB = checkAndTransformAddress(b);
|
|
81
81
|
if (!canonicalB) {
|
|
82
82
|
return false;
|
|
83
83
|
}
|
|
@@ -94,4 +94,11 @@ function checkAndTransformAddress(address) {
|
|
|
94
94
|
}
|
|
95
95
|
catch (err) { }
|
|
96
96
|
}
|
|
97
|
+
function includesAddress(arr, address) {
|
|
98
|
+
const canonAddr = checkAndTransformAddress(address);
|
|
99
|
+
if (!canonAddr) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
return arr.map(checkAndTransformAddress).includes(canonAddr);
|
|
103
|
+
}
|
|
97
104
|
Object.freeze(exports);
|
|
@@ -15,6 +15,7 @@ export declare function forTableInsert<T extends object>(record: T, transforms:
|
|
|
15
15
|
insertParams: ParamsObject;
|
|
16
16
|
};
|
|
17
17
|
export declare function performTableInsert<T extends object>(db: Database, tabName: string, record: T, transforms: TransformDefinition<T>): void;
|
|
18
|
+
export declare function performTableInsertOrNothingOnConflict<T extends object>(db: Database, tabName: string, record: T, transforms: TransformDefinition<T>): boolean;
|
|
18
19
|
export declare function selectFromTable<T extends object>(db: Database, tabName: string, selectColumns: (keyof T)[] | '*', selectWith: Partial<T>, transforms: TransformDefinition<T>): Partial<T>[] | undefined;
|
|
19
20
|
export declare function updateInTable<T extends object>(db: Database, tabName: string, valuesToSet: Partial<T>, updateWith: Partial<T>, transforms: TransformDefinition<T>): void;
|
|
20
21
|
export declare function setExprFor<T extends object>(params: ParamsObject, omit?: (keyof T)[]): string;
|
|
@@ -22,6 +22,7 @@ exports.fromQueryResult = fromQueryResult;
|
|
|
22
22
|
exports.queryParamsFromComplete = queryParamsFromComplete;
|
|
23
23
|
exports.forTableInsert = forTableInsert;
|
|
24
24
|
exports.performTableInsert = performTableInsert;
|
|
25
|
+
exports.performTableInsertOrNothingOnConflict = performTableInsertOrNothingOnConflict;
|
|
25
26
|
exports.selectFromTable = selectFromTable;
|
|
26
27
|
exports.updateInTable = updateInTable;
|
|
27
28
|
exports.setExprFor = setExprFor;
|
|
@@ -102,6 +103,11 @@ function performTableInsert(db, tabName, record, transforms) {
|
|
|
102
103
|
const { insertParams, orderedColumns, orderedValues } = forTableInsert(record, transforms);
|
|
103
104
|
db.exec(`INSERT INTO ${tabName} (${orderedColumns}) VALUES (${orderedValues})`, insertParams);
|
|
104
105
|
}
|
|
106
|
+
function performTableInsertOrNothingOnConflict(db, tabName, record, transforms) {
|
|
107
|
+
const { insertParams, orderedColumns, orderedValues } = forTableInsert(record, transforms);
|
|
108
|
+
db.exec(`INSERT INTO ${tabName} (${orderedColumns}) VALUES (${orderedValues}) ON CONFLICT DO NOTHING`, insertParams);
|
|
109
|
+
return (db.getRowsModified() > 0);
|
|
110
|
+
}
|
|
105
111
|
function selectFromTable(db, tabName, selectColumns, selectWith, transforms) {
|
|
106
112
|
const whereParams = queryParamsFrom(selectWith, transforms);
|
|
107
113
|
const whereClause = andEqualExprFor(whereParams);
|
|
@@ -33158,6 +33158,312 @@ $root.fs = (function() {
|
|
|
33158
33158
|
return CopyFolderRequestBody;
|
|
33159
33159
|
})();
|
|
33160
33160
|
|
|
33161
|
+
fs.CopyXAttrsRequestBody = (function() {
|
|
33162
|
+
|
|
33163
|
+
/**
|
|
33164
|
+
* Properties of a CopyXAttrsRequestBody.
|
|
33165
|
+
* @memberof fs
|
|
33166
|
+
* @interface ICopyXAttrsRequestBody
|
|
33167
|
+
* @property {string|null} [src] CopyXAttrsRequestBody src
|
|
33168
|
+
* @property {string|null} [dst] CopyXAttrsRequestBody dst
|
|
33169
|
+
* @property {Array.<string>|null} [filter] CopyXAttrsRequestBody filter
|
|
33170
|
+
*/
|
|
33171
|
+
|
|
33172
|
+
/**
|
|
33173
|
+
* Constructs a new CopyXAttrsRequestBody.
|
|
33174
|
+
* @memberof fs
|
|
33175
|
+
* @classdesc Represents a CopyXAttrsRequestBody.
|
|
33176
|
+
* @implements ICopyXAttrsRequestBody
|
|
33177
|
+
* @constructor
|
|
33178
|
+
* @param {fs.ICopyXAttrsRequestBody=} [properties] Properties to set
|
|
33179
|
+
*/
|
|
33180
|
+
function CopyXAttrsRequestBody(properties) {
|
|
33181
|
+
this.filter = [];
|
|
33182
|
+
if (properties)
|
|
33183
|
+
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
|
|
33184
|
+
if (properties[keys[i]] != null && keys[i] !== "__proto__")
|
|
33185
|
+
this[keys[i]] = properties[keys[i]];
|
|
33186
|
+
}
|
|
33187
|
+
|
|
33188
|
+
/**
|
|
33189
|
+
* CopyXAttrsRequestBody src.
|
|
33190
|
+
* @member {string} src
|
|
33191
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
33192
|
+
* @instance
|
|
33193
|
+
*/
|
|
33194
|
+
CopyXAttrsRequestBody.prototype.src = "";
|
|
33195
|
+
|
|
33196
|
+
/**
|
|
33197
|
+
* CopyXAttrsRequestBody dst.
|
|
33198
|
+
* @member {string} dst
|
|
33199
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
33200
|
+
* @instance
|
|
33201
|
+
*/
|
|
33202
|
+
CopyXAttrsRequestBody.prototype.dst = "";
|
|
33203
|
+
|
|
33204
|
+
/**
|
|
33205
|
+
* CopyXAttrsRequestBody filter.
|
|
33206
|
+
* @member {Array.<string>} filter
|
|
33207
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
33208
|
+
* @instance
|
|
33209
|
+
*/
|
|
33210
|
+
CopyXAttrsRequestBody.prototype.filter = $util.emptyArray;
|
|
33211
|
+
|
|
33212
|
+
/**
|
|
33213
|
+
* Creates a new CopyXAttrsRequestBody instance using the specified properties.
|
|
33214
|
+
* @function create
|
|
33215
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
33216
|
+
* @static
|
|
33217
|
+
* @param {fs.ICopyXAttrsRequestBody=} [properties] Properties to set
|
|
33218
|
+
* @returns {fs.CopyXAttrsRequestBody} CopyXAttrsRequestBody instance
|
|
33219
|
+
*/
|
|
33220
|
+
CopyXAttrsRequestBody.create = function create(properties) {
|
|
33221
|
+
return new CopyXAttrsRequestBody(properties);
|
|
33222
|
+
};
|
|
33223
|
+
|
|
33224
|
+
/**
|
|
33225
|
+
* Encodes the specified CopyXAttrsRequestBody message. Does not implicitly {@link fs.CopyXAttrsRequestBody.verify|verify} messages.
|
|
33226
|
+
* @function encode
|
|
33227
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
33228
|
+
* @static
|
|
33229
|
+
* @param {fs.ICopyXAttrsRequestBody} message CopyXAttrsRequestBody message or plain object to encode
|
|
33230
|
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
|
33231
|
+
* @returns {$protobuf.Writer} Writer
|
|
33232
|
+
*/
|
|
33233
|
+
CopyXAttrsRequestBody.encode = function encode(message, writer, q) {
|
|
33234
|
+
if (!writer)
|
|
33235
|
+
writer = $Writer.create();
|
|
33236
|
+
if (q === undefined)
|
|
33237
|
+
q = 0;
|
|
33238
|
+
if (q > $util.recursionLimit)
|
|
33239
|
+
throw Error("max depth exceeded");
|
|
33240
|
+
if (message.src != null && Object.hasOwnProperty.call(message, "src"))
|
|
33241
|
+
writer.uint32(/* id 1, wireType 2 =*/10).string(message.src);
|
|
33242
|
+
if (message.dst != null && Object.hasOwnProperty.call(message, "dst"))
|
|
33243
|
+
writer.uint32(/* id 2, wireType 2 =*/18).string(message.dst);
|
|
33244
|
+
if (message.filter != null && message.filter.length)
|
|
33245
|
+
for (var i = 0; i < message.filter.length; ++i)
|
|
33246
|
+
writer.uint32(/* id 3, wireType 2 =*/26).string(message.filter[i]);
|
|
33247
|
+
return writer;
|
|
33248
|
+
};
|
|
33249
|
+
|
|
33250
|
+
/**
|
|
33251
|
+
* Encodes the specified CopyXAttrsRequestBody message, length delimited. Does not implicitly {@link fs.CopyXAttrsRequestBody.verify|verify} messages.
|
|
33252
|
+
* @function encodeDelimited
|
|
33253
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
33254
|
+
* @static
|
|
33255
|
+
* @param {fs.ICopyXAttrsRequestBody} message CopyXAttrsRequestBody message or plain object to encode
|
|
33256
|
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
|
33257
|
+
* @returns {$protobuf.Writer} Writer
|
|
33258
|
+
*/
|
|
33259
|
+
CopyXAttrsRequestBody.encodeDelimited = function encodeDelimited(message, writer) {
|
|
33260
|
+
return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
|
|
33261
|
+
};
|
|
33262
|
+
|
|
33263
|
+
/**
|
|
33264
|
+
* Decodes a CopyXAttrsRequestBody message from the specified reader or buffer.
|
|
33265
|
+
* @function decode
|
|
33266
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
33267
|
+
* @static
|
|
33268
|
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
|
33269
|
+
* @param {number} [length] Message length if known beforehand
|
|
33270
|
+
* @returns {fs.CopyXAttrsRequestBody} CopyXAttrsRequestBody
|
|
33271
|
+
* @throws {Error} If the payload is not a reader or valid buffer
|
|
33272
|
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
33273
|
+
*/
|
|
33274
|
+
CopyXAttrsRequestBody.decode = function decode(reader, length, error, long) {
|
|
33275
|
+
if (!(reader instanceof $Reader))
|
|
33276
|
+
reader = $Reader.create(reader);
|
|
33277
|
+
if (long === undefined)
|
|
33278
|
+
long = 0;
|
|
33279
|
+
if (long > $Reader.recursionLimit)
|
|
33280
|
+
throw Error("maximum nesting depth exceeded");
|
|
33281
|
+
var end, message;
|
|
33282
|
+
if (length === undefined)
|
|
33283
|
+
end = reader.len;
|
|
33284
|
+
else {
|
|
33285
|
+
end = reader.pos + length;
|
|
33286
|
+
if (end > reader.len)
|
|
33287
|
+
throw RangeError("index out of range");
|
|
33288
|
+
length = reader.len;
|
|
33289
|
+
reader.len = end;
|
|
33290
|
+
}
|
|
33291
|
+
message = new $root.fs.CopyXAttrsRequestBody();
|
|
33292
|
+
while (reader.pos < end) {
|
|
33293
|
+
var tag = reader.uint32();
|
|
33294
|
+
if (tag === error)
|
|
33295
|
+
break;
|
|
33296
|
+
switch (tag >>> 3) {
|
|
33297
|
+
case 1: {
|
|
33298
|
+
message.src = reader.string();
|
|
33299
|
+
break;
|
|
33300
|
+
}
|
|
33301
|
+
case 2: {
|
|
33302
|
+
message.dst = reader.string();
|
|
33303
|
+
break;
|
|
33304
|
+
}
|
|
33305
|
+
case 3: {
|
|
33306
|
+
if (!(message.filter && message.filter.length))
|
|
33307
|
+
message.filter = [];
|
|
33308
|
+
message.filter.push(reader.string());
|
|
33309
|
+
break;
|
|
33310
|
+
}
|
|
33311
|
+
default:
|
|
33312
|
+
reader.skipType(tag & 7, long);
|
|
33313
|
+
break;
|
|
33314
|
+
}
|
|
33315
|
+
}
|
|
33316
|
+
if (length !== undefined) {
|
|
33317
|
+
if (reader.pos !== end)
|
|
33318
|
+
throw RangeError("index out of range");
|
|
33319
|
+
reader.len = length;
|
|
33320
|
+
}
|
|
33321
|
+
return message;
|
|
33322
|
+
};
|
|
33323
|
+
|
|
33324
|
+
/**
|
|
33325
|
+
* Decodes a CopyXAttrsRequestBody message from the specified reader or buffer, length delimited.
|
|
33326
|
+
* @function decodeDelimited
|
|
33327
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
33328
|
+
* @static
|
|
33329
|
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
|
33330
|
+
* @returns {fs.CopyXAttrsRequestBody} CopyXAttrsRequestBody
|
|
33331
|
+
* @throws {Error} If the payload is not a reader or valid buffer
|
|
33332
|
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
33333
|
+
*/
|
|
33334
|
+
CopyXAttrsRequestBody.decodeDelimited = function decodeDelimited(reader) {
|
|
33335
|
+
if (!(reader instanceof $Reader))
|
|
33336
|
+
reader = new $Reader(reader);
|
|
33337
|
+
return this.decode(reader, reader.uint32());
|
|
33338
|
+
};
|
|
33339
|
+
|
|
33340
|
+
/**
|
|
33341
|
+
* Verifies a CopyXAttrsRequestBody message.
|
|
33342
|
+
* @function verify
|
|
33343
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
33344
|
+
* @static
|
|
33345
|
+
* @param {Object.<string,*>} message Plain object to verify
|
|
33346
|
+
* @returns {string|null} `null` if valid, otherwise the reason why it is not
|
|
33347
|
+
*/
|
|
33348
|
+
CopyXAttrsRequestBody.verify = function verify(message, long) {
|
|
33349
|
+
if (typeof message !== "object" || message === null)
|
|
33350
|
+
return "object expected";
|
|
33351
|
+
if (long === undefined)
|
|
33352
|
+
long = 0;
|
|
33353
|
+
if (long > $util.recursionLimit)
|
|
33354
|
+
return "maximum nesting depth exceeded";
|
|
33355
|
+
if (message.src != null && Object.hasOwnProperty.call(message, "src"))
|
|
33356
|
+
if (!$util.isString(message.src))
|
|
33357
|
+
return "src: string expected";
|
|
33358
|
+
if (message.dst != null && Object.hasOwnProperty.call(message, "dst"))
|
|
33359
|
+
if (!$util.isString(message.dst))
|
|
33360
|
+
return "dst: string expected";
|
|
33361
|
+
if (message.filter != null && Object.hasOwnProperty.call(message, "filter")) {
|
|
33362
|
+
if (!Array.isArray(message.filter))
|
|
33363
|
+
return "filter: array expected";
|
|
33364
|
+
for (var i = 0; i < message.filter.length; ++i)
|
|
33365
|
+
if (!$util.isString(message.filter[i]))
|
|
33366
|
+
return "filter: string[] expected";
|
|
33367
|
+
}
|
|
33368
|
+
return null;
|
|
33369
|
+
};
|
|
33370
|
+
|
|
33371
|
+
/**
|
|
33372
|
+
* Creates a CopyXAttrsRequestBody message from a plain object. Also converts values to their respective internal types.
|
|
33373
|
+
* @function fromObject
|
|
33374
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
33375
|
+
* @static
|
|
33376
|
+
* @param {Object.<string,*>} object Plain object
|
|
33377
|
+
* @returns {fs.CopyXAttrsRequestBody} CopyXAttrsRequestBody
|
|
33378
|
+
*/
|
|
33379
|
+
CopyXAttrsRequestBody.fromObject = function fromObject(object, long) {
|
|
33380
|
+
if (object instanceof $root.fs.CopyXAttrsRequestBody)
|
|
33381
|
+
return object;
|
|
33382
|
+
if (!$util.isObject(object))
|
|
33383
|
+
throw TypeError(".fs.CopyXAttrsRequestBody: object expected");
|
|
33384
|
+
if (long === undefined)
|
|
33385
|
+
long = 0;
|
|
33386
|
+
if (long > $util.recursionLimit)
|
|
33387
|
+
throw Error("maximum nesting depth exceeded");
|
|
33388
|
+
var message = new $root.fs.CopyXAttrsRequestBody();
|
|
33389
|
+
if (object.src != null)
|
|
33390
|
+
message.src = String(object.src);
|
|
33391
|
+
if (object.dst != null)
|
|
33392
|
+
message.dst = String(object.dst);
|
|
33393
|
+
if (object.filter) {
|
|
33394
|
+
if (!Array.isArray(object.filter))
|
|
33395
|
+
throw TypeError(".fs.CopyXAttrsRequestBody.filter: array expected");
|
|
33396
|
+
message.filter = [];
|
|
33397
|
+
for (var i = 0; i < object.filter.length; ++i)
|
|
33398
|
+
message.filter[i] = String(object.filter[i]);
|
|
33399
|
+
}
|
|
33400
|
+
return message;
|
|
33401
|
+
};
|
|
33402
|
+
|
|
33403
|
+
/**
|
|
33404
|
+
* Creates a plain object from a CopyXAttrsRequestBody message. Also converts values to other types if specified.
|
|
33405
|
+
* @function toObject
|
|
33406
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
33407
|
+
* @static
|
|
33408
|
+
* @param {fs.CopyXAttrsRequestBody} message CopyXAttrsRequestBody
|
|
33409
|
+
* @param {$protobuf.IConversionOptions} [options] Conversion options
|
|
33410
|
+
* @returns {Object.<string,*>} Plain object
|
|
33411
|
+
*/
|
|
33412
|
+
CopyXAttrsRequestBody.toObject = function toObject(message, options, q) {
|
|
33413
|
+
if (!options)
|
|
33414
|
+
options = {};
|
|
33415
|
+
if (q === undefined)
|
|
33416
|
+
q = 0;
|
|
33417
|
+
if (q > $util.recursionLimit)
|
|
33418
|
+
throw Error("max depth exceeded");
|
|
33419
|
+
var object = {};
|
|
33420
|
+
if (options.arrays || options.defaults)
|
|
33421
|
+
object.filter = [];
|
|
33422
|
+
if (options.defaults) {
|
|
33423
|
+
object.src = "";
|
|
33424
|
+
object.dst = "";
|
|
33425
|
+
}
|
|
33426
|
+
if (message.src != null && Object.hasOwnProperty.call(message, "src"))
|
|
33427
|
+
object.src = message.src;
|
|
33428
|
+
if (message.dst != null && Object.hasOwnProperty.call(message, "dst"))
|
|
33429
|
+
object.dst = message.dst;
|
|
33430
|
+
if (message.filter && message.filter.length) {
|
|
33431
|
+
object.filter = [];
|
|
33432
|
+
for (var j = 0; j < message.filter.length; ++j)
|
|
33433
|
+
object.filter[j] = message.filter[j];
|
|
33434
|
+
}
|
|
33435
|
+
return object;
|
|
33436
|
+
};
|
|
33437
|
+
|
|
33438
|
+
/**
|
|
33439
|
+
* Converts this CopyXAttrsRequestBody to JSON.
|
|
33440
|
+
* @function toJSON
|
|
33441
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
33442
|
+
* @instance
|
|
33443
|
+
* @returns {Object.<string,*>} JSON object
|
|
33444
|
+
*/
|
|
33445
|
+
CopyXAttrsRequestBody.prototype.toJSON = function toJSON() {
|
|
33446
|
+
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
|
33447
|
+
};
|
|
33448
|
+
|
|
33449
|
+
/**
|
|
33450
|
+
* Gets the default type url for CopyXAttrsRequestBody
|
|
33451
|
+
* @function getTypeUrl
|
|
33452
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
33453
|
+
* @static
|
|
33454
|
+
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
|
|
33455
|
+
* @returns {string} The default type url
|
|
33456
|
+
*/
|
|
33457
|
+
CopyXAttrsRequestBody.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
|
|
33458
|
+
if (typeUrlPrefix === undefined) {
|
|
33459
|
+
typeUrlPrefix = "type.googleapis.com";
|
|
33460
|
+
}
|
|
33461
|
+
return typeUrlPrefix + "/fs.CopyXAttrsRequestBody";
|
|
33462
|
+
};
|
|
33463
|
+
|
|
33464
|
+
return CopyXAttrsRequestBody;
|
|
33465
|
+
})();
|
|
33466
|
+
|
|
33161
33467
|
fs.SaveFileRequestBody = (function() {
|
|
33162
33468
|
|
|
33163
33469
|
/**
|
package/build/protos/fs.proto.js
CHANGED
|
@@ -9058,6 +9058,312 @@ $root.fs = (function() {
|
|
|
9058
9058
|
return CopyFolderRequestBody;
|
|
9059
9059
|
})();
|
|
9060
9060
|
|
|
9061
|
+
fs.CopyXAttrsRequestBody = (function() {
|
|
9062
|
+
|
|
9063
|
+
/**
|
|
9064
|
+
* Properties of a CopyXAttrsRequestBody.
|
|
9065
|
+
* @memberof fs
|
|
9066
|
+
* @interface ICopyXAttrsRequestBody
|
|
9067
|
+
* @property {string|null} [src] CopyXAttrsRequestBody src
|
|
9068
|
+
* @property {string|null} [dst] CopyXAttrsRequestBody dst
|
|
9069
|
+
* @property {Array.<string>|null} [filter] CopyXAttrsRequestBody filter
|
|
9070
|
+
*/
|
|
9071
|
+
|
|
9072
|
+
/**
|
|
9073
|
+
* Constructs a new CopyXAttrsRequestBody.
|
|
9074
|
+
* @memberof fs
|
|
9075
|
+
* @classdesc Represents a CopyXAttrsRequestBody.
|
|
9076
|
+
* @implements ICopyXAttrsRequestBody
|
|
9077
|
+
* @constructor
|
|
9078
|
+
* @param {fs.ICopyXAttrsRequestBody=} [properties] Properties to set
|
|
9079
|
+
*/
|
|
9080
|
+
function CopyXAttrsRequestBody(properties) {
|
|
9081
|
+
this.filter = [];
|
|
9082
|
+
if (properties)
|
|
9083
|
+
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
|
|
9084
|
+
if (properties[keys[i]] != null && keys[i] !== "__proto__")
|
|
9085
|
+
this[keys[i]] = properties[keys[i]];
|
|
9086
|
+
}
|
|
9087
|
+
|
|
9088
|
+
/**
|
|
9089
|
+
* CopyXAttrsRequestBody src.
|
|
9090
|
+
* @member {string} src
|
|
9091
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
9092
|
+
* @instance
|
|
9093
|
+
*/
|
|
9094
|
+
CopyXAttrsRequestBody.prototype.src = "";
|
|
9095
|
+
|
|
9096
|
+
/**
|
|
9097
|
+
* CopyXAttrsRequestBody dst.
|
|
9098
|
+
* @member {string} dst
|
|
9099
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
9100
|
+
* @instance
|
|
9101
|
+
*/
|
|
9102
|
+
CopyXAttrsRequestBody.prototype.dst = "";
|
|
9103
|
+
|
|
9104
|
+
/**
|
|
9105
|
+
* CopyXAttrsRequestBody filter.
|
|
9106
|
+
* @member {Array.<string>} filter
|
|
9107
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
9108
|
+
* @instance
|
|
9109
|
+
*/
|
|
9110
|
+
CopyXAttrsRequestBody.prototype.filter = $util.emptyArray;
|
|
9111
|
+
|
|
9112
|
+
/**
|
|
9113
|
+
* Creates a new CopyXAttrsRequestBody instance using the specified properties.
|
|
9114
|
+
* @function create
|
|
9115
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
9116
|
+
* @static
|
|
9117
|
+
* @param {fs.ICopyXAttrsRequestBody=} [properties] Properties to set
|
|
9118
|
+
* @returns {fs.CopyXAttrsRequestBody} CopyXAttrsRequestBody instance
|
|
9119
|
+
*/
|
|
9120
|
+
CopyXAttrsRequestBody.create = function create(properties) {
|
|
9121
|
+
return new CopyXAttrsRequestBody(properties);
|
|
9122
|
+
};
|
|
9123
|
+
|
|
9124
|
+
/**
|
|
9125
|
+
* Encodes the specified CopyXAttrsRequestBody message. Does not implicitly {@link fs.CopyXAttrsRequestBody.verify|verify} messages.
|
|
9126
|
+
* @function encode
|
|
9127
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
9128
|
+
* @static
|
|
9129
|
+
* @param {fs.ICopyXAttrsRequestBody} message CopyXAttrsRequestBody message or plain object to encode
|
|
9130
|
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
|
9131
|
+
* @returns {$protobuf.Writer} Writer
|
|
9132
|
+
*/
|
|
9133
|
+
CopyXAttrsRequestBody.encode = function encode(message, writer, q) {
|
|
9134
|
+
if (!writer)
|
|
9135
|
+
writer = $Writer.create();
|
|
9136
|
+
if (q === undefined)
|
|
9137
|
+
q = 0;
|
|
9138
|
+
if (q > $util.recursionLimit)
|
|
9139
|
+
throw Error("max depth exceeded");
|
|
9140
|
+
if (message.src != null && Object.hasOwnProperty.call(message, "src"))
|
|
9141
|
+
writer.uint32(/* id 1, wireType 2 =*/10).string(message.src);
|
|
9142
|
+
if (message.dst != null && Object.hasOwnProperty.call(message, "dst"))
|
|
9143
|
+
writer.uint32(/* id 2, wireType 2 =*/18).string(message.dst);
|
|
9144
|
+
if (message.filter != null && message.filter.length)
|
|
9145
|
+
for (var i = 0; i < message.filter.length; ++i)
|
|
9146
|
+
writer.uint32(/* id 3, wireType 2 =*/26).string(message.filter[i]);
|
|
9147
|
+
return writer;
|
|
9148
|
+
};
|
|
9149
|
+
|
|
9150
|
+
/**
|
|
9151
|
+
* Encodes the specified CopyXAttrsRequestBody message, length delimited. Does not implicitly {@link fs.CopyXAttrsRequestBody.verify|verify} messages.
|
|
9152
|
+
* @function encodeDelimited
|
|
9153
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
9154
|
+
* @static
|
|
9155
|
+
* @param {fs.ICopyXAttrsRequestBody} message CopyXAttrsRequestBody message or plain object to encode
|
|
9156
|
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
|
9157
|
+
* @returns {$protobuf.Writer} Writer
|
|
9158
|
+
*/
|
|
9159
|
+
CopyXAttrsRequestBody.encodeDelimited = function encodeDelimited(message, writer) {
|
|
9160
|
+
return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
|
|
9161
|
+
};
|
|
9162
|
+
|
|
9163
|
+
/**
|
|
9164
|
+
* Decodes a CopyXAttrsRequestBody message from the specified reader or buffer.
|
|
9165
|
+
* @function decode
|
|
9166
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
9167
|
+
* @static
|
|
9168
|
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
|
9169
|
+
* @param {number} [length] Message length if known beforehand
|
|
9170
|
+
* @returns {fs.CopyXAttrsRequestBody} CopyXAttrsRequestBody
|
|
9171
|
+
* @throws {Error} If the payload is not a reader or valid buffer
|
|
9172
|
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
9173
|
+
*/
|
|
9174
|
+
CopyXAttrsRequestBody.decode = function decode(reader, length, error, long) {
|
|
9175
|
+
if (!(reader instanceof $Reader))
|
|
9176
|
+
reader = $Reader.create(reader);
|
|
9177
|
+
if (long === undefined)
|
|
9178
|
+
long = 0;
|
|
9179
|
+
if (long > $Reader.recursionLimit)
|
|
9180
|
+
throw Error("maximum nesting depth exceeded");
|
|
9181
|
+
var end, message;
|
|
9182
|
+
if (length === undefined)
|
|
9183
|
+
end = reader.len;
|
|
9184
|
+
else {
|
|
9185
|
+
end = reader.pos + length;
|
|
9186
|
+
if (end > reader.len)
|
|
9187
|
+
throw RangeError("index out of range");
|
|
9188
|
+
length = reader.len;
|
|
9189
|
+
reader.len = end;
|
|
9190
|
+
}
|
|
9191
|
+
message = new $root.fs.CopyXAttrsRequestBody();
|
|
9192
|
+
while (reader.pos < end) {
|
|
9193
|
+
var tag = reader.uint32();
|
|
9194
|
+
if (tag === error)
|
|
9195
|
+
break;
|
|
9196
|
+
switch (tag >>> 3) {
|
|
9197
|
+
case 1: {
|
|
9198
|
+
message.src = reader.string();
|
|
9199
|
+
break;
|
|
9200
|
+
}
|
|
9201
|
+
case 2: {
|
|
9202
|
+
message.dst = reader.string();
|
|
9203
|
+
break;
|
|
9204
|
+
}
|
|
9205
|
+
case 3: {
|
|
9206
|
+
if (!(message.filter && message.filter.length))
|
|
9207
|
+
message.filter = [];
|
|
9208
|
+
message.filter.push(reader.string());
|
|
9209
|
+
break;
|
|
9210
|
+
}
|
|
9211
|
+
default:
|
|
9212
|
+
reader.skipType(tag & 7, long);
|
|
9213
|
+
break;
|
|
9214
|
+
}
|
|
9215
|
+
}
|
|
9216
|
+
if (length !== undefined) {
|
|
9217
|
+
if (reader.pos !== end)
|
|
9218
|
+
throw RangeError("index out of range");
|
|
9219
|
+
reader.len = length;
|
|
9220
|
+
}
|
|
9221
|
+
return message;
|
|
9222
|
+
};
|
|
9223
|
+
|
|
9224
|
+
/**
|
|
9225
|
+
* Decodes a CopyXAttrsRequestBody message from the specified reader or buffer, length delimited.
|
|
9226
|
+
* @function decodeDelimited
|
|
9227
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
9228
|
+
* @static
|
|
9229
|
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
|
9230
|
+
* @returns {fs.CopyXAttrsRequestBody} CopyXAttrsRequestBody
|
|
9231
|
+
* @throws {Error} If the payload is not a reader or valid buffer
|
|
9232
|
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
9233
|
+
*/
|
|
9234
|
+
CopyXAttrsRequestBody.decodeDelimited = function decodeDelimited(reader) {
|
|
9235
|
+
if (!(reader instanceof $Reader))
|
|
9236
|
+
reader = new $Reader(reader);
|
|
9237
|
+
return this.decode(reader, reader.uint32());
|
|
9238
|
+
};
|
|
9239
|
+
|
|
9240
|
+
/**
|
|
9241
|
+
* Verifies a CopyXAttrsRequestBody message.
|
|
9242
|
+
* @function verify
|
|
9243
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
9244
|
+
* @static
|
|
9245
|
+
* @param {Object.<string,*>} message Plain object to verify
|
|
9246
|
+
* @returns {string|null} `null` if valid, otherwise the reason why it is not
|
|
9247
|
+
*/
|
|
9248
|
+
CopyXAttrsRequestBody.verify = function verify(message, long) {
|
|
9249
|
+
if (typeof message !== "object" || message === null)
|
|
9250
|
+
return "object expected";
|
|
9251
|
+
if (long === undefined)
|
|
9252
|
+
long = 0;
|
|
9253
|
+
if (long > $util.recursionLimit)
|
|
9254
|
+
return "maximum nesting depth exceeded";
|
|
9255
|
+
if (message.src != null && Object.hasOwnProperty.call(message, "src"))
|
|
9256
|
+
if (!$util.isString(message.src))
|
|
9257
|
+
return "src: string expected";
|
|
9258
|
+
if (message.dst != null && Object.hasOwnProperty.call(message, "dst"))
|
|
9259
|
+
if (!$util.isString(message.dst))
|
|
9260
|
+
return "dst: string expected";
|
|
9261
|
+
if (message.filter != null && Object.hasOwnProperty.call(message, "filter")) {
|
|
9262
|
+
if (!Array.isArray(message.filter))
|
|
9263
|
+
return "filter: array expected";
|
|
9264
|
+
for (var i = 0; i < message.filter.length; ++i)
|
|
9265
|
+
if (!$util.isString(message.filter[i]))
|
|
9266
|
+
return "filter: string[] expected";
|
|
9267
|
+
}
|
|
9268
|
+
return null;
|
|
9269
|
+
};
|
|
9270
|
+
|
|
9271
|
+
/**
|
|
9272
|
+
* Creates a CopyXAttrsRequestBody message from a plain object. Also converts values to their respective internal types.
|
|
9273
|
+
* @function fromObject
|
|
9274
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
9275
|
+
* @static
|
|
9276
|
+
* @param {Object.<string,*>} object Plain object
|
|
9277
|
+
* @returns {fs.CopyXAttrsRequestBody} CopyXAttrsRequestBody
|
|
9278
|
+
*/
|
|
9279
|
+
CopyXAttrsRequestBody.fromObject = function fromObject(object, long) {
|
|
9280
|
+
if (object instanceof $root.fs.CopyXAttrsRequestBody)
|
|
9281
|
+
return object;
|
|
9282
|
+
if (!$util.isObject(object))
|
|
9283
|
+
throw TypeError(".fs.CopyXAttrsRequestBody: object expected");
|
|
9284
|
+
if (long === undefined)
|
|
9285
|
+
long = 0;
|
|
9286
|
+
if (long > $util.recursionLimit)
|
|
9287
|
+
throw Error("maximum nesting depth exceeded");
|
|
9288
|
+
var message = new $root.fs.CopyXAttrsRequestBody();
|
|
9289
|
+
if (object.src != null)
|
|
9290
|
+
message.src = String(object.src);
|
|
9291
|
+
if (object.dst != null)
|
|
9292
|
+
message.dst = String(object.dst);
|
|
9293
|
+
if (object.filter) {
|
|
9294
|
+
if (!Array.isArray(object.filter))
|
|
9295
|
+
throw TypeError(".fs.CopyXAttrsRequestBody.filter: array expected");
|
|
9296
|
+
message.filter = [];
|
|
9297
|
+
for (var i = 0; i < object.filter.length; ++i)
|
|
9298
|
+
message.filter[i] = String(object.filter[i]);
|
|
9299
|
+
}
|
|
9300
|
+
return message;
|
|
9301
|
+
};
|
|
9302
|
+
|
|
9303
|
+
/**
|
|
9304
|
+
* Creates a plain object from a CopyXAttrsRequestBody message. Also converts values to other types if specified.
|
|
9305
|
+
* @function toObject
|
|
9306
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
9307
|
+
* @static
|
|
9308
|
+
* @param {fs.CopyXAttrsRequestBody} message CopyXAttrsRequestBody
|
|
9309
|
+
* @param {$protobuf.IConversionOptions} [options] Conversion options
|
|
9310
|
+
* @returns {Object.<string,*>} Plain object
|
|
9311
|
+
*/
|
|
9312
|
+
CopyXAttrsRequestBody.toObject = function toObject(message, options, q) {
|
|
9313
|
+
if (!options)
|
|
9314
|
+
options = {};
|
|
9315
|
+
if (q === undefined)
|
|
9316
|
+
q = 0;
|
|
9317
|
+
if (q > $util.recursionLimit)
|
|
9318
|
+
throw Error("max depth exceeded");
|
|
9319
|
+
var object = {};
|
|
9320
|
+
if (options.arrays || options.defaults)
|
|
9321
|
+
object.filter = [];
|
|
9322
|
+
if (options.defaults) {
|
|
9323
|
+
object.src = "";
|
|
9324
|
+
object.dst = "";
|
|
9325
|
+
}
|
|
9326
|
+
if (message.src != null && Object.hasOwnProperty.call(message, "src"))
|
|
9327
|
+
object.src = message.src;
|
|
9328
|
+
if (message.dst != null && Object.hasOwnProperty.call(message, "dst"))
|
|
9329
|
+
object.dst = message.dst;
|
|
9330
|
+
if (message.filter && message.filter.length) {
|
|
9331
|
+
object.filter = [];
|
|
9332
|
+
for (var j = 0; j < message.filter.length; ++j)
|
|
9333
|
+
object.filter[j] = message.filter[j];
|
|
9334
|
+
}
|
|
9335
|
+
return object;
|
|
9336
|
+
};
|
|
9337
|
+
|
|
9338
|
+
/**
|
|
9339
|
+
* Converts this CopyXAttrsRequestBody to JSON.
|
|
9340
|
+
* @function toJSON
|
|
9341
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
9342
|
+
* @instance
|
|
9343
|
+
* @returns {Object.<string,*>} JSON object
|
|
9344
|
+
*/
|
|
9345
|
+
CopyXAttrsRequestBody.prototype.toJSON = function toJSON() {
|
|
9346
|
+
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
|
9347
|
+
};
|
|
9348
|
+
|
|
9349
|
+
/**
|
|
9350
|
+
* Gets the default type url for CopyXAttrsRequestBody
|
|
9351
|
+
* @function getTypeUrl
|
|
9352
|
+
* @memberof fs.CopyXAttrsRequestBody
|
|
9353
|
+
* @static
|
|
9354
|
+
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
|
|
9355
|
+
* @returns {string} The default type url
|
|
9356
|
+
*/
|
|
9357
|
+
CopyXAttrsRequestBody.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
|
|
9358
|
+
if (typeUrlPrefix === undefined) {
|
|
9359
|
+
typeUrlPrefix = "type.googleapis.com";
|
|
9360
|
+
}
|
|
9361
|
+
return typeUrlPrefix + "/fs.CopyXAttrsRequestBody";
|
|
9362
|
+
};
|
|
9363
|
+
|
|
9364
|
+
return CopyXAttrsRequestBody;
|
|
9365
|
+
})();
|
|
9366
|
+
|
|
9061
9367
|
fs.SaveFileRequestBody = (function() {
|
|
9062
9368
|
|
|
9063
9369
|
/**
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2026 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.specs = void 0;
|
|
20
|
+
const random_node_1 = require("../../../../lib-common-on-node/random-node");
|
|
21
|
+
const bytes_equal_1 = require("../../../libs-for-tests/bytes-equal");
|
|
22
|
+
exports.specs = {
|
|
23
|
+
description: '.copyFile',
|
|
24
|
+
its: []
|
|
25
|
+
};
|
|
26
|
+
let it = {
|
|
27
|
+
expectation: 'if not allowed to create, fails for missing file',
|
|
28
|
+
};
|
|
29
|
+
it.func = async function (s) {
|
|
30
|
+
const { testFS } = s;
|
|
31
|
+
try {
|
|
32
|
+
await testFS.copyFile('non-existing-file', 'copy');
|
|
33
|
+
fail('should fail for missing source file');
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
expect(e.notFound).toBe(true);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
exports.specs.its.push(it);
|
|
40
|
+
it = {
|
|
41
|
+
expectation: 'copies file content'
|
|
42
|
+
};
|
|
43
|
+
it.func = async function (s) {
|
|
44
|
+
const { testFS } = s;
|
|
45
|
+
const src = `source.txt`;
|
|
46
|
+
const dst = `destination.txt`;
|
|
47
|
+
const content = await (0, random_node_1.bytes)(250);
|
|
48
|
+
await testFS.writeBytes(src, content);
|
|
49
|
+
await testFS.copyFile(src, dst);
|
|
50
|
+
const bytesInDst = await testFS.readBytes(dst);
|
|
51
|
+
expect((0, bytes_equal_1.bytesEqual)(bytesInDst, content)).toBeTrue();
|
|
52
|
+
};
|
|
53
|
+
exports.specs.its.push(it);
|
|
54
|
+
it = {
|
|
55
|
+
expectation: 'copies file content but not xattrs',
|
|
56
|
+
notIncludedIn: 'device-fs'
|
|
57
|
+
};
|
|
58
|
+
it.func = async function (s) {
|
|
59
|
+
const { testFS } = s;
|
|
60
|
+
const src = `source.txt`;
|
|
61
|
+
const attrName = `some-attr`;
|
|
62
|
+
const dst = `destination.txt`;
|
|
63
|
+
const content = await (0, random_node_1.bytes)(250);
|
|
64
|
+
await testFS.writeBytes(src, content);
|
|
65
|
+
await testFS.updateXAttrs(src, { set: { [attrName]: await (0, random_node_1.stringOfB64Chars)(30) } });
|
|
66
|
+
await testFS.copyFile(src, dst);
|
|
67
|
+
const bytesInDst = await testFS.readBytes(dst);
|
|
68
|
+
expect((0, bytes_equal_1.bytesEqual)(bytesInDst, content)).toBeTrue();
|
|
69
|
+
const attrInDst = await testFS.getXAttr(dst, attrName);
|
|
70
|
+
expect(attrInDst).toBeUndefined();
|
|
71
|
+
};
|
|
72
|
+
exports.specs.its.push(it);
|
|
73
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2026 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.specs = void 0;
|
|
20
|
+
const random_node_1 = require("../../../../lib-common-on-node/random-node");
|
|
21
|
+
const bytes_equal_1 = require("../../../libs-for-tests/bytes-equal");
|
|
22
|
+
const json_equal_1 = require("../../../libs-for-tests/json-equal");
|
|
23
|
+
exports.specs = {
|
|
24
|
+
description: '.copyXAttrs',
|
|
25
|
+
its: []
|
|
26
|
+
};
|
|
27
|
+
let it = {
|
|
28
|
+
expectation: 'fails for missing file',
|
|
29
|
+
notIncludedIn: 'device-fs'
|
|
30
|
+
};
|
|
31
|
+
it.func = async function (s) {
|
|
32
|
+
const { testFS } = s;
|
|
33
|
+
const unknown = 'non-existing-file';
|
|
34
|
+
try {
|
|
35
|
+
await testFS.copyXAttrs(unknown, 'copy');
|
|
36
|
+
fail('should fail for missing source file');
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
expect(e.notFound).toBe(true);
|
|
40
|
+
}
|
|
41
|
+
const src = `source.txt`;
|
|
42
|
+
const content = await (0, random_node_1.bytes)(250);
|
|
43
|
+
await testFS.writeBytes(src, content);
|
|
44
|
+
await testFS.copyXAttrs(src, unknown).catch(err => {
|
|
45
|
+
fail(`When there are no xattr's to copy, missing destination shouldn't get noticed`);
|
|
46
|
+
});
|
|
47
|
+
await testFS.updateXAttrs(src, { set: { 'some-attr': 'value' } });
|
|
48
|
+
try {
|
|
49
|
+
await testFS.copyXAttrs(src, unknown);
|
|
50
|
+
fail('should fail for missing source file');
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
expect(e.notFound).toBe(true);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
exports.specs.its.push(it);
|
|
57
|
+
it = {
|
|
58
|
+
expectation: 'copies xattrs',
|
|
59
|
+
notIncludedIn: 'device-fs'
|
|
60
|
+
};
|
|
61
|
+
it.func = async function (s) {
|
|
62
|
+
const { testFS } = s;
|
|
63
|
+
const src = `source.txt`;
|
|
64
|
+
const attrs = {
|
|
65
|
+
'attr-binary': await (0, random_node_1.bytes)(40),
|
|
66
|
+
'attr-str': await (0, random_node_1.stringOfB64Chars)(30),
|
|
67
|
+
'attr-obj': {
|
|
68
|
+
a: await (0, random_node_1.stringOfB64Chars)(10),
|
|
69
|
+
b: await (0, random_node_1.stringOfB64Chars)(20),
|
|
70
|
+
c: Math.round(1024 * Math.random())
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
await testFS.writeBytes(src, await (0, random_node_1.bytes)(150));
|
|
74
|
+
await testFS.updateXAttrs(src, { set: attrs });
|
|
75
|
+
// actually, dst and src don't have to be same
|
|
76
|
+
const dst = `destination.txt`;
|
|
77
|
+
await testFS.writeBytes(dst, await (0, random_node_1.bytes)(200));
|
|
78
|
+
expect((await testFS.listXAttrs(dst)).length).toBe(0);
|
|
79
|
+
await testFS.copyXAttrs(src, dst);
|
|
80
|
+
expect((0, bytes_equal_1.bytesEqual)(attrs['attr-binary'], await testFS.getXAttr(dst, 'attr-binary'))).toBeTrue();
|
|
81
|
+
expect(await testFS.getXAttr(dst, 'attr-str')).toBe(attrs['attr-str']);
|
|
82
|
+
expect((0, json_equal_1.deepEqual)(attrs['attr-obj'], await testFS.getXAttr(dst, 'attr-obj'))).toBeTrue();
|
|
83
|
+
};
|
|
84
|
+
exports.specs.its.push(it);
|
|
85
|
+
Object.freeze(exports);
|
package/package.json
CHANGED
package/protos/fs.proto
CHANGED
|
@@ -324,6 +324,14 @@ message CopyFolderRequestBody {
|
|
|
324
324
|
common.BooleanValue merge_and_overwrite = 3;
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
+
// --- WritableFS.copyXAttrs ---
|
|
328
|
+
// Reply body is empty
|
|
329
|
+
message CopyXAttrsRequestBody {
|
|
330
|
+
string src = 1;
|
|
331
|
+
string dst = 2;
|
|
332
|
+
repeated string filter = 3;
|
|
333
|
+
}
|
|
334
|
+
|
|
327
335
|
// --- WritableFS.saveFile ---
|
|
328
336
|
// Reply body is empty
|
|
329
337
|
message SaveFileRequestBody {
|