Add some sshfs config tests

This commit is contained in:
Johannes Zellner
2020-06-05 12:43:09 +02:00
parent 6f60495d4d
commit 7ba3412aae
+19 -4
View File
@@ -103,10 +103,25 @@ function testConfig(apiConfig, callback) {
// TODO check fstab entry
// TODO check mountpoint
// TODO check we can stat backup dir
// TODO check backup dir is dir
// TODO check we can create 'snapshot' folder
// TODO check we can write to backup dir (create and remove test file)
const backupPath = path.join(apiConfig.mountPoint, apiConfig.prefix);
const stat = safe.fs.statSync(backupPath);
if (!stat) return callback(new BoxError(BoxError.BAD_FIELD, 'Directory does not exist or cannot be accessed: ' + safe.error.message), { field: 'prefix' });
if (!stat.isDirectory()) return callback(new BoxError(BoxError.BAD_FIELD, 'Backup location is not a directory', { field: 'prefix' }));
if (!safe.fs.mkdirSync(path.join(backupPath, 'snapshot')) && safe.error.code !== 'EEXIST') {
if (safe.error && safe.error.code === 'EACCES') return callback(new BoxError(BoxError.BAD_FIELD, `Access denied. Run "chown yellowtent:yellowtent ${backupPath}" on the server`, { field: 'prefix' }));
return callback(new BoxError(BoxError.BAD_FIELD, safe.error.message, { field: 'prefix' }));
}
if (!safe.fs.writeFileSync(path.join(backupPath, 'cloudron-testfile'), 'testcontent')) {
return callback(new BoxError(BoxError.BAD_FIELD, `Unable to create test file as 'yellowtent' user in ${backupPath}: ${safe.error.message}. Check dir/mount permissions`, { field: 'prefix' }));
}
if (!safe.fs.unlinkSync(path.join(backupPath, 'cloudron-testfile'))) {
return callback(new BoxError(BoxError.BAD_FIELD, `Unable to remove test file as 'yellowtent' user in ${backupPath}: ${safe.error.message}. Check dir/mount permissions`, { field: 'prefix' }));
}
callback(null);
}