-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmoveExtensionDataPath.ts
More file actions
59 lines (53 loc) · 1.97 KB
/
moveExtensionDataPath.ts
File metadata and controls
59 lines (53 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { Logger } from "../utilities";
import { refreshLocalExercises } from "./refreshLocalExercises";
import { ActionContext } from "./types";
import * as fs from "fs-extra";
import * as path from "path";
import { Err, Result } from "ts-results";
import * as vscode from "vscode";
/**
* Moves physical location of all exercises on disk. Closes active course workspace's exercises for
* the duration of transfer.
*
* @param newPath New disk location for exercises.
*/
export async function moveExtensionDataPath(
actionContext: ActionContext,
newPath: vscode.Uri,
onUpdate?: (value: { percent: number; message?: string }) => void,
): Promise<Result<void, Error>> {
const { resources, tmc } = actionContext;
if (!(tmc.ok && resources.ok)) {
return new Err(new Error("Extension was not initialized properly"));
}
Logger.info("Moving extension data path");
// This appears to be unnecessary with current VS Code version
/*
const activeCourse = workspaceManager.activeCourse;
if (activeCourse) {
const exercisesToClose = workspaceManager
.getExercisesByCourseSlug(activeCourse)
.filter((x) => x.status === ExerciseStatus.Open)
.map((x) => x.exerciseSlug);
// Close exercises without writing the result to "reopen" them with refreshLocalExercises
const closeResult = await workspaceManager.closeCourseExercises(
activeCourse,
exercisesToClose,
);
if (closeResult.err) {
return closeResult;
}
}
*/
// Use given path if empty dir, otherwise append
let newFsPath = newPath.fsPath;
if (fs.readdirSync(newFsPath).length > 0) {
newFsPath = path.join(newFsPath, "tmcdata");
}
const moveResult = await tmc.val.moveProjectsDirectory(newFsPath, onUpdate);
if (moveResult.err) {
return moveResult;
}
resources.val.projectsDirectory = newFsPath;
return refreshLocalExercises(actionContext);
}