From 1e27d3e334a9d1f533cd652cba0542d09fb6d547 Mon Sep 17 00:00:00 2001 From: "@mazikiou" <mazikiou@takima.fr> Date: Mon, 4 Jul 2022 15:46:48 +0200 Subject: [PATCH] fix: fixed async issue when removing files no proper awaiting is made --- .../deadlock-extension/src/core/config.ts | 2 ++ .../deadlock-extension/src/core/gitMission.ts | 6 +++++ .../src/recorder/recorder.ts | 10 ++++++--- .../src/recorder/utils/gitea.ts | 4 ++-- .../src/recorder/utils/workdir.ts | 22 ++++++++----------- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/deadlock-plugins/deadlock-extension/src/core/config.ts b/deadlock-plugins/deadlock-extension/src/core/config.ts index caf45ef9..50d2bb53 100644 --- a/deadlock-plugins/deadlock-extension/src/core/config.ts +++ b/deadlock-plugins/deadlock-extension/src/core/config.ts @@ -6,6 +6,7 @@ const homeDir = os.homedir(); // if we are on container, means the directory will depend differently const onContainer = isDocker(); +// TODO: remove this next line const deadlockExtensionPath = path.join(homeDir, 'deadlock-extension'); const deadlockConfigPath = path.join(homeDir, '.deadlock'); @@ -14,6 +15,7 @@ export const missionWorkdir = path.join(deadlockConfigPath, 'workspace'); export const PROJECT_SRC_PATH = onContainer ? '/project' : path.join(homeDir, 'deadlock-extension', '/project'); +// TODO: remove this next line (theia????) export const PROJECT_DEADLOCK_DESKTOP_PATH = onContainer ? path.join('/home/deadlock/mission') : path.join(deadlockExtensionPath, 'project-theia'); diff --git a/deadlock-plugins/deadlock-extension/src/core/gitMission.ts b/deadlock-plugins/deadlock-extension/src/core/gitMission.ts index d80bf521..ae085a23 100644 --- a/deadlock-plugins/deadlock-extension/src/core/gitMission.ts +++ b/deadlock-plugins/deadlock-extension/src/core/gitMission.ts @@ -83,6 +83,12 @@ export default class GitMission { false, 'local', ); + await this.git.addConfig( + 'core.excludesFile', + `user-git-${this.userConfig!.userConfigJson.username}/\n`, + true, + 'local', + ); return Promise.resolve(this); } catch (e) { diff --git a/deadlock-plugins/deadlock-extension/src/recorder/recorder.ts b/deadlock-plugins/deadlock-extension/src/recorder/recorder.ts index 262354ac..192ff323 100644 --- a/deadlock-plugins/deadlock-extension/src/recorder/recorder.ts +++ b/deadlock-plugins/deadlock-extension/src/recorder/recorder.ts @@ -9,7 +9,6 @@ import AutomaticSave from './services/automatic-save'; import { clearFilesExceptGit, copyProjectSources, renameTempToUserGitFiles } from './utils/workdir'; import aquirePermissions from './utils/permission'; import { isReviewingStudent } from '../core/mission/model/userMission'; - export default class Recorder { private _gitMission?: GitMission; private userConfig?: UserConfigNode; @@ -33,7 +32,10 @@ export default class Recorder { async setupProject(userConfig: UserConfig, gitMission?: GitMission) { if (!isReviewingStudent(userConfig.userConfigJson)) { - await copyProjectSources(PROJECT_SRC_PATH, PROJECT_DEADLOCK_DESKTOP_PATH, ['.git/']); + await copyProjectSources(PROJECT_SRC_PATH, PROJECT_DEADLOCK_DESKTOP_PATH, [ + '.git/', + `user-git-${userConfig.userConfigJson.username}`, + ]); if (gitMission) { renameTempToUserGitFiles(PROJECT_DEADLOCK_DESKTOP_PATH, gitMission.author); @@ -41,7 +43,9 @@ export default class Recorder { error('Cannot start command recorder, gitMission not found'); } } else { - await copyProjectSources(PROJECT_SRC_PATH, PROJECT_DEADLOCK_DESKTOP_PATH); + await copyProjectSources(PROJECT_SRC_PATH, PROJECT_DEADLOCK_DESKTOP_PATH, [ + `user-git-${userConfig.userConfigJson.username}`, + ]); } } diff --git a/deadlock-plugins/deadlock-extension/src/recorder/utils/gitea.ts b/deadlock-plugins/deadlock-extension/src/recorder/utils/gitea.ts index 43852873..0a600f63 100644 --- a/deadlock-plugins/deadlock-extension/src/recorder/utils/gitea.ts +++ b/deadlock-plugins/deadlock-extension/src/recorder/utils/gitea.ts @@ -31,18 +31,18 @@ export async function commitAndPushOnQueue(gitMission: GitMission, from: 'Run' | async function commitAndPushCode(gitMission: GitMission) { try { + await gitMission.checkout(Branch.LIVE); await clearFilesExceptGit(PROJECT_SRC_PATH); copyGitUserFiles(PROJECT_DEADLOCK_DESKTOP_PATH, PROJECT_SRC_PATH, gitMission.author); execSync( - `rsync -r --exclude .git --exclude npm --exclude target ${PROJECT_DEADLOCK_DESKTOP_PATH}/* ${PROJECT_SRC_PATH}`, + `rsync -r --exclude .git --exclude node_modules --exclude target ${PROJECT_DEADLOCK_DESKTOP_PATH}/* ${PROJECT_SRC_PATH}`, ); if (existsSync(join(DEADLOCK_WORKDIR_PATH, '.gitignore'))) { await copyFile(join(DEADLOCK_WORKDIR_PATH, '.gitignore'), join(PROJECT_SRC_PATH, '.gitignore')); } const currentDate = format(new Date(), "HH'H'mm'_'dd/LL/y"); - await gitMission.checkout(Branch.LIVE); await gitMission.addAll(); await gitMission.commit(currentDate); await gitMission.push(); diff --git a/deadlock-plugins/deadlock-extension/src/recorder/utils/workdir.ts b/deadlock-plugins/deadlock-extension/src/recorder/utils/workdir.ts index ac0bf741..c446beba 100644 --- a/deadlock-plugins/deadlock-extension/src/recorder/utils/workdir.ts +++ b/deadlock-plugins/deadlock-extension/src/recorder/utils/workdir.ts @@ -1,9 +1,9 @@ import { exec as execCallback, execSync } from 'child_process'; -import { copyFileSync, existsSync, lstatSync, PathLike, readdirSync, renameSync } from 'fs'; +import { copyFileSync, existsSync, PathLike, readdirSync, renameSync } from 'fs'; import { join } from 'path'; import { log } from './log'; import { promisify } from 'util'; -import { mkdir, unlink, rm } from 'fs/promises'; +import { mkdir, rm } from 'fs/promises'; const exec = promisify(execCallback); const PREFIX = '[DEADLOCK-RECORDER]'; @@ -20,16 +20,12 @@ export async function copyProjectSources( } export async function clearFilesExceptGit(path: string) { - readdirSync(path).forEach(async (file) => { + for (const file of readdirSync(path)) { if (file !== '.git') { const curPath = join(path, file); - if (lstatSync(curPath).isDirectory()) { - await rm(curPath, { recursive: true }); - } else { - await unlink(curPath); - } + await rm(curPath, { recursive: true }); } - }); + } } function renameIfExistsSync(srcPath: PathLike, destPath: PathLike) { @@ -83,14 +79,14 @@ export function copyGitUserFiles(srcPath: string, destPath: string, userId: stri } export async function removeFilesOrDirectories(...paths: string[]) { - paths.filter(existsSync).forEach(async (path) => { + for (const path of paths.filter(existsSync)) { await rm(path, { recursive: true }); - }); + } } export async function emptyDirectories(...directoryPaths: string[]) { - directoryPaths.forEach(async (directoryPath) => { + for (const directoryPath of directoryPaths) { await rm(directoryPath, { recursive: true }); await mkdir(directoryPath); - }); + } } -- GitLab