use mount code to check mount status

This commit is contained in:
Girish Ramakrishnan
2022-10-02 16:51:03 +02:00
parent a4a9b52966
commit 4f4a0ec289

View File

@@ -77,25 +77,17 @@ async function checkBackupPreconditions(apiConfig, dataLayout) {
assert.strictEqual(typeof apiConfig, 'object');
assert(dataLayout instanceof DataLayout, 'dataLayout must be a DataLayout');
let backupRootPath;
if (apiConfig.provider === PROVIDER_SSHFS || apiConfig.provider === PROVIDER_CIFS || apiConfig.provider === PROVIDER_NFS || apiConfig.provider === PROVIDER_EXT4 || apiConfig.provider === PROVIDER_XFS) {
backupRootPath = paths.MANAGED_BACKUP_MOUNT_DIR;
} else if (apiConfig.provider === PROVIDER_MOUNTPOINT) {
backupRootPath = paths.apiConfig.mountpoint;
} else {
backupRootPath = apiConfig.backupFolder;
}
const [error, dfResult] = await safe(df.file(backupRootPath)); // without prefix in case it's not mounted at all
if (error) throw new BoxError(BoxError.FS_ERROR, `Error when checking for disk space: ${error.message}`);
// Check filesystem is mounted so we don't write into the actual folder on disk
if (apiConfig.provider === PROVIDER_SSHFS || apiConfig.provider === PROVIDER_CIFS || apiConfig.provider === PROVIDER_NFS || apiConfig.provider === PROVIDER_EXT4 || apiConfig.provider === PROVIDER_XFS) {
if (dfResult.mountpoint !== paths.MANAGED_BACKUP_MOUNT_DIR) throw new BoxError(BoxError.FS_ERROR, 'Backup target is not mounted');
} else if (apiConfig.provider === PROVIDER_MOUNTPOINT) {
if (dfResult.mountpoint === '/') throw new BoxError(BoxError.FS_ERROR, `${apiConfig.backupFolder} is not mounted`);
if (mounts.isManagedProvider(apiConfig.provider) || apiConfig.provider === 'mountpoint') {
const hostPath = mounts.isManagedProvider(apiConfig.provider) ? paths.MANAGED_BACKUP_MOUNT_DIR : apiConfig.mountPoint;
const status = await mounts.getStatus(apiConfig.provider, hostPath); // { state, message }
debug(`clean: mount point status is ${JSON.stringify(status)}`);
if (status.state !== 'active') throw new BoxError(BoxError.MOUNT_ERROR, `Backup endpoint is not mounted: ${status.message}`);
}
const [error, dfResult] = await safe(df.file(getBackupRootPath(apiConfig)));
if (error) throw new BoxError(BoxError.FS_ERROR, `Error when checking for disk space: ${error.message}`);
let used = 0;
for (const localPath of dataLayout.localPaths()) {
debug(`checkBackupPreconditions: getting disk usage of ${localPath}`);