@filen/sync 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -12
- package/dist/index.js +12 -11
- package/dist/index.js.map +1 -1
- package/dist/lib/deltas.js +141 -40
- package/dist/lib/deltas.js.map +1 -1
- package/dist/lib/filesystems/local.d.ts +8 -24
- package/dist/lib/filesystems/local.js +198 -69
- package/dist/lib/filesystems/local.js.map +1 -1
- package/dist/lib/filesystems/remote.d.ts +4 -1
- package/dist/lib/filesystems/remote.js +141 -51
- package/dist/lib/filesystems/remote.js.map +1 -1
- package/dist/lib/ipc.js +4 -0
- package/dist/lib/ipc.js.map +1 -1
- package/dist/lib/lock.d.ts +13 -0
- package/dist/lib/lock.js +73 -0
- package/dist/lib/lock.js.map +1 -0
- package/dist/lib/state.js +91 -59
- package/dist/lib/state.js.map +1 -1
- package/dist/lib/sync.d.ts +7 -1
- package/dist/lib/sync.js +160 -47
- package/dist/lib/sync.js.map +1 -1
- package/dist/lib/tasks.d.ts +11 -9
- package/dist/lib/tasks.js +368 -42
- package/dist/lib/tasks.js.map +1 -1
- package/dist/types.d.ts +201 -36
- package/dist/utils.d.ts +18 -0
- package/dist/utils.js +43 -11
- package/dist/utils.js.map +1 -1
- package/index.d.ts +9 -0
- package/jest.config.js +5 -0
- package/package.json +5 -3
- package/tests/utils.test.ts +33 -0
- package/tsconfig.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type SyncPair } from "./types";
|
|
1
|
+
import { type SyncPair, type SyncMessage } from "./types";
|
|
2
2
|
import Sync from "./lib/sync";
|
|
3
3
|
import FilenSDK, { type FilenSDKConfig } from "@filen/sdk";
|
|
4
4
|
import Logger from "./lib/logger";
|
|
@@ -17,20 +17,13 @@ export declare class SyncWorker {
|
|
|
17
17
|
readonly initSyncPairsMutex: import("./semaphore").ISemaphore;
|
|
18
18
|
readonly sdk: FilenSDK;
|
|
19
19
|
readonly logger: Logger;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
* @constructor
|
|
24
|
-
* @public
|
|
25
|
-
* @param {{ syncPairs: SyncPair[]; dbPath: string; sdkConfig: FilenSDKConfig }} param0
|
|
26
|
-
* @param {{}} param0.syncPairs
|
|
27
|
-
* @param {string} param0.dbPath
|
|
28
|
-
* @param {FilenSDKConfig} param0.sdkConfig
|
|
29
|
-
*/
|
|
30
|
-
constructor({ syncPairs, dbPath, sdkConfig }: {
|
|
20
|
+
readonly runOnce: boolean;
|
|
21
|
+
constructor({ syncPairs, dbPath, sdkConfig, onMessage, runOnce }: {
|
|
31
22
|
syncPairs: SyncPair[];
|
|
32
23
|
dbPath: string;
|
|
33
24
|
sdkConfig: FilenSDKConfig;
|
|
25
|
+
onMessage?: (message: SyncMessage) => void;
|
|
26
|
+
runOnce?: boolean;
|
|
34
27
|
});
|
|
35
28
|
/**
|
|
36
29
|
* Sets up receiving message from the main thread.
|
package/dist/index.js
CHANGED
|
@@ -35,19 +35,13 @@ const logger_1 = __importDefault(require("./lib/logger"));
|
|
|
35
35
|
* @typedef {SyncWorker}
|
|
36
36
|
*/
|
|
37
37
|
class SyncWorker {
|
|
38
|
-
|
|
39
|
-
* Creates an instance of SyncWorker.
|
|
40
|
-
*
|
|
41
|
-
* @constructor
|
|
42
|
-
* @public
|
|
43
|
-
* @param {{ syncPairs: SyncPair[]; dbPath: string; sdkConfig: FilenSDKConfig }} param0
|
|
44
|
-
* @param {{}} param0.syncPairs
|
|
45
|
-
* @param {string} param0.dbPath
|
|
46
|
-
* @param {FilenSDKConfig} param0.sdkConfig
|
|
47
|
-
*/
|
|
48
|
-
constructor({ syncPairs, dbPath, sdkConfig }) {
|
|
38
|
+
constructor({ syncPairs, dbPath, sdkConfig, onMessage, runOnce = false }) {
|
|
49
39
|
this.syncs = {};
|
|
50
40
|
this.initSyncPairsMutex = new semaphore_1.Semaphore(1);
|
|
41
|
+
if (onMessage) {
|
|
42
|
+
process.onMessage = onMessage;
|
|
43
|
+
}
|
|
44
|
+
this.runOnce = runOnce;
|
|
51
45
|
this.syncPairs = syncPairs;
|
|
52
46
|
this.dbPath = dbPath;
|
|
53
47
|
this.logger = new logger_1.default(dbPath);
|
|
@@ -119,6 +113,8 @@ class SyncWorker {
|
|
|
119
113
|
*/
|
|
120
114
|
async initSyncPairs(pairs) {
|
|
121
115
|
await this.initSyncPairsMutex.acquire();
|
|
116
|
+
const currentSyncPairsUUIDs = this.syncPairs.map(pair => pair.uuid);
|
|
117
|
+
const newSyncPairsUUIDs = pairs.map(pair => pair.uuid);
|
|
122
118
|
try {
|
|
123
119
|
const promises = [];
|
|
124
120
|
for (const pair of pairs) {
|
|
@@ -131,6 +127,11 @@ class SyncWorker {
|
|
|
131
127
|
}
|
|
132
128
|
}
|
|
133
129
|
await Promise.all(promises);
|
|
130
|
+
for (const uuid of currentSyncPairsUUIDs) {
|
|
131
|
+
if (!newSyncPairsUUIDs.includes(uuid) && this.syncs[uuid]) {
|
|
132
|
+
this.syncs[uuid].removed = true;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
134
135
|
}
|
|
135
136
|
catch (e) {
|
|
136
137
|
this.logger.log("error", e, "index.initSyncPairs");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AACA,sDAA6B;AAC7B,qDAA0D;AAC1D,mDAAyD;AACzD,mCAA6C;AAC7C,2CAAuC;AACvC,2CAA2C;AAC3C,mCAAwC;AACxC,0DAAiC;AAEjC;;;;;;;GAOG;AACH,MAAa,UAAU;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AACA,sDAA6B;AAC7B,qDAA0D;AAC1D,mDAAyD;AACzD,mCAA6C;AAC7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AC,CAAA;QACR,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAA;QAClC,CAAC;IACF,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,UAAU;QACtB,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACzC,CAAC;CACD;AA5JD,gCA4JC;AAED,0CAAuB;AACvB,kBAAe,UAAU,CAAA"}
|
package/dist/lib/deltas.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Deltas = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
4
5
|
/**
|
|
5
6
|
* Deltas
|
|
6
7
|
* @date 3/1/2024 - 11:11:32 PM
|
|
@@ -43,9 +44,20 @@ class Deltas {
|
|
|
43
44
|
let deltas = [];
|
|
44
45
|
const pathsAdded = {};
|
|
45
46
|
const erroredLocalPaths = {};
|
|
47
|
+
const renamedRemoteDirectories = [];
|
|
48
|
+
const renamedLocalDirectories = [];
|
|
49
|
+
const deletedRemoteDirectories = [];
|
|
50
|
+
const deletedLocalDirectories = [];
|
|
46
51
|
for (const error of currentLocalTreeErrors) {
|
|
47
52
|
erroredLocalPaths[error.relativePath] = true;
|
|
48
53
|
}
|
|
54
|
+
// The order of delta processing:
|
|
55
|
+
// 1. Local directory/file move/rename
|
|
56
|
+
// 2. Remote directory/file move/rename
|
|
57
|
+
// 3. Local deletions
|
|
58
|
+
// 4. Remote deletions
|
|
59
|
+
// 5. Local additions/filemodifications
|
|
60
|
+
// 6. Remote additions/filemodifications
|
|
49
61
|
// Local file/directory move/rename
|
|
50
62
|
for (const inode in currentLocalTree.inodes) {
|
|
51
63
|
const currentItem = currentLocalTree.inodes[inode];
|
|
@@ -58,14 +70,18 @@ class Deltas {
|
|
|
58
70
|
erroredLocalPaths[previousItem.path]) {
|
|
59
71
|
continue;
|
|
60
72
|
}
|
|
61
|
-
// Path from current item changed, it was either renamed or moved
|
|
62
|
-
if (currentItem.path !== previousItem.path) {
|
|
63
|
-
|
|
73
|
+
// Path from current item changed, it was either renamed or moved (same type)
|
|
74
|
+
if (currentItem.path !== previousItem.path && currentItem.type === previousItem.type) {
|
|
75
|
+
const delta = {
|
|
64
76
|
type: currentItem.type === "directory" ? "renameRemoteDirectory" : "renameRemoteFile",
|
|
65
77
|
path: currentItem.path,
|
|
66
78
|
from: previousItem.path,
|
|
67
79
|
to: currentItem.path
|
|
68
|
-
}
|
|
80
|
+
};
|
|
81
|
+
deltas.push(delta);
|
|
82
|
+
if (currentItem.type === "directory") {
|
|
83
|
+
renamedRemoteDirectories.push(delta);
|
|
84
|
+
}
|
|
69
85
|
pathsAdded[currentItem.path] = true;
|
|
70
86
|
pathsAdded[previousItem.path] = true;
|
|
71
87
|
}
|
|
@@ -73,18 +89,22 @@ class Deltas {
|
|
|
73
89
|
// Remote file/directory move/rename
|
|
74
90
|
for (const uuid in currentRemoteTree.uuids) {
|
|
75
91
|
const currentItem = currentRemoteTree.uuids[uuid];
|
|
76
|
-
const previousItem =
|
|
92
|
+
const previousItem = previousRemoteTree.uuids[uuid];
|
|
77
93
|
if (!currentItem || !previousItem || pathsAdded[currentItem.path] || pathsAdded[previousItem.path]) {
|
|
78
94
|
continue;
|
|
79
95
|
}
|
|
80
|
-
// Path from current item changed, it was either renamed or moved
|
|
81
|
-
if (currentItem.path !== previousItem.path) {
|
|
82
|
-
|
|
83
|
-
type: currentItem.type === "directory" ? "
|
|
96
|
+
// Path from current item changed, it was either renamed or moved (same type)
|
|
97
|
+
if (currentItem.path !== previousItem.path && currentItem.type === previousItem.type) {
|
|
98
|
+
const delta = {
|
|
99
|
+
type: currentItem.type === "directory" ? "renameLocalDirectory" : "renameLocalFile",
|
|
84
100
|
path: currentItem.path,
|
|
85
101
|
from: previousItem.path,
|
|
86
102
|
to: currentItem.path
|
|
87
|
-
}
|
|
103
|
+
};
|
|
104
|
+
deltas.push(delta);
|
|
105
|
+
if (currentItem.type === "directory") {
|
|
106
|
+
renamedLocalDirectories.push(delta);
|
|
107
|
+
}
|
|
88
108
|
pathsAdded[currentItem.path] = true;
|
|
89
109
|
pathsAdded[previousItem.path] = true;
|
|
90
110
|
}
|
|
@@ -96,12 +116,19 @@ class Deltas {
|
|
|
96
116
|
}
|
|
97
117
|
const previousLocalItem = previousLocalTree.tree[path];
|
|
98
118
|
const currentLocalItem = currentLocalTree.tree[path];
|
|
99
|
-
|
|
100
|
-
|
|
119
|
+
// If the item does not exist in the current tree but does in the previous one, it has been deleted.
|
|
120
|
+
// We also check if the previous inode does not exist in the current tree.
|
|
121
|
+
if (!currentLocalItem && previousLocalItem && !currentLocalTree.inodes[previousLocalItem.inode]) {
|
|
122
|
+
const delta = {
|
|
101
123
|
type: previousLocalItem.type === "directory" ? "deleteRemoteDirectory" : "deleteRemoteFile",
|
|
102
124
|
path
|
|
103
|
-
}
|
|
125
|
+
};
|
|
126
|
+
deltas.push(delta);
|
|
127
|
+
if (previousLocalItem.type === "directory") {
|
|
128
|
+
deletedRemoteDirectories.push(delta);
|
|
129
|
+
}
|
|
104
130
|
pathsAdded[path] = true;
|
|
131
|
+
pathsAdded[previousLocalItem.path] = true;
|
|
105
132
|
}
|
|
106
133
|
}
|
|
107
134
|
// Remote deletions
|
|
@@ -111,12 +138,19 @@ class Deltas {
|
|
|
111
138
|
}
|
|
112
139
|
const previousRemoteItem = previousRemoteTree.tree[path];
|
|
113
140
|
const currentRemoteItem = currentRemoteTree.tree[path];
|
|
114
|
-
|
|
115
|
-
|
|
141
|
+
// If the item does not exist in the current tree but does in the previous one, it has been deleted.
|
|
142
|
+
// We also check if the previous UUID does not exist in the current tree.
|
|
143
|
+
if (!currentRemoteItem && previousRemoteItem && !currentRemoteTree.uuids[previousRemoteItem.uuid]) {
|
|
144
|
+
const delta = {
|
|
116
145
|
type: previousRemoteItem.type === "directory" ? "deleteLocalDirectory" : "deleteLocalFile",
|
|
117
146
|
path
|
|
118
|
-
}
|
|
147
|
+
};
|
|
148
|
+
deltas.push(delta);
|
|
149
|
+
if (previousRemoteItem.type === "directory") {
|
|
150
|
+
deletedLocalDirectories.push(delta);
|
|
151
|
+
}
|
|
119
152
|
pathsAdded[path] = true;
|
|
153
|
+
pathsAdded[previousRemoteItem.path] = true;
|
|
120
154
|
}
|
|
121
155
|
}
|
|
122
156
|
// Local additions/filemodifications
|
|
@@ -126,7 +160,9 @@ class Deltas {
|
|
|
126
160
|
}
|
|
127
161
|
const currentLocalItem = currentLocalTree.tree[path];
|
|
128
162
|
const currentRemoteItem = currentRemoteTree.tree[path];
|
|
129
|
-
|
|
163
|
+
// If the item does not exist in the current remote tree, but does in the local one, it should be uploaded.
|
|
164
|
+
// We also check if it in fact has existed before (the inode), if so, we skip it.
|
|
165
|
+
if (!currentRemoteItem && currentLocalItem && !previousLocalTree.inodes[currentLocalItem.inode]) {
|
|
130
166
|
deltas.push({
|
|
131
167
|
type: currentLocalItem.type === "directory" ? "createRemoteDirectory" : "uploadFile",
|
|
132
168
|
path
|
|
@@ -134,19 +170,20 @@ class Deltas {
|
|
|
134
170
|
pathsAdded[path] = true;
|
|
135
171
|
continue;
|
|
136
172
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
173
|
+
// If the item exists in both trees and has a different mod time + hash, we upload it again.
|
|
174
|
+
if (currentRemoteItem &&
|
|
175
|
+
currentRemoteItem.type === "file" &&
|
|
176
|
+
currentLocalItem &&
|
|
177
|
+
currentLocalItem.lastModified > currentRemoteItem.lastModified &&
|
|
178
|
+
(await this.sync.localFileSystem.createFileHash({
|
|
179
|
+
relativePath: path,
|
|
180
|
+
algorithm: "md5"
|
|
181
|
+
})) !== this.sync.localFileHashes[currentLocalItem.path]) {
|
|
182
|
+
deltas.push({
|
|
183
|
+
type: "uploadFile",
|
|
184
|
+
path
|
|
185
|
+
});
|
|
186
|
+
pathsAdded[path] = true;
|
|
150
187
|
}
|
|
151
188
|
}
|
|
152
189
|
// Remote additions/changes
|
|
@@ -156,7 +193,9 @@ class Deltas {
|
|
|
156
193
|
}
|
|
157
194
|
const currentLocalItem = currentLocalTree.tree[path];
|
|
158
195
|
const currentRemoteItem = currentRemoteTree.tree[path];
|
|
159
|
-
|
|
196
|
+
// If the item does not exist in the current local tree, but does in the remote one, it should be download.
|
|
197
|
+
// We also check if it in fact has existed before (the UUID), if so, we skip it.
|
|
198
|
+
if (!currentLocalItem && currentRemoteItem && !previousRemoteTree.uuids[currentRemoteItem.uuid]) {
|
|
160
199
|
deltas.push({
|
|
161
200
|
type: currentRemoteItem.type === "directory" ? "createLocalDirectory" : "downloadFile",
|
|
162
201
|
path
|
|
@@ -164,14 +203,16 @@ class Deltas {
|
|
|
164
203
|
pathsAdded[path] = true;
|
|
165
204
|
continue;
|
|
166
205
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
206
|
+
// If the item exists in both trees and the mod time changed, we download it.
|
|
207
|
+
if (currentRemoteItem &&
|
|
208
|
+
currentRemoteItem.type === "file" &&
|
|
209
|
+
currentLocalItem &&
|
|
210
|
+
currentRemoteItem.lastModified > currentLocalItem.lastModified) {
|
|
211
|
+
deltas.push({
|
|
212
|
+
type: "downloadFile",
|
|
213
|
+
path
|
|
214
|
+
});
|
|
215
|
+
pathsAdded[path] = true;
|
|
175
216
|
}
|
|
176
217
|
}
|
|
177
218
|
// Filter deltas by sync mode
|
|
@@ -203,7 +244,67 @@ class Deltas {
|
|
|
203
244
|
delta.type === "renameLocalFile" ||
|
|
204
245
|
delta.type === "downloadFile");
|
|
205
246
|
}
|
|
206
|
-
|
|
247
|
+
// Work on deltas from "left to right" (ascending order, path length).
|
|
248
|
+
const deltasSorted = deltas.sort((a, b) => a.path.split("/").length - b.path.split("/").length);
|
|
249
|
+
// Here we apply the done task to the delta state.
|
|
250
|
+
// E.g. when the user renames/moves a directory from "/sync/dir" to "/sync/dir2"
|
|
251
|
+
// we'll get all the rename/move deltas for the directory children aswell.
|
|
252
|
+
// This is pretty unecessary, hence we filter them here.
|
|
253
|
+
// Same for deletions. We only ever need to rename/move/delete the parent directory if the children did not change.
|
|
254
|
+
// This saves a lot of disk usage and API requests. This also saves time applying all done tasks to the overall state,
|
|
255
|
+
// since we need to loop through less doneTasks.
|
|
256
|
+
for (let i = 0; i < deltasSorted.length; i++) {
|
|
257
|
+
const delta = deltasSorted[i];
|
|
258
|
+
let moveUp = false;
|
|
259
|
+
if (delta.type === "renameLocalDirectory" || delta.type === "renameLocalFile") {
|
|
260
|
+
for (const directoryDelta of renamedLocalDirectories) {
|
|
261
|
+
if (directoryDelta.type === "renameLocalDirectory" && delta.from.startsWith(directoryDelta.from + "/")) {
|
|
262
|
+
const newFromPath = (0, utils_1.replacePathStartWithFromAndTo)(delta.from, directoryDelta.from, directoryDelta.to);
|
|
263
|
+
if (newFromPath === delta.to) {
|
|
264
|
+
deltasSorted.splice(i, 1);
|
|
265
|
+
moveUp = true;
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
deltasSorted.splice(i, 1, Object.assign(Object.assign({}, delta), { from: newFromPath }));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
else if (delta.type === "renameRemoteDirectory" || delta.type === "renameRemoteFile") {
|
|
274
|
+
for (const directoryDelta of renamedRemoteDirectories) {
|
|
275
|
+
if (directoryDelta.type === "renameRemoteDirectory" && delta.from.startsWith(directoryDelta.from + "/")) {
|
|
276
|
+
const newFromPath = (0, utils_1.replacePathStartWithFromAndTo)(delta.from, directoryDelta.from, directoryDelta.to);
|
|
277
|
+
if (newFromPath === delta.to) {
|
|
278
|
+
deltasSorted.splice(i, 1);
|
|
279
|
+
moveUp = true;
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
deltasSorted.splice(i, 1, Object.assign(Object.assign({}, delta), { from: newFromPath }));
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
else if (delta.type === "deleteLocalDirectory" || delta.type === "deleteLocalFile") {
|
|
288
|
+
for (const directoryDelta of deletedLocalDirectories) {
|
|
289
|
+
if (directoryDelta.type === "deleteLocalDirectory" && delta.path.startsWith(directoryDelta.path + "/")) {
|
|
290
|
+
deltasSorted.splice(i, 1);
|
|
291
|
+
moveUp = true;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
else if (delta.type === "deleteRemoteDirectory" || delta.type === "deleteRemoteFile") {
|
|
296
|
+
for (const directoryDelta of deletedRemoteDirectories) {
|
|
297
|
+
if (directoryDelta.type === "deleteRemoteDirectory" && delta.path.startsWith(directoryDelta.path + "/")) {
|
|
298
|
+
deltasSorted.splice(i, 1);
|
|
299
|
+
moveUp = true;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (moveUp) {
|
|
304
|
+
i--;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return deltasSorted;
|
|
207
308
|
}
|
|
208
309
|
}
|
|
209
310
|
exports.Deltas = Deltas;
|
package/dist/lib/deltas.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deltas.js","sourceRoot":"","sources":["../../src/lib/deltas.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"deltas.js","sourceRoot":"","sources":["../../src/lib/deltas.ts"],"names":[],"mappings":";;;AAGA,oCAAwD;AAiDxD;;;;;;;GAOG;AACH,MAAa,MAAM;IAGlB;;;;;;OAMG;IACH,YAAmB,IAAU;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IACjB,CAAC;IAED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AAC,CAAA;wBAEzB,MAAM,GAAG,IAAI,CAAA;oBACd,CAAC;gBACF,CAAC;YACF,CAAC;YAED,IAAI,MAAM,EAAE,CAAC;gBACZ,CAAC,EAAE,CAAA;YACJ,CAAC;QACF,CAAC;QAED,OAAO,YAAY,CAAA;IACpB,CAAC;CACD;AAxYD,wBAwYC;AAED,kBAAe,MAAM,CAAA"}
|
|
@@ -24,7 +24,7 @@ export type LocalTreeError = {
|
|
|
24
24
|
export type LocalTreeIgnored = {
|
|
25
25
|
localPath: string;
|
|
26
26
|
relativePath: string;
|
|
27
|
-
reason: "dotFile" | "localIgnore" | "defaultIgnore";
|
|
27
|
+
reason: "dotFile" | "localIgnore" | "defaultIgnore" | "empty" | "symlink" | "invalidType";
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
30
|
* LocalFileSystem
|
|
@@ -44,6 +44,9 @@ export declare class LocalFileSystem {
|
|
|
44
44
|
};
|
|
45
45
|
watcherRunning: boolean;
|
|
46
46
|
private watcherInstance;
|
|
47
|
+
readonly itemsMutex: import("../../semaphore").ISemaphore;
|
|
48
|
+
readonly mutex: import("../../semaphore").ISemaphore;
|
|
49
|
+
readonly mkdirMutex: import("../../semaphore").ISemaphore;
|
|
47
50
|
/**
|
|
48
51
|
* Creates an instance of LocalFileSystem.
|
|
49
52
|
*
|
|
@@ -118,32 +121,10 @@ export declare class LocalFileSystem {
|
|
|
118
121
|
mkdir({ relativePath }: {
|
|
119
122
|
relativePath: string;
|
|
120
123
|
}): Promise<fs.Stats>;
|
|
121
|
-
/**
|
|
122
|
-
* Delete a file/directory inside the local sync path.
|
|
123
|
-
* @date 3/3/2024 - 10:05:55 PM
|
|
124
|
-
*
|
|
125
|
-
* @public
|
|
126
|
-
* @async
|
|
127
|
-
* @param {{ relativePath: string; permanent?: boolean }} param0
|
|
128
|
-
* @param {string} param0.relativePath
|
|
129
|
-
* @param {boolean} [param0.permanent=false]
|
|
130
|
-
* @returns {Promise<void>}
|
|
131
|
-
*/
|
|
132
124
|
unlink({ relativePath, permanent }: {
|
|
133
125
|
relativePath: string;
|
|
134
126
|
permanent?: boolean;
|
|
135
127
|
}): Promise<void>;
|
|
136
|
-
/**
|
|
137
|
-
* Rename a file/directory inside the local sync path. Recursively creates intermediate directories if needed.
|
|
138
|
-
* @date 3/2/2024 - 12:41:15 PM
|
|
139
|
-
*
|
|
140
|
-
* @public
|
|
141
|
-
* @async
|
|
142
|
-
* @param {{ fromRelativePath: string; toRelativePath: string }} param0
|
|
143
|
-
* @param {string} param0.fromRelativePath
|
|
144
|
-
* @param {string} param0.toRelativePath
|
|
145
|
-
* @returns {Promise<fs.Stats>}
|
|
146
|
-
*/
|
|
147
128
|
rename({ fromRelativePath, toRelativePath }: {
|
|
148
129
|
fromRelativePath: string;
|
|
149
130
|
toRelativePath: string;
|
|
@@ -156,10 +137,13 @@ export declare class LocalFileSystem {
|
|
|
156
137
|
* @async
|
|
157
138
|
* @param {{ relativePath: string }} param0
|
|
158
139
|
* @param {string} param0.relativePath
|
|
159
|
-
* @returns {Promise<
|
|
140
|
+
* @returns {Promise<CloudItem>}
|
|
160
141
|
*/
|
|
161
142
|
upload({ relativePath }: {
|
|
162
143
|
relativePath: string;
|
|
163
144
|
}): Promise<CloudItem>;
|
|
145
|
+
isPathWritable(path: string): Promise<boolean>;
|
|
146
|
+
isPathReadable(path: string): Promise<boolean>;
|
|
147
|
+
pathExists(path: string): Promise<boolean>;
|
|
164
148
|
}
|
|
165
149
|
export default LocalFileSystem;
|