@cocalc/project
Version:
CoCalc: project daemon
68 lines • 2.45 kB
JavaScript
;
/*
* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
* License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
/*
This makes dedicated disks conveniently available from the $HOME directory – a kucalc-only functionality.
*/
const dedicated_1 = require("@cocalc/util/consts/dedicated");
const fs_1 = require("fs");
const lodash_1 = require("lodash");
const os_1 = require("os");
const path_1 = require("path");
const logger_1 = require("./logger");
const project_setup_1 = require("./project-setup");
const { F_OK, W_OK, R_OK } = fs_1.constants;
const { info, warn } = (0, logger_1.getLogger)("dedicated-disks");
async function ensureSymlink(name) {
const disk = (0, path_1.join)(dedicated_1.ROOT, name);
const link = (0, path_1.join)((0, os_1.homedir)(), dedicated_1.HOME_PREFIX);
try {
await fs_1.promises.access(disk, F_OK | R_OK | W_OK);
}
catch {
warn(`disk directory ${disk} not writeable -- abort`);
return false;
}
// create a symlink to the /local directory
// don't disturb what's already in $HOME
try {
await fs_1.promises.access(link, F_OK);
info(`'${link}' already exists`);
}
catch {
// link does not exist, hence we create it
try {
await fs_1.promises.symlink(dedicated_1.ROOT, link);
info(`successfully symlinked ${link} → ${disk}`);
}
catch (err) {
warn(`problem symlinking ${link} → ${disk} -- ${err}`);
}
}
// even if there is a problem, it makes no sense to try again
return true;
}
async function init() {
info("initializing");
const conf = (0, project_setup_1.getProjectConfig)();
// we're a bit extra careful, because there could be anything in the DB
if (conf?.quota?.dedicated_disks == null)
return;
if (!(0, lodash_1.isArray)(conf.quota.dedicated_disks))
return;
for (const disk of conf.quota.dedicated_disks) {
if (typeof disk.name === "string") {
// if there is a disk, a symlink is made to point to the directory where it is
// hence it is enough to link to it once
if (await ensureSymlink(disk.name)) {
return;
}
}
}
}
exports.init = init;
//# sourceMappingURL=dedicated-disks.js.map