Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c2a2976
Refactor sync root management to use drive instance for unregistering…
ArceDanielShok Feb 11, 2025
53167e6
Update unregisterSyncRoot to use providerId instead of syncRootPath
ArceDanielShok Feb 12, 2025
976468b
Refactor registerSyncRoot to use providerId from instance and update …
ArceDanielShok Feb 12, 2025
850e4c3
Remove connections map from VirtualDrive and simplify disconnectSyncR…
ArceDanielShok Feb 12, 2025
693be0c
Add FilePlaceholderId type for improved type safety in TFetchDataCall…
ArceDanielShok Feb 12, 2025
326ad37
Remove syncRootPath parameter from connectSyncRoot method for cleaner…
ArceDanielShok Feb 13, 2025
5d68993
Refactor VirtualDrive to use logger for connection debug information …
ArceDanielShok Feb 13, 2025
2ff474e
Merge pull request #130 from internxt/chore/improve-sync-engine-and-v…
ArceDanielShok Feb 13, 2025
a95222d
Merge pull request #132 from internxt/master
dajimenezriv-internxt Feb 13, 2025
43e9c78
Delete 3758a9e6-de8b-4e1e-a4fe-53300d078e99
dajimenezriv-internxt Feb 13, 2025
bbc1c09
Add prettier
dajimenezriv-internxt Feb 13, 2025
cf10e3c
Remove prettier
dajimenezriv-internxt Feb 13, 2025
1ec350c
Update pull-request.yml
dajimenezriv-internxt Feb 13, 2025
4874fa2
Create .gitattributes
dajimenezriv-internxt Feb 13, 2025
04c2447
Update .gitattributes
dajimenezriv-internxt Feb 13, 2025
82ec823
Update .gitattributes
dajimenezriv-internxt Feb 13, 2025
b990df3
Update pull-request.yml
dajimenezriv-internxt Feb 13, 2025
0ee614d
Update pull-request.yml
dajimenezriv-internxt Feb 13, 2025
8813ddd
Remove IQueueManager
dajimenezriv-internxt Feb 13, 2025
61d0df6
Update virtual-drive.ts
dajimenezriv-internxt Feb 13, 2025
f951ed7
Merge pull request #133 from internxt/add-prettier
ArceDanielShok Feb 14, 2025
53fccf6
Check PR size
dajimenezriv-internxt Feb 25, 2025
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=crlf
10 changes: 5 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
release:
types: [created]
workflow_dispatch:

jobs:
build-windows:
runs-on: windows-latest
Expand All @@ -12,7 +12,7 @@ jobs:
packages: write
steps:
- uses: actions/checkout@v2
- run: yarn build:gyp
- run: yarn build:gyp
- uses: actions/upload-artifact@v2
with:
name: windows-binaries
Expand All @@ -32,11 +32,11 @@ jobs:
path: build/Release
- uses: actions/setup-node@v2
with:
node-version: '16.x'
registry-url: 'https://npm.pkg.github.com'
node-version: "16.x"
registry-url: "https://npm.pkg.github.com"
- run: yarn
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: yarn publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 changes: 13 additions & 5 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Some pull request checks
name: Pull request checks

on:
pull_request:

jobs:
type-check:
runs-on: ubuntu-latest
checks:
runs-on: windows-latest

steps:
- name: Checkout code
Expand All @@ -16,11 +16,19 @@ jobs:
with:
node-version: 18

- name: Check PR size
- uses: maidsafe/pr_size_checker@v2
with:
max_lines_changed: 500

- name: Install dependencies
run: yarn install --ignore-scripts

- name: Run TypeScript compiler
run: yarn tsc

# - name: Run Vitest
# run: yarn vitest:once
- name: Run Prettier
run: yarn prettier . --check

- name: Run tests
run: yarn test:once
2 changes: 1 addition & 1 deletion examples/drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import VirtualDrive from "@/virtual-drive";

import settings from "./settings";

export const drive = new VirtualDrive(settings.syncRootPath, settings.defaultLogPath);
export const drive = new VirtualDrive(settings.syncRootPath, settings.providerid, settings.defaultLogPath);
export const logger = createLogger(settings.defaultLogPath);
4 changes: 2 additions & 2 deletions examples/populate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import VirtualDrive from "@/virtual-drive";

import { execSync } from "child_process";
import { join } from "path";
import { v4 } from "uuid";

import VirtualDrive from "@/virtual-drive";

import settings from "./settings";

const rootFileName1 = v4();
Expand Down
4 changes: 2 additions & 2 deletions examples/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const handlers = { handleAdd, handleHydrate, handleDehydrate, handleChangeSize }
const notify = { onTaskSuccess: async () => undefined, onTaskProcessing: async () => undefined };
const queueManager = new QueueManager(handlers, notify, settings.queuePersistPath);

drive.registerSyncRoot(settings.driveName, settings.driveVersion, settings.providerid, callbacks, settings.iconPath);
drive.registerSyncRoot(settings.driveName, settings.driveVersion, callbacks, settings.iconPath);
drive.connectSyncRoot();

try {
Expand All @@ -29,5 +29,5 @@ try {
} catch (error) {
logger.error(error);
drive.disconnectSyncRoot();
VirtualDrive.unregisterSyncRoot(settings.syncRootPath);
drive.unregisterSyncRoot();
}
4 changes: 2 additions & 2 deletions examples/unregister.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import VirtualDrive from "@/virtual-drive";

import { drive } from "./drive";
import { deleteInfoItems } from "./info-items-manager";
import settings from "./settings";

VirtualDrive.unregisterSyncRoot(settings.syncRootPath);
drive.unregisterSyncRoot();
deleteInfoItems();
65 changes: 32 additions & 33 deletions examples/utils.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
import fs from 'fs';
import path from 'path';
import fs from "fs";
import path from "path";

interface FileDetail {
path: string;
size: number;
baseDir: string;
path: string;
size: number;
baseDir: string;
}

function readFilesRecursively(dir: string, fileList: FileDetail[] = []): FileDetail[] {
fs.readdirSync(dir).forEach(file => {
const filePath = path.join(dir, file);
if (fs.statSync(filePath).isDirectory()) {
readFilesRecursively(filePath, fileList);
} else {
fileList.push({
path: filePath,
size: fs.statSync(filePath).size,
baseDir: dir
});
}
});
return fileList;
fs.readdirSync(dir).forEach((file) => {
const filePath = path.join(dir, file);
if (fs.statSync(filePath).isDirectory()) {
readFilesRecursively(filePath, fileList);
} else {
fileList.push({
path: filePath,
size: fs.statSync(filePath).size,
baseDir: dir,
});
}
});
return fileList;
}

function createFilesWithSize(sourceFolder: string, destFolder: string): void {
const files: FileDetail[] = readFilesRecursively(sourceFolder);
const files: FileDetail[] = readFilesRecursively(sourceFolder);

if (!fs.existsSync(destFolder)) {
fs.mkdirSync(destFolder, { recursive: true });
}

files.forEach(file => {
const relativePath = path.relative(file.baseDir, file.path);
const destFilePath = path.join(file.baseDir.replace(sourceFolder, destFolder), relativePath);//path.join(destFolder, relativePath);
const destFileDir = file.baseDir.replace(sourceFolder, destFolder);//path.dirname(destFilePath);
if (!fs.existsSync(destFolder)) {
fs.mkdirSync(destFolder, { recursive: true });
}

if (!fs.existsSync(destFileDir)){
fs.mkdirSync(destFileDir, { recursive: true });
}
files.forEach((file) => {
const relativePath = path.relative(file.baseDir, file.path);
const destFilePath = path.join(file.baseDir.replace(sourceFolder, destFolder), relativePath); //path.join(destFolder, relativePath);
const destFileDir = file.baseDir.replace(sourceFolder, destFolder); //path.dirname(destFilePath);

fs.writeFileSync(destFilePath, Buffer.alloc(file.size));
});
if (!fs.existsSync(destFileDir)) {
fs.mkdirSync(destFileDir, { recursive: true });
}

fs.writeFileSync(destFilePath, Buffer.alloc(file.size));
});
}

export { createFilesWithSize };
export { createFilesWithSize };
53 changes: 11 additions & 42 deletions examples/utils/generate-random-file-tree.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import VirtualDrive from '@/virtual-drive';
import { v4 as uuidv4 } from 'uuid';
import { v4 as uuidv4 } from "uuid";

import VirtualDrive from "@/virtual-drive";

interface GenerateOptions {
rootPath: string
rootPath: string;
depth: number;
filesPerFolder: number;
foldersPerLevel: number;
Expand All @@ -26,18 +27,7 @@ function randomNormal(mean: number, stdDev: number): number {
}

function getRandomExtension(): string {
const extensions = [
".txt",
".pdf",
".rar",
".jpg",
".docx",
".xlsx",
".mp4",
".mkv",
".json",
""
];
const extensions = [".txt", ".pdf", ".rar", ".jpg", ".docx", ".xlsx", ".mp4", ".mkv", ".json", ""];
const index = Math.floor(Math.random() * extensions.length);
return extensions[index];
}
Expand All @@ -47,17 +37,11 @@ async function createStructureRecursively(
currentPath: string,
level: number,
options: GenerateOptions,
result: Record<string, string>
result: Record<string, string>,
): Promise<void> {
if (level < 0) return;

const {
filesPerFolder,
foldersPerLevel,
meanSize,
stdDev,
timeOffset
} = options;
const { filesPerFolder, foldersPerLevel, meanSize, stdDev, timeOffset } = options;

for (let i = 0; i < filesPerFolder; i++) {
const fileName = `file_${generateRandomId()}${getRandomExtension()}`;
Expand All @@ -69,13 +53,7 @@ async function createStructureRecursively(
const createdAt = Date.now() - (timeOffset || 0);
const updatedAt = Date.now() - (timeOffset || 0) + 2000;

drive.createFileByPath(
fullPath,
fileId,
fileSize,
createdAt,
updatedAt
);
drive.createFileByPath(fullPath, fileId, fileSize, createdAt, updatedAt);

result[fileId] = fullPath;
}
Expand All @@ -88,22 +66,13 @@ async function createStructureRecursively(
const createdAt = Date.now() - (timeOffset || 0) - 10000; // Ejemplo
const updatedAt = Date.now() - (timeOffset || 0);

drive.createFolderByPath(
newFolderPath,
folderId,
1000,
createdAt,
updatedAt
);
drive.createFolderByPath(newFolderPath, folderId, 1000, createdAt, updatedAt);

await createStructureRecursively(drive, newFolderPath, level - 1, options, result);
}
}

async function generateRandomFilesAndFolders(
drive: VirtualDrive,
options: GenerateOptions
): Promise<Record<string, string>> {
async function generateRandomFilesAndFolders(drive: VirtualDrive, options: GenerateOptions): Promise<Record<string, string>> {
const { rootPath } = options;

const result: Record<string, string> = {};
Expand All @@ -114,4 +83,4 @@ async function generateRandomFilesAndFolders(
}

export { generateRandomFilesAndFolders };
export type { GenerateOptions }
export type { GenerateOptions };
12 changes: 6 additions & 6 deletions gyp.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"gyp_file": "binding.gyp",
"source_dirs": ["native-src/**/*.cpp"],
"ignored_source_dirs": [],
"include_dirs": ["include"],
"ignored_include_dirs": []
}
"gyp_file": "binding.gyp",
"source_dirs": ["native-src/**/*.cpp"],
"ignored_source_dirs": [],
"include_dirs": ["include"],
"ignored_include_dirs": []
}
8 changes: 5 additions & 3 deletions include/sync_root_interface/SyncRoot.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ class SyncRoot
public:
static HRESULT RegisterSyncRoot(const wchar_t *syncRootPath, const wchar_t *providerName, const wchar_t *providerVersion, const GUID &providerId, const wchar_t *logoPath);
static HRESULT ConnectSyncRoot(const wchar_t *syncRootPath, InputSyncCallbacks syncCallbacks, napi_env env, CF_CONNECTION_KEY *connectionKey);
static HRESULT DisconnectSyncRoot();
static HRESULT UnregisterSyncRoot();
static std::list<ItemInfo> GetItemsSyncRoot(const wchar_t *syncRootPath);
static HRESULT DisconnectSyncRoot(const wchar_t *syncRootPath);
static HRESULT UnregisterSyncRoot(const GUID &providerId);
static std::string GetFileIdentity(const wchar_t *path);
static void HydrateFile(const wchar_t *filePath);
static void DehydrateFile(const wchar_t *filePath);
static void DeleteFileSyncRoot(const wchar_t *path);

private:
CF_CONNECTION_KEY connectionKey;
};
Loading