Skip to content

Commit

Permalink
feat: apply double check in folder deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
cg27shokworks committed Mar 16, 2024
1 parent 60f2ee9 commit 8833f09
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 47 deletions.
15 changes: 0 additions & 15 deletions src/apps/sync-engine/BindingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ export class BindingsManager {
await this.container.repositoryPopulator.run(tree.files);
await this.container.filesPlaceholderCreator.run(tree.files);

Logger.debug(
'Trashed in load',
tree.trashedFilesList,
tree.trashedFoldersList
);

Logger.debug(
'Trashed folder',
tree.trashedFoldersList.map((f) => f.path)
);
await this.container?.filesPlaceholderDeleter?.run(tree.trashedFilesList);
await this.container?.folderPlaceholderDeleter?.run(
tree.trashedFoldersList
Expand Down Expand Up @@ -317,11 +307,6 @@ export class BindingsManager {
try {
const tree = await this.container.existingItemsTreeBuilder.run();

Logger.debug(
'Trashed folder',
tree.trashedFoldersList.map((f) => f.path)
);

// Delete all the placeholders that are not in the tree
await this.container?.filesPlaceholderDeleter?.run(tree.trashedFilesList);
await this.container?.folderPlaceholderDeleter?.run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,14 @@ export class FilesPlaceholderDeleter {
);

Logger.info(
`localdb path: ${remote.path}\n
localdb uuid: ${remote['contentsId']}\n
localStatus: ${remote.status.value}\n
syncroot uuidd: ${localUUID.split(':')[1]}\n
syncroot uuidd2: ${localUUID}\n
remoteo status: ${fileStatus}\n
trashed condition: ${
`
Localdb path: ${remote.path}\n
___________\n
Condition Status: ${
fileStatus === FileStatuses.TRASHED ||
fileStatus === FileStatuses.DELETED
}\n
localUUID condition: ${localUUID.split(':')[1] === remote['contentsId']}\n
lenuuid: ${localUUID.split(':')[1]?.trim().length}\n
lenremote: ${remote['contentsId']?.trim().length}\n`
Condition ID: ${localUUID.split(':')[1] === remote['contentsId']}\n`
);
return (
(fileStatus === FileStatuses.TRASHED ||
Expand All @@ -48,13 +43,7 @@ export class FilesPlaceholderDeleter {

private async delete(remote: File): Promise<void> {
const hasToBeDeleted = await this.hasToBeDeleted(remote);
Logger.info(`hasToBeDeleted: ${hasToBeDeleted}`);
if (hasToBeDeleted) {
Logger.info(`deleting file: ${remote.path}`);
// const win32AbsolutePath = this.relativePathToAbsoluteConverter.run(
// remote.path
// );
// Logger.info(`win32AbsolutePath: ${win32AbsolutePath}`);
await this.local.deleteFileSyncRoot(remote.path);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { RelativePathToAbsoluteConverter } from '../../shared/application/RelativePathToAbsoluteConverter';
import { Folder } from '../domain/Folder';
import { FolderStatuses } from '../domain/FolderStatus';
import fs from 'fs/promises';
import { RemoteFileSystem } from '../domain/file-systems/RemoteFileSystem';
import { LocalFileSystem } from '../domain/file-systems/LocalFileSystem';
import Logger from 'electron-log';
import { sleep } from '../../../../apps/main/util';
import fs from 'fs/promises';

export class FolderPlaceholderDeleter {
constructor(
Expand All @@ -16,10 +14,14 @@ export class FolderPlaceholderDeleter {
) {}

private async hasToBeDeleted(remote: Folder): Promise<boolean> {
Logger.info(`remote path in hastobedeleted: ${remote.path}`);
if (!remote.path) {
return false;
}
const localUUID = await this.local.getFileIdentity(remote.path);
Logger.info(`localUUID in hastobedeleted: ${localUUID}`);
Logger.info(`Local UUID: ${localUUID}, remote path: ${remote.path}`);

if (!localUUID) {
Logger.info(`Local UUID not found for ${remote.path}, skipping deletion`);
return false;
}

Expand All @@ -28,20 +30,28 @@ export class FolderPlaceholderDeleter {
remote['uuid']
);

// temporal condition to avoid deleting folders that are not in the trash
// https://github.com/internxt/drive-desktop/blob/60f2ee9a28eab37438b3e8365f4bd519e748a047/src/context/virtual-drive/folders/infrastructure/HttpRemoteFileSystem.ts#L70
if (
folderStatus === FolderStatuses.DELETED &&
!remote.status.is(FolderStatuses.DELETED) &&
!remote.status.is(FolderStatuses.TRASHED)
) {
Logger.info(
`Folder ${remote.path} with undefined status, skipping deletion`
);
return false;
}

Logger.info(
`localdb path: ${remote.path}\n
localdb uuid: ${remote['uuid']}\n
localStatus: ${remote.status.value}\n
syncroot uuidd: ${localUUID.split(':')[1]}\n
syncroot uuidd2: ${localUUID}\n
remoteo status: ${folderStatus}\n
trashed condition: ${
`
Localdb path: ${remote.path}\n
___________\n
Condition Status: ${
folderStatus === FolderStatuses.TRASHED ||
folderStatus === FolderStatuses.DELETED
}\n
localUUID condition: ${localUUID.split(':')[1] === remote['uuid']}\n
lenuuid: ${localUUID.split(':')[1]?.trim().length}\n
lenremote: ${remote['uuid']?.trim().length}\n`
Condition ID: ${localUUID.split(':')[1] === remote['uuid']}\n`
);

return (
Expand All @@ -58,7 +68,6 @@ export class FolderPlaceholderDeleter {
const win32AbsolutePath = this.relativePathToAbsoluteConverter.run(
remote.path
);
Logger.info(`win32AbsolutePath in delete: ${win32AbsolutePath}`);
//await fs.rm(win32AbsolutePath, { recursive: true, force: true });
await this.local.deleteFileSyncRoot(remote.path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class HttpRemoteFileSystem implements RemoteFileSystem {
response = await this.trashClient.get(
`${process.env.NEW_DRIVE_URL}/drive/folders/${uuid}/meta`
);
} catch {
} catch (error) {
return FolderStatuses.DELETED;
}

Expand Down

0 comments on commit 8833f09

Please sign in to comment.