make sure we only use mount objects with the mounts api

This commit is contained in:
Johannes Zellner
2025-08-04 14:02:48 +02:00
parent 1a0d1f7d79
commit 90c82ab1e7

View File

@@ -273,23 +273,13 @@ async function cleanup(config, progressCallback) {
assert.strictEqual(typeof progressCallback, 'function');
}
async function setupManagedMount(provider, mountOptions, hostPath) {
assert.strictEqual(typeof provider, 'string');
assert.strictEqual(typeof mountOptions, 'object');
assert.strictEqual(typeof hostPath, 'string');
debug(`setupManagedMount: setting up mount at ${hostPath} with ${provider}`);
const newMount = {
function mountObjectFromConfig(config) {
return {
description: `Cloudron Managed Mount`,
hostPath,
mountType: provider,
mountOptions
hostPath: config._managedMountPath,
mountType: config._provider,
mountOptions: config.mountOptions
};
await mounts.tryAddMount(newMount, { timeout: 10 }); // 10 seconds
return newMount;
}
async function setup(config) {
@@ -298,11 +288,11 @@ async function setup(config) {
debug('setup: removing old storage configuration');
if (!mounts.isManagedProvider(config._provider)) return;
const mountPath = path.join(paths.MANAGED_BACKUP_MOUNT_DIR, config.id);
await safe(mounts.removeMount(mountPath), { debug }); // ignore error
const mount = mountObjectFromConfig(config);
await safe(mounts.removeMount(mount), { debug }); // ignore error
debug('setup: setting up new storage configuration');
await setupManagedMount(config._provider, config.mountOptions, mountPath);
await mounts.tryAddMount(mount, { timeout: 10 }); // 10 seconds
}
async function teardown(config) {
@@ -310,8 +300,7 @@ async function teardown(config) {
if (!mounts.isManagedProvider(config._provider)) return;
const mountPath = path.join(paths.MANAGED_BACKUP_MOUNT_DIR, config.id);
await safe(mounts.removeMount({ hostPath: mountPath, mountType: config._provider, mountOptions: config.mountOptions }), { debug }); // ignore error
await safe(mounts.removeMount(mountObjectFromConfig(config)), { debug }); // ignore error
}
async function verifyConfig({ id, provider, config }) {
@@ -344,7 +333,7 @@ async function verifyConfig({ id, provider, config }) {
const error = mounts.validateMountOptions(provider, config.mountOptions);
if (error) throw error;
await setupManagedMount(provider, config.mountOptions, `${managedMountPath}-validation`);
await mounts.tryAddMount(mountObjectFromConfig({ provider, mountOptions: config.mountOptions, hostPath: `${managedMountPath}-validation` }), { timeout: 10 });
} else if (provider === mounts.MOUNT_TYPE_MOUNTPOINT) {
if (!config.mountPoint || typeof config.mountPoint !== 'string') throw new BoxError(BoxError.BAD_FIELD, 'mountPoint must be non-empty string');
const error = validateDestDir(config.mountPoint);
@@ -358,7 +347,7 @@ async function verifyConfig({ id, provider, config }) {
}
const tmp = _.pick(config, ['noHardlinks', 'chown', 'preserveAttributes', 'backupDir', 'prefix', 'mountOptions', 'mountPoint']);
const newConfig = { _provider: provider, _managedMountPath: managedMountPath, id, ...tmp };
const newConfig = { _provider: provider, _managedMountPath: managedMountPath, ...tmp };
const fullPath = getRootPath(newConfig);
if (!safe.fs.mkdirSync(path.join(fullPath, 'snapshot'), { recursive: true }) && safe.error.code !== 'EEXIST') {