@@ -13,6 +13,7 @@ import { join } from "node:path";
13
13
import { pathToFiles } from "@cocalc/backend/files/path-to-files" ;
14
14
import getLogger from "@cocalc/backend/logger" ;
15
15
import { newCounter } from "@cocalc/backend/metrics" ;
16
+ import { homePath } from "@cocalc/backend/misc" ;
16
17
import getPool from "@cocalc/database/pool" ;
17
18
import { getServerSettings } from "@cocalc/database/settings" ;
18
19
import { callback2 } from "@cocalc/util/async-utils" ;
@@ -82,7 +83,8 @@ export async function unlink_old_deleted_projects(
82
83
db : PostgreSQL ,
83
84
age_d = 30 ,
84
85
) : Promise < void > {
85
- await callback2 ( db . _query , {
86
+ const L = log . extend ( "unlink_old_deleted_projects" ) . debug ;
87
+ const { rowCount } = await callback2 ( db . _query , {
86
88
query : "UPDATE projects" ,
87
89
set : { users : null } ,
88
90
where : [
@@ -91,6 +93,7 @@ export async function unlink_old_deleted_projects(
91
93
`last_edited <= NOW() - '${ age_d } days'::INTERVAL` ,
92
94
] ,
93
95
} ) ;
96
+ L ( "unlinked projects:" , rowCount ) ;
94
97
}
95
98
96
99
const Q_CLEANUP_SYNCSTRINGS = `
@@ -184,6 +187,13 @@ export async function cleanup_old_projects_data(
184
187
) ;
185
188
186
189
if ( on_prem ) {
190
+ // we don't delete the central_log, it has its own expiration
191
+ // such an entry is good to have for reconstructing what really happened
192
+ db . log ( {
193
+ event : "delete_project" ,
194
+ value : { deleting : "files" , project_id } ,
195
+ } ) ;
196
+
187
197
L2 ( `delete all project files` ) ;
188
198
await deleteProjectFiles ( L2 , project_id ) ;
189
199
@@ -199,6 +209,10 @@ export async function cleanup_old_projects_data(
199
209
200
210
// This gets rid of all sorts of data in tables specific to the given project.
201
211
delRows += await delete_associated_project_data ( L2 , project_id ) ;
212
+ db . log ( {
213
+ event : "delete_project" ,
214
+ value : { deleting : "database" , project_id } ,
215
+ } ) ;
202
216
203
217
// now, that we're done with that project, mark it as state.state ->> 'deleted'
204
218
// in addition to the flag "deleted = true". This also updates the state.time timestamp.
@@ -283,7 +297,8 @@ async function delete_associated_project_data(
283
297
284
298
async function deleteProjectFiles ( L2 , project_id : string ) {
285
299
// TODO: this only works on-prem, and requires the project files to be mounted
286
- const projects_root = process . env [ "MOUNTED_PROJECTS_ROOT" ] ;
300
+ const projects_root =
301
+ process . env [ "MOUNTED_PROJECTS_ROOT" ] ?? homePath ( project_id ) ;
287
302
if ( ! projects_root ) return ;
288
303
const project_dir = join ( projects_root , project_id ) ;
289
304
try {
@@ -297,7 +312,7 @@ async function deleteProjectFiles(L2, project_id: string) {
297
312
}
298
313
} catch ( err ) {
299
314
L2 (
300
- `not deleting project files: either it does not exist or is not accessible` ,
315
+ `not deleting project files: either path does not exist or is not accessible` ,
301
316
) ;
302
317
}
303
318
}
0 commit comments