@filen/sync 0.1.1 → 0.1.3
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/LICENSE +661 -661
- package/README.md +1 -1
- package/SECURITY.md +17 -17
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +51 -1
- package/dist/constants.js.map +1 -1
- package/dist/ignorer.d.ts +14 -0
- package/dist/ignorer.js +69 -0
- package/dist/ignorer.js.map +1 -0
- package/dist/index.d.ts +27 -6
- package/dist/index.js +113 -13
- package/dist/index.js.map +1 -1
- package/dist/lib/deltas.d.ts +9 -31
- package/dist/lib/deltas.js +59 -65
- package/dist/lib/deltas.js.map +1 -1
- package/dist/lib/filesystems/local.d.ts +25 -20
- package/dist/lib/filesystems/local.js +203 -55
- package/dist/lib/filesystems/local.js.map +1 -1
- package/dist/lib/filesystems/remote.d.ts +18 -7
- package/dist/lib/filesystems/remote.js +435 -61
- package/dist/lib/filesystems/remote.js.map +1 -1
- package/dist/lib/ipc.d.ts +9 -0
- package/dist/lib/ipc.js +56 -0
- package/dist/lib/ipc.js.map +1 -0
- package/dist/lib/logger.d.ts +14 -0
- package/dist/lib/logger.js +93 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/state.d.ts +4 -15
- package/dist/lib/state.js +16 -29
- package/dist/lib/state.js.map +1 -1
- package/dist/lib/sync.d.ts +23 -9
- package/dist/lib/sync.js +242 -28
- package/dist/lib/sync.js.map +1 -1
- package/dist/lib/tasks.d.ts +18 -33
- package/dist/lib/tasks.js +52 -29
- package/dist/lib/tasks.js.map +1 -1
- package/dist/types.d.ts +175 -0
- package/dist/utils.d.ts +24 -0
- package/dist/utils.js +132 -1
- package/dist/utils.js.map +1 -1
- package/package.json +60 -58
- package/tsconfig.json +24 -24
- package/index.d.ts +0 -298
package/dist/lib/sync.js
CHANGED
|
@@ -4,13 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Sync = void 0;
|
|
7
|
-
const sdk_1 = __importDefault(require("@filen/sdk"));
|
|
8
7
|
const constants_1 = require("../constants");
|
|
9
8
|
const local_1 = require("./filesystems/local");
|
|
10
9
|
const remote_1 = require("./filesystems/remote");
|
|
11
10
|
const deltas_1 = __importDefault(require("./deltas"));
|
|
12
11
|
const tasks_1 = __importDefault(require("./tasks"));
|
|
13
12
|
const state_1 = __importDefault(require("./state"));
|
|
13
|
+
const ipc_1 = require("./ipc");
|
|
14
|
+
const worker_threads_1 = require("worker_threads");
|
|
15
|
+
const ignorer_1 = __importDefault(require("../ignorer"));
|
|
16
|
+
const utils_1 = require("../utils");
|
|
14
17
|
/**
|
|
15
18
|
* Sync
|
|
16
19
|
*
|
|
@@ -24,24 +27,95 @@ class Sync {
|
|
|
24
27
|
*
|
|
25
28
|
* @constructor
|
|
26
29
|
* @public
|
|
27
|
-
* @param {{ syncPair: SyncPair;
|
|
30
|
+
* @param {{ syncPair: SyncPair; worker: SyncWorker }} param0
|
|
28
31
|
* @param {SyncPair} param0.syncPair
|
|
29
|
-
* @param {
|
|
30
|
-
* @param {FilenSDKConfig} param0.sdkConfig
|
|
32
|
+
* @param {SyncWorker} param0.worker
|
|
31
33
|
*/
|
|
32
|
-
constructor({ syncPair,
|
|
34
|
+
constructor({ syncPair, worker }) {
|
|
33
35
|
this.isInitialized = false;
|
|
34
|
-
this.previousLocalTree = {
|
|
35
|
-
|
|
36
|
+
this.previousLocalTree = {
|
|
37
|
+
tree: {},
|
|
38
|
+
inodes: {}
|
|
39
|
+
};
|
|
40
|
+
this.previousRemoteTree = {
|
|
41
|
+
tree: {},
|
|
42
|
+
uuids: {}
|
|
43
|
+
};
|
|
36
44
|
this.localFileHashes = {};
|
|
45
|
+
this.abortControllers = {};
|
|
46
|
+
this.pauseSignals = {};
|
|
47
|
+
this.worker = worker;
|
|
37
48
|
this.syncPair = syncPair;
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
40
|
-
this.
|
|
41
|
-
this.
|
|
42
|
-
this.
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
49
|
+
this.mode = syncPair.mode;
|
|
50
|
+
this.paused = syncPair.paused;
|
|
51
|
+
this.excludeDotFiles = syncPair.excludeDotFiles;
|
|
52
|
+
this.dbPath = worker.dbPath;
|
|
53
|
+
this.sdk = worker.sdk;
|
|
54
|
+
this.localFileSystem = new local_1.LocalFileSystem(this);
|
|
55
|
+
this.remoteFileSystem = new remote_1.RemoteFileSystem(this);
|
|
56
|
+
this.deltas = new deltas_1.default(this);
|
|
57
|
+
this.tasks = new tasks_1.default(this);
|
|
58
|
+
this.state = new state_1.default(this);
|
|
59
|
+
this.localIgnorer = new ignorer_1.default(this, "localIgnorer");
|
|
60
|
+
this.remoteIgnorer = new ignorer_1.default(this, "remoteIgnorer");
|
|
61
|
+
this.setupMainThreadListeners();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Sets up receiving message from the main thread.
|
|
65
|
+
*
|
|
66
|
+
* @private
|
|
67
|
+
*/
|
|
68
|
+
setupMainThreadListeners() {
|
|
69
|
+
const receiver = !worker_threads_1.isMainThread && worker_threads_1.parentPort ? worker_threads_1.parentPort : process;
|
|
70
|
+
receiver.on("message", (message) => {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
if (message.type === "stopTransfer" && message.syncPair.uuid === this.syncPair.uuid) {
|
|
73
|
+
const abortController = this.abortControllers[`${message.data.of}:${message.data.relativePath}`];
|
|
74
|
+
if (!abortController || abortController.signal.aborted) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
abortController.abort();
|
|
78
|
+
}
|
|
79
|
+
else if (message.type === "pauseTransfer" && message.syncPair.uuid === this.syncPair.uuid) {
|
|
80
|
+
const pauseSignal = this.pauseSignals[`${message.data.of}:${message.data.relativePath}`];
|
|
81
|
+
if (!pauseSignal || pauseSignal.isPaused()) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
pauseSignal.pause();
|
|
85
|
+
}
|
|
86
|
+
else if (message.type === "resumeTransfer" && message.syncPair.uuid === this.syncPair.uuid) {
|
|
87
|
+
const pauseSignal = this.pauseSignals[`${message.data.of}:${message.data.relativePath}`];
|
|
88
|
+
if (!pauseSignal || !pauseSignal.isPaused()) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
pauseSignal.resume();
|
|
92
|
+
}
|
|
93
|
+
else if (message.type === "updateLocalIgnorer" && message.syncPair.uuid === this.syncPair.uuid) {
|
|
94
|
+
this.localIgnorer.update((_a = message.data) === null || _a === void 0 ? void 0 : _a.content).catch(err => {
|
|
95
|
+
this.worker.logger.log("error", err, "sync.setupMainThreadListeners");
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
else if (message.type === "updateRemoteIgnorer" && message.syncPair.uuid === this.syncPair.uuid) {
|
|
99
|
+
this.remoteIgnorer.update((_b = message.data) === null || _b === void 0 ? void 0 : _b.content).catch(err => {
|
|
100
|
+
this.worker.logger.log("error", err, "sync.setupMainThreadListeners");
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
else if (message.type === "pauseSyncPair" && message.syncPair.uuid === this.syncPair.uuid) {
|
|
104
|
+
this.paused = true;
|
|
105
|
+
}
|
|
106
|
+
else if (message.type === "resumeSyncPair" && message.syncPair.uuid === this.syncPair.uuid) {
|
|
107
|
+
this.paused = false;
|
|
108
|
+
}
|
|
109
|
+
else if (message.type === "changeSyncPairMode" && message.syncPair.uuid === this.syncPair.uuid) {
|
|
110
|
+
this.mode = message.data.mode;
|
|
111
|
+
}
|
|
112
|
+
else if (message.type === "syncPairExcludeDotFiles" && message.syncPair.uuid === this.syncPair.uuid) {
|
|
113
|
+
this.excludeDotFiles = true;
|
|
114
|
+
}
|
|
115
|
+
else if (message.type === "syncPairIncludeDotFiles" && message.syncPair.uuid === this.syncPair.uuid) {
|
|
116
|
+
this.excludeDotFiles = false;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
45
119
|
}
|
|
46
120
|
async initialize() {
|
|
47
121
|
if (this.isInitialized) {
|
|
@@ -50,47 +124,187 @@ class Sync {
|
|
|
50
124
|
this.isInitialized = true;
|
|
51
125
|
try {
|
|
52
126
|
//local/remote smoke test
|
|
53
|
-
await
|
|
54
|
-
|
|
127
|
+
await Promise.all([
|
|
128
|
+
this.localFileSystem.startDirectoryWatcher(),
|
|
129
|
+
this.state.initialize(),
|
|
130
|
+
this.localIgnorer.initialize(),
|
|
131
|
+
this.remoteIgnorer.initialize()
|
|
132
|
+
]);
|
|
55
133
|
this.run();
|
|
56
134
|
}
|
|
57
135
|
catch (e) {
|
|
136
|
+
this.worker.logger.log("error", e, "sync.initialize");
|
|
58
137
|
this.isInitialized = false;
|
|
59
138
|
throw e;
|
|
60
139
|
}
|
|
61
140
|
}
|
|
62
141
|
async run() {
|
|
142
|
+
if (this.paused) {
|
|
143
|
+
(0, ipc_1.postMessageToMain)({
|
|
144
|
+
type: "cyclePaused",
|
|
145
|
+
syncPair: this.syncPair
|
|
146
|
+
});
|
|
147
|
+
setTimeout(() => {
|
|
148
|
+
this.run();
|
|
149
|
+
}, constants_1.SYNC_INTERVAL);
|
|
150
|
+
(0, ipc_1.postMessageToMain)({
|
|
151
|
+
type: "cycleRestarting",
|
|
152
|
+
syncPair: this.syncPair
|
|
153
|
+
});
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
(0, ipc_1.postMessageToMain)({
|
|
157
|
+
type: "cycleStarted",
|
|
158
|
+
syncPair: this.syncPair
|
|
159
|
+
});
|
|
63
160
|
try {
|
|
161
|
+
(0, ipc_1.postMessageToMain)({
|
|
162
|
+
type: "cycleWaitingForLocalDirectoryChangesStarted",
|
|
163
|
+
syncPair: this.syncPair
|
|
164
|
+
});
|
|
64
165
|
await this.localFileSystem.waitForLocalDirectoryChanges();
|
|
166
|
+
(0, ipc_1.postMessageToMain)({
|
|
167
|
+
type: "cycleWaitingForLocalDirectoryChangesDone",
|
|
168
|
+
syncPair: this.syncPair
|
|
169
|
+
});
|
|
170
|
+
(0, ipc_1.postMessageToMain)({
|
|
171
|
+
type: "cycleGettingTreesStarted",
|
|
172
|
+
syncPair: this.syncPair
|
|
173
|
+
});
|
|
174
|
+
// eslint-disable-next-line prefer-const
|
|
65
175
|
let [currentLocalTree, currentRemoteTree] = await Promise.all([
|
|
66
176
|
this.localFileSystem.getDirectoryTree(),
|
|
67
177
|
this.remoteFileSystem.getDirectoryTree()
|
|
68
178
|
]);
|
|
179
|
+
if (!currentLocalTree.changed && !currentRemoteTree.changed) {
|
|
180
|
+
(0, ipc_1.postMessageToMain)({
|
|
181
|
+
type: "cycleNoChanges",
|
|
182
|
+
syncPair: this.syncPair
|
|
183
|
+
});
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
(0, ipc_1.postMessageToMain)({
|
|
187
|
+
type: "cycleGettingTreesDone",
|
|
188
|
+
syncPair: this.syncPair
|
|
189
|
+
});
|
|
190
|
+
(0, ipc_1.postMessageToMain)({
|
|
191
|
+
type: "localTreeErrors",
|
|
192
|
+
syncPair: this.syncPair,
|
|
193
|
+
data: {
|
|
194
|
+
errors: currentLocalTree.errors.map(e => (Object.assign(Object.assign({}, e), { error: (0, utils_1.serializeError)(e.error) })))
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
(0, ipc_1.postMessageToMain)({
|
|
198
|
+
type: "localTreeIgnored",
|
|
199
|
+
syncPair: this.syncPair,
|
|
200
|
+
data: {
|
|
201
|
+
ignored: currentLocalTree.ignored
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
(0, ipc_1.postMessageToMain)({
|
|
205
|
+
type: "remoteTreeIgnored",
|
|
206
|
+
syncPair: this.syncPair,
|
|
207
|
+
data: {
|
|
208
|
+
ignored: currentRemoteTree.ignored
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
(0, ipc_1.postMessageToMain)({
|
|
212
|
+
type: "cycleProcessingDeltasStarted",
|
|
213
|
+
syncPair: this.syncPair
|
|
214
|
+
});
|
|
69
215
|
const deltas = await this.deltas.process({
|
|
70
|
-
currentLocalTree,
|
|
71
|
-
currentRemoteTree,
|
|
216
|
+
currentLocalTree: currentLocalTree.result,
|
|
217
|
+
currentRemoteTree: currentRemoteTree.result,
|
|
72
218
|
previousLocalTree: this.previousLocalTree,
|
|
73
|
-
previousRemoteTree: this.previousRemoteTree
|
|
219
|
+
previousRemoteTree: this.previousRemoteTree,
|
|
220
|
+
currentLocalTreeErrors: currentLocalTree.errors
|
|
221
|
+
});
|
|
222
|
+
(0, ipc_1.postMessageToMain)({
|
|
223
|
+
type: "cycleProcessingDeltasDone",
|
|
224
|
+
syncPair: this.syncPair
|
|
225
|
+
});
|
|
226
|
+
(0, ipc_1.postMessageToMain)({
|
|
227
|
+
type: "deltas",
|
|
228
|
+
syncPair: this.syncPair,
|
|
229
|
+
data: {
|
|
230
|
+
deltas
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
this.worker.logger.log("info", { deltas, localErrors: currentLocalTree.errors });
|
|
234
|
+
(0, ipc_1.postMessageToMain)({
|
|
235
|
+
type: "cycleProcessingTasksStarted",
|
|
236
|
+
syncPair: this.syncPair
|
|
237
|
+
});
|
|
238
|
+
const { doneTasks, errors } = await this.tasks.process({ deltas });
|
|
239
|
+
(0, ipc_1.postMessageToMain)({
|
|
240
|
+
type: "cycleProcessingTasksDone",
|
|
241
|
+
syncPair: this.syncPair
|
|
242
|
+
});
|
|
243
|
+
(0, ipc_1.postMessageToMain)({
|
|
244
|
+
type: "doneTasks",
|
|
245
|
+
syncPair: this.syncPair,
|
|
246
|
+
data: {
|
|
247
|
+
tasks: doneTasks.map(task => (Object.assign({ path: task.path, type: task.type }, (task.type === "uploadFile" ? { item: task.item } : {})))),
|
|
248
|
+
errors: errors.map(e => (Object.assign(Object.assign({}, e), { error: (0, utils_1.serializeError)(e.error) })))
|
|
249
|
+
}
|
|
74
250
|
});
|
|
75
|
-
console.log(deltas);
|
|
76
|
-
const doneTasks = await this.tasks.process({ deltas });
|
|
77
|
-
console.log(doneTasks);
|
|
78
251
|
if (doneTasks.length > 0) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
252
|
+
(0, ipc_1.postMessageToMain)({
|
|
253
|
+
type: "cycleApplyingStateStarted",
|
|
254
|
+
syncPair: this.syncPair
|
|
255
|
+
});
|
|
256
|
+
const applied = this.state.applyDoneTasksToState({
|
|
257
|
+
doneTasks,
|
|
258
|
+
currentLocalTree: currentLocalTree.result,
|
|
259
|
+
currentRemoteTree: currentRemoteTree.result
|
|
260
|
+
});
|
|
261
|
+
currentLocalTree.result = applied.currentLocalTree;
|
|
262
|
+
currentRemoteTree.result = applied.currentRemoteTree;
|
|
263
|
+
(0, ipc_1.postMessageToMain)({
|
|
264
|
+
type: "cycleApplyingStateDone",
|
|
265
|
+
syncPair: this.syncPair
|
|
266
|
+
});
|
|
82
267
|
}
|
|
83
|
-
|
|
84
|
-
|
|
268
|
+
(0, ipc_1.postMessageToMain)({
|
|
269
|
+
type: "cycleSavingStateStarted",
|
|
270
|
+
syncPair: this.syncPair
|
|
271
|
+
});
|
|
272
|
+
this.previousLocalTree = currentLocalTree.result;
|
|
273
|
+
this.previousRemoteTree = currentRemoteTree.result;
|
|
85
274
|
await this.state.save();
|
|
275
|
+
(0, ipc_1.postMessageToMain)({
|
|
276
|
+
type: "cycleSavingStateDone",
|
|
277
|
+
syncPair: this.syncPair
|
|
278
|
+
});
|
|
279
|
+
(0, ipc_1.postMessageToMain)({
|
|
280
|
+
type: "cycleSuccess",
|
|
281
|
+
syncPair: this.syncPair
|
|
282
|
+
});
|
|
86
283
|
}
|
|
87
284
|
catch (e) {
|
|
88
|
-
|
|
285
|
+
this.worker.logger.log("error", e, "sync.run");
|
|
286
|
+
if (e instanceof Error) {
|
|
287
|
+
(0, ipc_1.postMessageToMain)({
|
|
288
|
+
type: "cycleError",
|
|
289
|
+
syncPair: this.syncPair,
|
|
290
|
+
data: {
|
|
291
|
+
error: (0, utils_1.serializeError)(e)
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
89
295
|
}
|
|
90
296
|
finally {
|
|
297
|
+
(0, ipc_1.postMessageToMain)({
|
|
298
|
+
type: "cycleFinished",
|
|
299
|
+
syncPair: this.syncPair
|
|
300
|
+
});
|
|
91
301
|
setTimeout(() => {
|
|
92
302
|
this.run();
|
|
93
303
|
}, constants_1.SYNC_INTERVAL);
|
|
304
|
+
(0, ipc_1.postMessageToMain)({
|
|
305
|
+
type: "cycleRestarting",
|
|
306
|
+
syncPair: this.syncPair
|
|
307
|
+
});
|
|
94
308
|
}
|
|
95
309
|
}
|
|
96
310
|
}
|
package/dist/lib/sync.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/lib/sync.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/lib/sync.ts"],"names":[],"mappings":";;;;;;AAEA,4CAA4C;AAC5C,+CAAgE;AAChE,iDAAmE;AACnE,sDAA6B;AAC7B,oDAA2B;AAC3B,oDAA2B;AAC3B,+BAAyC;AACzC,mDAAyD;AACzD,yDAAgC;AAChC,oCAAyC;AAGzC;;;;;;GAMG;AACH,MAAa,IAAI;IA4BhB;;;;;;;;OAQG;IACH,YAAmB,EAAE,QAAQ,EAAE,MAAM,EAA8C;QAlC3E,kBAAa,GAAG,KAAK,CAAA;QAItB,sBAAiB,GAAc;YACrC,IAAI,EAAE,EAAE;YACR,MAAM,EAAE,EAAE;SACV,CAAA;QACM,uBAAkB,GAAe;YACvC,IAAI,EAAE,EAAE;YACR,KAAK,EAAE,EAAE;SACT,CAAA;QACM,oBAAe,GAA2B,EAAE,CAAA;QAInC,qBAAgB,GAAoC,EAAE,CAAA;QACtD,iBAAY,GAAgC,EAAE,CAAA;QAkB7D,IAAI,CAAC,MAAM,GAAG,MAAM,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AAC,EAAE,UAAU,CAAC,CAAA;YAE9C,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;gBACxB,IAAA,uBAAiB,EAAC;oBACjB,IAAI,EAAE,YAAY;oBAClB,QAAQ,EAAE,IAAI,CAAC,QAAQ;oBACvB,IAAI,EAAE;wBACL,KAAK,EAAE,IAAA,sBAAc,EAAC,CAAC,CAAC;qBACxB;iBACD,CAAC,CAAA;YACH,CAAC;QACF,CAAC;gBAAS,CAAC;YACV,IAAA,uBAAiB,EAAC;gBACjB,IAAI,EAAE,eAAe;gBACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACvB,CAAC,CAAA;YAEF,UAAU,CAAC,GAAG,EAAE;gBACf,IAAI,CAAC,GAAG,EAAE,CAAA;YACX,CAAC,EAAE,yBAAa,CAAC,CAAA;YAEjB,IAAA,uBAAiB,EAAC;gBACjB,IAAI,EAAE,iBAAiB;gBACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACvB,CAAC,CAAA;QACH,CAAC;IACF,CAAC;CACD;AA/VD,oBA+VC;AAED,kBAAe,IAAI,CAAA"}
|
package/dist/lib/tasks.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type Sync from "./sync";
|
|
3
|
-
import type
|
|
4
|
-
import type
|
|
3
|
+
import { type Delta } from "./deltas";
|
|
4
|
+
import { type CloudItem } from "@filen/sdk";
|
|
5
5
|
import fs from "fs-extra";
|
|
6
|
+
export type TaskError = {
|
|
7
|
+
path: string;
|
|
8
|
+
error: Error;
|
|
9
|
+
type: "uploadFile" | "createRemoteDirectory" | "createLocalDirectory" | "deleteLocalFile" | "deleteRemoteFile" | "deleteLocalDirectory" | "deleteRemoteDirectory" | "downloadFile" | "renameLocalFile" | "renameRemoteFile" | "renameRemoteDirectory" | "renameLocalDirectory";
|
|
10
|
+
};
|
|
6
11
|
export type DoneTask = {
|
|
7
12
|
path: string;
|
|
8
13
|
} & ({
|
|
@@ -25,19 +30,11 @@ export type DoneTask = {
|
|
|
25
30
|
} | {
|
|
26
31
|
type: "downloadFile";
|
|
27
32
|
stats: fs.Stats;
|
|
28
|
-
} | {
|
|
29
|
-
type: "moveLocalFile";
|
|
30
|
-
from: string;
|
|
31
|
-
to: string;
|
|
32
33
|
} | {
|
|
33
34
|
type: "renameLocalFile";
|
|
34
35
|
from: string;
|
|
35
36
|
to: string;
|
|
36
37
|
stats: fs.Stats;
|
|
37
|
-
} | {
|
|
38
|
-
type: "moveRemoteFile";
|
|
39
|
-
from: string;
|
|
40
|
-
to: string;
|
|
41
38
|
} | {
|
|
42
39
|
type: "renameRemoteFile";
|
|
43
40
|
from: string;
|
|
@@ -51,20 +48,6 @@ export type DoneTask = {
|
|
|
51
48
|
from: string;
|
|
52
49
|
to: string;
|
|
53
50
|
stats: fs.Stats;
|
|
54
|
-
} | {
|
|
55
|
-
type: "moveRemoteDirectory";
|
|
56
|
-
from: string;
|
|
57
|
-
to: string;
|
|
58
|
-
} | {
|
|
59
|
-
type: "moveLocalFile";
|
|
60
|
-
from: string;
|
|
61
|
-
to: string;
|
|
62
|
-
stats: fs.Stats;
|
|
63
|
-
} | {
|
|
64
|
-
type: "moveLocalDirectory";
|
|
65
|
-
from: string;
|
|
66
|
-
to: string;
|
|
67
|
-
stats: fs.Stats;
|
|
68
51
|
});
|
|
69
52
|
/**
|
|
70
53
|
* Tasks
|
|
@@ -76,18 +59,15 @@ export type DoneTask = {
|
|
|
76
59
|
*/
|
|
77
60
|
export declare class Tasks {
|
|
78
61
|
private readonly sync;
|
|
62
|
+
private readonly mutex;
|
|
79
63
|
/**
|
|
80
64
|
* Creates an instance of Tasks.
|
|
81
|
-
* @date 3/1/2024 - 11:11:36 PM
|
|
82
65
|
*
|
|
83
66
|
* @constructor
|
|
84
67
|
* @public
|
|
85
|
-
* @param {
|
|
86
|
-
* @param {Sync} param0.sync
|
|
68
|
+
* @param {Sync} sync
|
|
87
69
|
*/
|
|
88
|
-
constructor(
|
|
89
|
-
sync: Sync;
|
|
90
|
-
});
|
|
70
|
+
constructor(sync: Sync);
|
|
91
71
|
/**
|
|
92
72
|
* Process a task.
|
|
93
73
|
* @date 3/2/2024 - 12:14:48 PM
|
|
@@ -101,16 +81,21 @@ export declare class Tasks {
|
|
|
101
81
|
private processTask;
|
|
102
82
|
/**
|
|
103
83
|
* Process all deltas.
|
|
104
|
-
* @date 3/5/2024 - 3:59:51 PM
|
|
105
84
|
*
|
|
106
85
|
* @public
|
|
107
86
|
* @async
|
|
108
87
|
* @param {{ deltas: Delta[] }} param0
|
|
109
88
|
* @param {{}} param0.deltas
|
|
110
|
-
* @returns {Promise<
|
|
89
|
+
* @returns {Promise<{
|
|
90
|
+
* doneTasks: DoneTask[]
|
|
91
|
+
* errors: TaskError[]
|
|
92
|
+
* }>}
|
|
111
93
|
*/
|
|
112
94
|
process({ deltas }: {
|
|
113
95
|
deltas: Delta[];
|
|
114
|
-
}): Promise<
|
|
96
|
+
}): Promise<{
|
|
97
|
+
doneTasks: DoneTask[];
|
|
98
|
+
errors: TaskError[];
|
|
99
|
+
}>;
|
|
115
100
|
}
|
|
116
101
|
export default Tasks;
|
package/dist/lib/tasks.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Tasks = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
+
const semaphore_1 = require("../semaphore");
|
|
5
6
|
/**
|
|
6
7
|
* Tasks
|
|
7
8
|
* @date 3/1/2024 - 11:11:32 PM
|
|
@@ -13,14 +14,13 @@ const utils_1 = require("../utils");
|
|
|
13
14
|
class Tasks {
|
|
14
15
|
/**
|
|
15
16
|
* Creates an instance of Tasks.
|
|
16
|
-
* @date 3/1/2024 - 11:11:36 PM
|
|
17
17
|
*
|
|
18
18
|
* @constructor
|
|
19
19
|
* @public
|
|
20
|
-
* @param {
|
|
21
|
-
* @param {Sync} param0.sync
|
|
20
|
+
* @param {Sync} sync
|
|
22
21
|
*/
|
|
23
|
-
constructor(
|
|
22
|
+
constructor(sync) {
|
|
23
|
+
this.mutex = new semaphore_1.Semaphore(1);
|
|
24
24
|
this.sync = sync;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
@@ -53,18 +53,20 @@ class Tasks {
|
|
|
53
53
|
await this.sync.remoteFileSystem.unlink({ relativePath: delta.path });
|
|
54
54
|
return delta;
|
|
55
55
|
}
|
|
56
|
-
case "moveLocalDirectory":
|
|
57
56
|
case "renameLocalDirectory":
|
|
58
|
-
case "renameLocalFile":
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
case "renameLocalFile": {
|
|
58
|
+
const stats = await this.sync.localFileSystem.rename({
|
|
59
|
+
fromRelativePath: delta.from,
|
|
60
|
+
toRelativePath: delta.to
|
|
61
|
+
});
|
|
61
62
|
return Object.assign(Object.assign({}, delta), { stats });
|
|
62
63
|
}
|
|
63
|
-
case "moveRemoteDirectory":
|
|
64
64
|
case "renameRemoteDirectory":
|
|
65
|
-
case "renameRemoteFile":
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
case "renameRemoteFile": {
|
|
66
|
+
await this.sync.remoteFileSystem.rename({
|
|
67
|
+
fromRelativePath: delta.from,
|
|
68
|
+
toRelativePath: delta.to
|
|
69
|
+
});
|
|
68
70
|
return delta;
|
|
69
71
|
}
|
|
70
72
|
case "downloadFile": {
|
|
@@ -79,31 +81,52 @@ class Tasks {
|
|
|
79
81
|
}
|
|
80
82
|
/**
|
|
81
83
|
* Process all deltas.
|
|
82
|
-
* @date 3/5/2024 - 3:59:51 PM
|
|
83
84
|
*
|
|
84
85
|
* @public
|
|
85
86
|
* @async
|
|
86
87
|
* @param {{ deltas: Delta[] }} param0
|
|
87
88
|
* @param {{}} param0.deltas
|
|
88
|
-
* @returns {Promise<
|
|
89
|
+
* @returns {Promise<{
|
|
90
|
+
* doneTasks: DoneTask[]
|
|
91
|
+
* errors: TaskError[]
|
|
92
|
+
* }>}
|
|
89
93
|
*/
|
|
90
94
|
async process({ deltas }) {
|
|
91
|
-
// Work on deltas from "left to right" (ascending order, path length).
|
|
92
|
-
deltas = deltas.sort((a, b) => a.path.split("/").length - b.path.split("/").length);
|
|
93
95
|
const executed = [];
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
96
|
+
const errors = [];
|
|
97
|
+
await (0, utils_1.promiseAllSettledChunked)(
|
|
98
|
+
// Work on deltas from "left to right" (ascending order, path length).
|
|
99
|
+
deltas
|
|
100
|
+
.sort((a, b) => a.path.split("/").length - b.path.split("/").length)
|
|
101
|
+
.map(async (delta) => {
|
|
102
|
+
const semaphoreToAcquire = delta.type === "createRemoteDirectory" ||
|
|
103
|
+
delta.type === "renameLocalDirectory" ||
|
|
104
|
+
delta.type === "deleteRemoteDirectory"
|
|
105
|
+
? this.mutex
|
|
106
|
+
: null;
|
|
107
|
+
await (semaphoreToAcquire === null || semaphoreToAcquire === void 0 ? void 0 : semaphoreToAcquire.acquire());
|
|
108
|
+
try {
|
|
109
|
+
const doneTask = await this.processTask({ delta });
|
|
110
|
+
executed.push(doneTask);
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
this.sync.worker.logger.log("error", e, "tasks.process");
|
|
114
|
+
if (e instanceof Error) {
|
|
115
|
+
errors.push({
|
|
116
|
+
path: delta.path,
|
|
117
|
+
type: delta.type,
|
|
118
|
+
error: e
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
semaphoreToAcquire === null || semaphoreToAcquire === void 0 ? void 0 : semaphoreToAcquire.release();
|
|
124
|
+
}
|
|
125
|
+
}));
|
|
126
|
+
return {
|
|
127
|
+
doneTasks: executed,
|
|
128
|
+
errors
|
|
129
|
+
};
|
|
107
130
|
}
|
|
108
131
|
}
|
|
109
132
|
exports.Tasks = Tasks;
|
package/dist/lib/tasks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tasks.js","sourceRoot":"","sources":["../../src/lib/tasks.ts"],"names":[],"mappings":";;;AAEA,oCAAmD;
|
|
1
|
+
{"version":3,"file":"tasks.js","sourceRoot":"","sources":["../../src/lib/tasks.ts"],"names":[],"mappings":";;;AAEA,oCAAmD;AAGnD,4CAAwC;AAsExC;;;;;;;GAOG;AACH,MAAa,KAAK;IAIjB;;;;;;OAMG;IACH,YAAmB,IAAU;QATZ,UAAK,GAAG,IAAI,qBAAS,CAAC,CAAC,CAAC,CAAA;QAUxC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IACjB,CAAC;IAED;;;;;;;;;OASG;IACK,KAAK,CAAC,WAAW,CAAC,EAAE,KAAK,EAAoB;QACpD,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;YACpB,KAAK,sBAAsB,CAAC,CAAC,CAAC;gBAC7B,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;gBAEjF,uCACI,KAAK,KACR,KAAK,IACL;YACF,CAAC;YAED,KAAK,uBAAuB,CAAC,CAAC,CAAC;gBAC9B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;gBAEjF,uCACI,KAAK,KACR,IAAI,IACJ;YACF,CAAC;YAED,KAAK,sBAAsB,CAAC;YAC5B,KAAK,iBAAiB,CAAC,CAAC,CAAC;gBACxB,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;gBAEp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