Skip to content

Commit 33ddc7a

Browse files
committed
hub/delete-projects: fix homePath, to make it work for the OnPrem situation
1 parent 55d2a11 commit 33ddc7a

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/packages/backend/misc.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createHash } from "crypto";
2+
import { join } from "node:path";
23

34
import { projects } from "@cocalc/backend/data";
45
import { is_valid_uuid_string } from "@cocalc/util/misc";
@@ -74,5 +75,11 @@ export function envForSpawn() {
7475

7576
// return the absolute home directory of given @project_id project on disk
7677
export function homePath(project_id: string): string {
77-
return projects.replace("[project_id]", project_id);
78+
// $MOUNTED_PROJECTS_ROOT is for OnPrem and that "projects" location is only for dev/single-user
79+
const projects_root = process.env.MOUNTED_PROJECTS_ROOT;
80+
if (projects_root) {
81+
return join(projects_root, project_id);
82+
} else {
83+
return projects.replace("[project_id]", project_id);
84+
}
7885
}

src/packages/database/postgres/delete-projects.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Code related to permanently deleting projects.
88
*/
99

1010
import { promises as fs } from "node:fs";
11-
import { join } from "node:path";
1211

1312
import { pathToFiles } from "@cocalc/backend/files/path-to-files";
1413
import getLogger, { WinstonLogger } from "@cocalc/backend/logger";
@@ -301,12 +300,7 @@ async function deleteProjectFiles(
301300
L2: WinstonLogger["debug"],
302301
project_id: string,
303302
) {
304-
// $MOUNTED_PROJECTS_ROOT is for OnPrem and homePath only works in dev/single-user
305-
const projects_root =
306-
process.env["MOUNTED_PROJECTS_ROOT"] ?? homePath(project_id);
307-
if (!projects_root) return;
308-
const project_dir = join(projects_root, project_id);
309-
L2(`attempting to delete all files in ${project_dir}`);
303+
const project_dir = homePath(project_id);
310304
try {
311305
await fs.access(project_dir, F_OK | R_OK | W_OK);
312306
const stats = await fs.lstat(project_dir);
@@ -318,7 +312,7 @@ async function deleteProjectFiles(
318312
}
319313
} catch (err) {
320314
L2(
321-
`not deleting project files: either path does not exist or is not accessible`,
315+
`not deleting project files: either '${project_dir}' does not exist or is not accessible`,
322316
);
323317
}
324318
}

0 commit comments

Comments
 (0)