@cocalc/project
Version:
CoCalc: project daemon
51 lines • 1.95 kB
JavaScript
;
/*
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
* License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.delete_files = void 0;
const fs_1 = require("fs");
const awaiting_1 = require("awaiting");
const api_1 = require("./api");
const listings_1 = require("../sync/listings");
const delete_files_1 = require("@cocalc/util/delete-files");
const fs_extra_1 = require("fs-extra");
// Delete the files/directories in the given project with the given list of paths.
async function delete_files(paths, logger) {
logger.debug(`delete_files ${JSON.stringify(paths)}`);
// Update the listings table to record that these were deleted.
const listings = (0, listings_1.get_listings_table)();
if (listings != null) {
for (const path of paths) {
await listings.set_deleted(path);
}
}
// For each path that exists and is not a directory,
// add in all the hidden variants.
let extra = [];
for (const path of paths) {
try {
const s = await (0, awaiting_1.callback)(fs_1.stat, path);
if (!s.isDirectory()) {
for (const variation of (0, delete_files_1.deleted_file_variations)(path)) {
if (await (0, fs_extra_1.pathExists)(variation)) {
if (listings != null) {
await listings.set_deleted(variation);
}
extra.push(variation);
}
}
}
}
catch (_err) { }
}
// Actually delete the files and directories and any hidden variants
await (0, api_1.exec)({
command: "rm",
timeout: 60,
args: ["-rf", "--"].concat(paths).concat(extra),
});
}
exports.delete_files = delete_files;
//# sourceMappingURL=delete-files.js.map