From f1bba7b191cf2b589b41c72b5551d504b0d0c1d3 Mon Sep 17 00:00:00 2001 From: miguel Date: Fri, 5 Apr 2024 11:30:57 -0500 Subject: [PATCH 1/3] wip: add fileIdentityUpdater - add updateIdentity of nodewin - add updateIdentity to update content --- .../dependency-injection/files/FilesContainer.ts | 2 ++ .../sync-engine/dependency-injection/files/builder.ts | 5 +++++ .../files/application/FileIndetityUpdater.ts | 10 ++++++++++ .../virtual-drive/files/application/FileSyncronizer.ts | 3 +++ .../files/domain/file-systems/LocalFileSystem.ts | 5 +++++ .../files/infrastructure/NodeWinLocalFileSystem.ts | 7 ++++++- 6 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/context/virtual-drive/files/application/FileIndetityUpdater.ts diff --git a/src/apps/sync-engine/dependency-injection/files/FilesContainer.ts b/src/apps/sync-engine/dependency-injection/files/FilesContainer.ts index 06359dc19..c692474e1 100644 --- a/src/apps/sync-engine/dependency-injection/files/FilesContainer.ts +++ b/src/apps/sync-engine/dependency-injection/files/FilesContainer.ts @@ -15,6 +15,7 @@ import { FilePlaceholderConverter } from '../../../../context/virtual-drive/file import { FileSyncStatusUpdater } from '../../../../context/virtual-drive/files/application/FileSyncStatusUpdater'; import { FileCheckerStatusInRoot } from '../../../../context/virtual-drive/files/application/FileCheckerStatusInRoot'; import { FilesPlaceholderDeleter } from '../../../../context/virtual-drive/files/application/FilesPlaceholderDeleter'; +import { FileIdentityUpdater } from '../../../../context/virtual-drive/files/application/FileIndetityUpdater'; export interface FilesContainer { fileFinderByContentsId: FileFinderByContentsId; @@ -34,4 +35,5 @@ export interface FilesContainer { filePlaceholderConverter: FilePlaceholderConverter; fileSyncStatusUpdater: FileSyncStatusUpdater; filesCheckerStatusInRoot: FileCheckerStatusInRoot; + fileIdentityUpdater: FileIdentityUpdater; } diff --git a/src/apps/sync-engine/dependency-injection/files/builder.ts b/src/apps/sync-engine/dependency-injection/files/builder.ts index 8a57d6db0..4cebc5297 100644 --- a/src/apps/sync-engine/dependency-injection/files/builder.ts +++ b/src/apps/sync-engine/dependency-injection/files/builder.ts @@ -31,6 +31,7 @@ import { FileSyncStatusUpdater } from '../../../../context/virtual-drive/files/a import { FileContentsUpdater } from '../../../../context/virtual-drive/files/application/FileContentsUpdater'; import { FileCheckerStatusInRoot } from '../../../../context/virtual-drive/files/application/FileCheckerStatusInRoot'; import { FilesPlaceholderDeleter } from '../../../../context/virtual-drive/files/application/FilesPlaceholderDeleter'; +import { FileIdentityUpdater } from '../../../../context/virtual-drive/files/application/FileIndetityUpdater'; export async function buildFilesContainer( folderContainer: FoldersContainer, @@ -144,10 +145,13 @@ export async function buildFilesContainer( remoteFileSystem ); + const fileIdentityUpdater = new FileIdentityUpdater(localFileSystem); + const fileSyncronizer = new FileSyncronizer( repository, fileSyncStatusUpdater, filePlaceholderConverter, + fileIdentityUpdater, fileCreator, sharedContainer.absolutePathToRelativeConverter, folderContainer.folderCreator, @@ -176,6 +180,7 @@ export async function buildFilesContainer( filePlaceholderConverter, fileSyncStatusUpdater, filesCheckerStatusInRoot, + fileIdentityUpdater, }; return { container, subscribers: [] }; diff --git a/src/context/virtual-drive/files/application/FileIndetityUpdater.ts b/src/context/virtual-drive/files/application/FileIndetityUpdater.ts new file mode 100644 index 000000000..6fb40e3c9 --- /dev/null +++ b/src/context/virtual-drive/files/application/FileIndetityUpdater.ts @@ -0,0 +1,10 @@ +import { File } from '../domain/File'; +import { LocalFileSystem } from '../domain/file-systems/LocalFileSystem'; + +export class FileIdentityUpdater { + constructor(private readonly localFileSystem: LocalFileSystem) {} + + async run(file: File) { + await this.localFileSystem.updateFileIdentity(file.path, file.placeholderId); + } +} diff --git a/src/context/virtual-drive/files/application/FileSyncronizer.ts b/src/context/virtual-drive/files/application/FileSyncronizer.ts index 6d97c3124..5ae1ad7d2 100644 --- a/src/context/virtual-drive/files/application/FileSyncronizer.ts +++ b/src/context/virtual-drive/files/application/FileSyncronizer.ts @@ -15,6 +15,7 @@ import { File } from '../domain/File'; import { FileSyncStatusUpdater } from './FileSyncStatusUpdater'; import { FilePlaceholderConverter } from './FIlePlaceholderConverter'; import { FileContentsUpdater } from './FileContentsUpdater'; +import { FileIdentityUpdater } from './FileIndetityUpdater'; export class FileSyncronizer { // queue of files to be uploaded @@ -23,6 +24,7 @@ export class FileSyncronizer { private readonly repository: FileRepository, private readonly fileSyncStatusUpdater: FileSyncStatusUpdater, private readonly filePlaceholderConverter: FilePlaceholderConverter, + private readonly fileIdentityUpdater: FileIdentityUpdater, private readonly fileCreator: FileCreator, private readonly absolutePathToRelativeConverter: AbsolutePathToRelativeConverter, private readonly folderCreator: FolderCreator, @@ -148,6 +150,7 @@ export class FileSyncronizer { private async convertAndUpdateSyncStatus(file: File) { await Promise.all([ this.filePlaceholderConverter.run(file), + this.fileIdentityUpdater.run(file), this.fileSyncStatusUpdater.run(file), ]); } diff --git a/src/context/virtual-drive/files/domain/file-systems/LocalFileSystem.ts b/src/context/virtual-drive/files/domain/file-systems/LocalFileSystem.ts index 7b8145823..84a201134 100644 --- a/src/context/virtual-drive/files/domain/file-systems/LocalFileSystem.ts +++ b/src/context/virtual-drive/files/domain/file-systems/LocalFileSystem.ts @@ -19,4 +19,9 @@ export interface LocalFileSystem { getPlaceholderStateByRelativePath( relativePath: string ): Promise; + + updateFileIdentity( + path: File['path'], + newIdentity: string + ): Promise; } diff --git a/src/context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem.ts b/src/context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem.ts index d656a751f..123082091 100644 --- a/src/context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem.ts +++ b/src/context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem.ts @@ -15,7 +15,7 @@ export class NodeWinLocalFileSystem implements LocalFileSystem { async getLocalFileId(file: File): Promise<`${string}-${string}`> { const win32AbsolutePath = this.relativePathToAbsoluteConverter.run( file.path - ); + ); const { ino, dev } = await fs.stat(win32AbsolutePath); @@ -72,4 +72,9 @@ export class NodeWinLocalFileSystem implements LocalFileSystem { relativePath ) as Promise; } + + async updateFileIdentity(path: string, newIdentity: `${string}-${string}`): Promise { + const isNotDirectory = true; + return this.virtualDrive.updateFileIdentity(path, newIdentity, isNotDirectory); + } } From 5b62c84a234b2361c98fb5c05e3b194e64046a14 Mon Sep 17 00:00:00 2001 From: miguel Date: Wed, 17 Apr 2024 17:36:06 -0500 Subject: [PATCH 2/3] fix update identity by unsyced file --- .../files/infrastructure/InMemoryFileRepository.ts | 7 +++++-- .../files/infrastructure/NodeWinLocalFileSystem.ts | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/context/virtual-drive/files/infrastructure/InMemoryFileRepository.ts b/src/context/virtual-drive/files/infrastructure/InMemoryFileRepository.ts index 431850df0..966fcf7c7 100644 --- a/src/context/virtual-drive/files/infrastructure/InMemoryFileRepository.ts +++ b/src/context/virtual-drive/files/infrastructure/InMemoryFileRepository.ts @@ -92,10 +92,13 @@ export class InMemoryFileRepository implements FileRepository { if (!this.files.has(file.contentsId)) { throw new Error('File not found'); } - + const oldContentsId = file.contentsId; const updatedFile = file.replaceContestsAndSize(newContentsId, newSize); + // first delete the old file to be able to add the new one + this.files.delete(oldContentsId); this.files.set(updatedFile.contentsId, updatedFile.attributes()); - this.files.delete(file.contentsId); return updatedFile; } + + } diff --git a/src/context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem.ts b/src/context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem.ts index 123082091..0f722dcf2 100644 --- a/src/context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem.ts +++ b/src/context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem.ts @@ -5,6 +5,7 @@ import { LocalFileSystem } from '../domain/file-systems/LocalFileSystem'; import { RelativePathToAbsoluteConverter } from '../../shared/application/RelativePathToAbsoluteConverter'; import fs from 'fs/promises'; import { PlaceholderState } from '../domain/PlaceholderState'; +import Logger from 'electron-log'; export class NodeWinLocalFileSystem implements LocalFileSystem { constructor( @@ -74,6 +75,7 @@ export class NodeWinLocalFileSystem implements LocalFileSystem { } async updateFileIdentity(path: string, newIdentity: `${string}-${string}`): Promise { + Logger.info('[updateFileIdentity]: ', path, newIdentity); const isNotDirectory = true; return this.virtualDrive.updateFileIdentity(path, newIdentity, isNotDirectory); } From f533fb878edb7485a2af7c0950178e5c3dd3bcdd Mon Sep 17 00:00:00 2001 From: miguel Date: Thu, 18 Apr 2024 16:32:21 -0500 Subject: [PATCH 3/3] wip: add dataintegrity on appstore --- src/apps/main/config.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/apps/main/config.ts b/src/apps/main/config.ts index 9a59413d7..c521a4d28 100644 --- a/src/apps/main/config.ts +++ b/src/apps/main/config.ts @@ -37,6 +37,7 @@ export interface AppStore { preferedLanguage?: string; preferedTheme?: string; virtualdriveWindowsLetter: string; + dataIntegrityMaintenance?: boolean; } const schema: Schema = { @@ -103,6 +104,9 @@ const schema: Schema = { virtualdriveWindowsLetter: { type: 'string', }, + dataIntegrityMaintenance: { + type: 'boolean', + }, } as const; export const defaults: AppStore = { @@ -127,6 +131,7 @@ export const defaults: AppStore = { preferedLanguage: '', preferedTheme: 'system', virtualdriveWindowsLetter: 'I', + dataIntegrityMaintenance: false, }; const configStore = new Store({ schema, defaults });