Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2d5024c
Refactor watcher
dajimenezriv-internxt Mar 20, 2026
a253b3b
Commit
dajimenezriv-internxt Mar 23, 2026
861ff45
Commit
dajimenezriv-internxt Mar 23, 2026
0ccc245
Update fetch-folder.test.ts
dajimenezriv-internxt Mar 23, 2026
cf15e72
Commit
dajimenezriv-internxt Mar 23, 2026
1410fc2
Revert "Commit"
dajimenezriv-internxt Mar 23, 2026
1492967
Commit
dajimenezriv-internxt Mar 23, 2026
fc86224
Refactor watcher 2
dajimenezriv-internxt Mar 23, 2026
f2873e2
Update upload-file.test.ts
dajimenezriv-internxt Mar 23, 2026
6925b1c
Update client-wrapper.test.ts
dajimenezriv-internxt Mar 23, 2026
a523dc4
Merge branch 'refactor-watcher' into refactor-watcher-2
dajimenezriv-internxt Mar 23, 2026
36b1272
Commit
dajimenezriv-internxt Mar 23, 2026
84412f8
Commit
dajimenezriv-internxt Mar 23, 2026
88e7070
Commit
dajimenezriv-internxt Mar 23, 2026
3b72e43
Update on-unlink.test.ts
dajimenezriv-internxt Mar 23, 2026
50727c7
Update debounce-on-raw.ts
dajimenezriv-internxt Mar 23, 2026
8825895
Update debounce-on-raw.ts
dajimenezriv-internxt Mar 23, 2026
62b713d
Update debounce-on-raw.ts
dajimenezriv-internxt Mar 23, 2026
99d4584
Update process-event.test.ts
dajimenezriv-internxt Mar 23, 2026
f95899a
Commit
dajimenezriv-internxt Mar 23, 2026
8e6b8d1
Update create-placeholder.infra.test.ts
dajimenezriv-internxt Mar 23, 2026
196e254
Update on-unlink.test.ts
dajimenezriv-internxt Mar 23, 2026
346f12b
Refactor watcher 3
dajimenezriv-internxt Mar 23, 2026
e5d6538
Update utils.helper.test.ts
dajimenezriv-internxt Mar 23, 2026
86765a6
Commit
dajimenezriv-internxt Mar 23, 2026
500fbdb
Commit
dajimenezriv-internxt Mar 23, 2026
0c7ef1d
Commit
dajimenezriv-internxt Mar 23, 2026
f7fac91
Update check-if-modified.infra.test.ts
dajimenezriv-internxt Mar 23, 2026
baba74d
Revert
dajimenezriv-internxt Mar 24, 2026
3260175
Update measure-health.ts
dajimenezriv-internxt Mar 24, 2026
7314cd6
Merge branch 'refactor-watcher' into refactor-watcher-2
dajimenezriv-internxt Mar 24, 2026
438781f
Merge branch 'main' into refactor-watcher-2
dajimenezriv-internxt Mar 24, 2026
2f3a996
Merge branch 'refactor-watcher-2' into refactor-watcher-3
dajimenezriv-internxt Mar 25, 2026
4a04124
Merge branch 'main' into refactor-watcher-3
dajimenezriv-internxt Mar 25, 2026
b593914
Update on-unlink.test.ts
dajimenezriv-internxt Mar 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/apps/sync-engine/tests/create-placeholder.infra.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import { initWatcher } from '@/node-win/watcher/watcher';
import { VirtualDrive } from '@/node-win/virtual-drive';
import { join } from '@/context/local/localFile/infrastructure/AbsolutePath';
import { Sync } from '@/backend/features/sync';
import * as processEvent from '@/node-win/watcher/process-event';
import { SqliteModule } from '@/infra/sqlite/sqlite.module';

describe('create-placeholder', () => {
const processEventSpy = partialSpyOn(processEvent, 'processEvent', false);
const createFileMock = partialSpyOn(Sync.Actions, 'createFile');
const getByNameMock = partialSpyOn(SqliteModule.FileModule, 'getByName');

Expand Down Expand Up @@ -43,15 +41,17 @@ describe('create-placeholder', () => {

// When
await writeFile(file, 'content');
await sleep(3000);
return;
await sleep(2200);

// Then
calls(loggerMock.error).toHaveLength(0);
calls(loggerMock.debug).toStrictEqual([
calls(loggerMock.debug).toMatchObject([
{ tag: 'SYNC-ENGINE', msg: 'Create sync root folder', code: 'NON_EXISTS' },
{ msg: 'Register sync root', providerId, rootPath },
{ msg: 'Setup watcher' },
{ msg: 'Watcher event', event: { action: 'create', size: 0 } },
{ msg: 'Watcher event', event: { action: 'update', size: 7 } },
{ msg: 'Watcher event', event: { action: 'update', size: 7 } },
{
msg: 'On change event',
path: file,
Expand All @@ -63,11 +63,5 @@ describe('create-placeholder', () => {
isModified: true,
},
]);

calls(processEventSpy).toMatchObject([
{ event: 'create', path: file },
{ event: 'update', path: file },
{ event: 'update', path: file },
]);
});
});

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { call, calls, partialSpyOn } from '@/tests/vitest/utils.helper.test';
import { call, calls, partialSpyOn, TestProps } from '@/tests/vitest/utils.helper.test';
import { abs } from '@/context/local/localFile/infrastructure/AbsolutePath';
import { FolderUuid } from '@/apps/main/database/entities/DriveFolder';
import { loggerMock } from '@/tests/vitest/mocks.helper.test';
Expand All @@ -7,7 +7,6 @@ import { NodeWin } from '@/infra/node-win/node-win.module';
import { SqliteModule } from '@/infra/sqlite/sqlite.module';
import { onUnlink } from './on-unlink';
import * as ipcMain from '@/infra/drive-server-wip/out/ipc-main';
import { DeepPartial } from 'ts-essentials';

describe('on-unlink', () => {
const getFolderInfoMock = partialSpyOn(NodeWin, 'getFolderInfo');
Expand All @@ -16,7 +15,7 @@ describe('on-unlink', () => {
const deleteFileByUuidMock = partialSpyOn(ipcMain, 'deleteFileByUuid');
const deleteFolderByUuidMock = partialSpyOn(ipcMain, 'deleteFolderByUuid');

let props: DeepPartial<Parameters<typeof onUnlink>[0]>;
let props: TestProps<typeof onUnlink>;

beforeEach(() => {
getFolderInfoMock.mockResolvedValue({ data: { uuid: 'parentUuid' as FolderUuid } });
Expand All @@ -33,9 +32,9 @@ describe('on-unlink', () => {
// Given
getFolderInfoMock.mockResolvedValue({ error: new Error() });
// When
await onUnlink(props as any);
const promise = onUnlink(props as any);
// Then
expect(loggerMock.error).toBeCalledTimes(1);
await expect(promise).rejects.toThrow();
});

it('should skip if file does not exist', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,28 @@ type Props = {
};

export async function onUnlink({ ctx, path, type }: Props) {
try {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove try catch here, we are already cathing in the previous one and logging the whole event.

// Get parent placeholderId from the file explorer.
const parentPath = dirname(path);
const { data: parentInfo, error } = await NodeWin.getFolderInfo({ ctx, path: parentPath });
if (error) throw error;
// Get parent placeholderId from the file explorer.
const parentPath = dirname(path);
const { data: parentInfo, error } = await NodeWin.getFolderInfo({ ctx, path: parentPath });
if (error) throw error;

const parentUuid = parentInfo.uuid;
const name = basename(path);
const parentUuid = parentInfo.uuid;
const name = basename(path);

if (type === 'folder') {
// Since the item is deleted we cannot obtain the placeholderId from the file explorer
// and we need to obtain it from the sqlite.
const { data: folder } = await SqliteModule.FolderModule.getByName({ parentUuid, plainName: name });
if (!folder) return;
if (type === 'folder') {
// Since the item is deleted we cannot obtain the placeholderId from the file explorer
// and we need to obtain it from the sqlite.
const { data: folder } = await SqliteModule.FolderModule.getByName({ parentUuid, plainName: name });
if (!folder) return;

ctx.logger.debug({ msg: 'Folder unlinked', path });
await deleteFolderByUuid({ ctx, path, uuid: folder.uuid });
return;
}
ctx.logger.debug({ msg: 'Folder unlinked', path });
await deleteFolderByUuid({ ctx, path, uuid: folder.uuid });
return;
}

const { data: file } = await SqliteModule.FileModule.getByName({ parentUuid, nameWithExtension: name });
if (!file) return;
const { data: file } = await SqliteModule.FileModule.getByName({ parentUuid, nameWithExtension: name });
if (!file) return;

ctx.logger.debug({ msg: 'File unlinked', path });
await deleteFileByUuid({ ctx, path, uuid: file.uuid });
} catch (error) {
ctx.logger.error({ msg: 'Error on unlink event', path, error });
}
ctx.logger.debug({ msg: 'File unlinked', path });
await deleteFileByUuid({ ctx, path, uuid: file.uuid });
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('check-if-modified', () => {
uuid: 'uuid' as FileUuid,
absolutePath: path,
updatedAt: '2000-01-02',
size: 1000,
size: 14,
},
local: {
path,
Expand All @@ -48,28 +48,33 @@ describe('check-if-modified', () => {
// When
await sleep(100);
await checkIfModified(props);
await sleep(100);
return;
await sleep(2200);

// Then
calls(loggerMock.error).toHaveLength(0);
calls(loggerMock.debug).toStrictEqual([
calls(loggerMock.debug).toMatchObject([
{ tag: 'SYNC-ENGINE', msg: 'Create sync root folder', code: 'NON_EXISTS' },
{ msg: 'Register sync root', providerId, rootPath },
{ msg: 'Setup watcher' },
{ msg: 'Watcher event', event: { action: 'create', size: 0 } },
{ msg: 'Watcher event', event: { action: 'update', size: 7 } },
{ msg: 'Watcher event', event: { action: 'update', size: 7 } },
{
msg: 'Sync remote changes to local',
path,
remoteSize: 1000,
remoteSize: 14,
localSize: 7,
remoteDate: new Date('2000-01-02T00:00:00.000Z'),
localDate: new Date('2000-01-01T00:00:00.000Z'),
},
{ msg: 'Watcher event', event: { action: 'update', size: 14 } },
{ msg: 'Watcher event', event: { action: 'update', size: 14 } },
{ msg: 'Watcher event', event: { action: 'update', size: 14 } },
]);

const stats = await stat(path);
const fileInfo = await Addon.getPlaceholderState({ path });
expect(stats.size).toBe(1000);
expect(stats.size).toBe(14);
expect(fileInfo.onDiskSize).toBe(0);
});
});
60 changes: 0 additions & 60 deletions src/node-win/watcher/events/debounce-on-raw.test.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/node-win/watcher/events/debounce-on-raw.ts

This file was deleted.

25 changes: 9 additions & 16 deletions src/node-win/watcher/events/on-add-dir.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,17 @@ type TProps = {
};

export async function onAddDir({ ctx, path }: TProps) {
try {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove try catch here, we are already cathing in the previous one and logging the whole event.

const { data: folderInfo } = await NodeWin.getFolderInfo({ ctx, path });
const { data: folderInfo } = await NodeWin.getFolderInfo({ ctx, path });

if (folderInfo) {
await moveFolder({ ctx, path, uuid: folderInfo.uuid });
return;
}
if (folderInfo) {
await moveFolder({ ctx, path, uuid: folderInfo.uuid });
return;
}

const { data: parentInfo } = await NodeWin.getFolderInfo({ ctx, path: dirname(path) });
const { data: parentInfo } = await NodeWin.getFolderInfo({ ctx, path: dirname(path) });

if (parentInfo) {
await Drive.Actions.createFolder({
ctx,
path,
parentUuid: parentInfo.uuid,
});
}
} catch (error) {
ctx.logger.error({ msg: 'Error on addDir event', path, error });
if (parentInfo) {
const parentUuid = parentInfo.uuid;
await Drive.Actions.createFolder({ ctx, path, parentUuid });
}
}
Loading
Loading