|
@@ -38,8 +38,6 @@ class FolderWatcher {
|
|
* If the file system directory corresponding to the (root) folder path of a
|
|
* If the file system directory corresponding to the (root) folder path of a
|
|
* folder watch is deleted on disk, we note down that in this queue so that
|
|
* folder watch is deleted on disk, we note down that in this queue so that
|
|
* we can ignore any file system events that come for it next.
|
|
* we can ignore any file system events that come for it next.
|
|
- *
|
|
|
|
- * TODO: is this really needed? the mappings are pre-checked first.
|
|
|
|
*/
|
|
*/
|
|
private deletedFolderPaths: string[] = [];
|
|
private deletedFolderPaths: string[] = [];
|
|
/** `true` if we are using the uploader. */
|
|
/** `true` if we are using the uploader. */
|
|
@@ -89,12 +87,12 @@ class FolderWatcher {
|
|
this.syncWithDisk();
|
|
this.syncWithDisk();
|
|
}
|
|
}
|
|
|
|
|
|
- /** `true` if we are currently using the uploader */
|
|
|
|
|
|
+ /** Return `true` if we are currently using the uploader. */
|
|
isUploadRunning() {
|
|
isUploadRunning() {
|
|
return this.uploadRunning;
|
|
return this.uploadRunning;
|
|
}
|
|
}
|
|
|
|
|
|
- /** `true` if syncing has been temporarily paused */
|
|
|
|
|
|
+ /** Return `true` if syncing has been temporarily paused. */
|
|
isSyncPaused() {
|
|
isSyncPaused() {
|
|
return this.isPaused;
|
|
return this.isPaused;
|
|
}
|
|
}
|
|
@@ -501,31 +499,30 @@ class FolderWatcher {
|
|
this.eventQueue = this.eventQueue.filter(
|
|
this.eventQueue = this.eventQueue.filter(
|
|
(event) => !event.filePath.startsWith(deletedFolderPath),
|
|
(event) => !event.filePath.startsWith(deletedFolderPath),
|
|
);
|
|
);
|
|
|
|
+
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
private async moveToTrash(syncedFiles: FolderWatch["syncedFiles"]) {
|
|
private async moveToTrash(syncedFiles: FolderWatch["syncedFiles"]) {
|
|
|
|
+ const syncedFileForID = new Map<number, FolderWatchSyncedFile>();
|
|
|
|
+ for (const file of syncedFiles)
|
|
|
|
+ syncedFileForID.set(file.uploadedFileID, file);
|
|
|
|
+
|
|
const files = await getLocalFiles();
|
|
const files = await getLocalFiles();
|
|
- const toTrashFilesMap = new Map<number, FolderWatchSyncedFile>();
|
|
|
|
- for (const file of syncedFiles) {
|
|
|
|
- toTrashFilesMap.set(file.uploadedFileID, file);
|
|
|
|
- }
|
|
|
|
const filesToTrash = files.filter((file) => {
|
|
const filesToTrash = files.filter((file) => {
|
|
- if (toTrashFilesMap.has(file.id)) {
|
|
|
|
- const fileToTrash = toTrashFilesMap.get(file.id);
|
|
|
|
- if (fileToTrash.collectionID === file.collectionID) {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
|
|
+ const correspondingSyncedFile = syncedFileForID.get(file.id);
|
|
|
|
+ if (
|
|
|
|
+ correspondingSyncedFile &&
|
|
|
|
+ correspondingSyncedFile.collectionID == file.collectionID
|
|
|
|
+ ) {
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
+ return false;
|
|
});
|
|
});
|
|
- const groupFilesByCollectionId =
|
|
|
|
- groupFilesBasedOnCollectionID(filesToTrash);
|
|
|
|
-
|
|
|
|
- for (const [
|
|
|
|
- collectionID,
|
|
|
|
- filesToTrash,
|
|
|
|
- ] of groupFilesByCollectionId.entries()) {
|
|
|
|
- await removeFromCollection(collectionID, filesToTrash);
|
|
|
|
|
|
+
|
|
|
|
+ const filesByCollectionID = groupFilesBasedOnCollectionID(filesToTrash);
|
|
|
|
+ for (const [id, files] of filesByCollectionID.entries()) {
|
|
|
|
+ await removeFromCollection(id, files);
|
|
}
|
|
}
|
|
|
|
|
|
this.requestSyncWithRemote();
|
|
this.requestSyncWithRemote();
|