Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/backend/files/delete-files.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { getHome } from "./util";6import { deleted_file_variations } from "@cocalc/util/delete-files";7import { rimraf } from "rimraf";8import { join } from "path";9import getLogger from "@cocalc/backend/logger";1011const log = getLogger("delete-files");1213// Delete the files/directories in the given project with the given list of paths.14export async function delete_files(15paths: string[],16home?: string,17): Promise<void> {18const HOME = getHome(home);19log.debug({ paths, HOME });20paths = paths.map((x) => (x.startsWith("/") ? x : join(HOME, x)));21// Add in all the hidden variants.22let extra: string[] = [];23for (const path of paths) {24for (const variation of deleted_file_variations(path)) {25extra.push(variation);26}27}28// Actually delete the files and directories and any hidden variants.29// This is just simply deleting the files from disk. It will get noticed30// by browser clients, etc. We could do stuff that is way more clever here31// involving the listings table... but:32// - that results in weird race conditions that can make files immediately33// reappear after deletion34// - we MUST make deletion detection fully work based entirely on what happens35// on the file system, e.g., due to git checkout and people using the terminal36log.debug("extra = ", extra);37await rimraf(paths.concat(extra), { maxRetries: 2 });38}394041