Skip to content

Commit

Permalink
Fix: Auto correction now no longer shares temp dir with submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkoelle committed Jun 30, 2021
1 parent 5d44e33 commit 9219e3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 8 additions & 1 deletion app/autocorrection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ type MultipleSolutionsFound = {
type Solution = SingleSolutionFound | MultipleSolutionsFound | NoSolutionFound;

export default class AutoCorrection {
public static tempDir = 'auto_correction_temp';

constructor() {
if (!fs.existsSync(AutoCorrection.tempDir)) {
fs.mkdirSync(AutoCorrection.tempDir);
}

ipcMain.on(AUTOCORRECTION_START, (event: IpcMainEvent, arg) => {
const { sender } = event;
AutoCorrection.autoCorrectSingleChoiceTasksOfSheet(
Expand Down Expand Up @@ -171,7 +177,8 @@ export default class AutoCorrection {
const { submission } = c;
const txtFiles = loadFilesFromWorkspaceMainProcess(
submission.name,
workspace
workspace,
AutoCorrection.tempDir
).filter((f) => Path.extname(f) === '.txt');

// Extract the student solution from every .txt files
Expand Down
10 changes: 6 additions & 4 deletions app/utils/FileAccess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,15 @@ export function deleteEverythingInDir(dir: string) {

export function loadFilesFromWorkspace(
submissionName: string,
workspace: string
workspace: string,
dir = 'temp'
): string[] {
if (!fs.existsSync(workspace) || Path.extname(workspace) !== '.cor') {
return [];
}
const tempPaths: string[] = [];
const userDataPath: string = remote.app.getPath('userData');
const tempDir = Path.join(userDataPath, 'temp');
const tempDir = Path.join(userDataPath, dir);
if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir);
}
Expand Down Expand Up @@ -293,14 +294,15 @@ export function exportWorkspace(zipPath: string, workspace: string) {

export function loadFilesFromWorkspaceMainProcess(
submissionName: string,
workspace: string
workspace: string,
dir = 'temp'
): string[] {
if (!fs.existsSync(workspace) || Path.extname(workspace) !== '.cor') {
return [];
}
const tempPaths: string[] = [];
const userDataPath: string = app.getPath('userData');
const tempDir = Path.join(userDataPath, 'temp');
const tempDir = Path.join(userDataPath, dir);
if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir);
}
Expand Down

0 comments on commit 9219e3b

Please sign in to comment.