mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
checking sqlite.db write permission
This commit is contained in:
parent
be25b9e068
commit
b46cdc2e11
@ -10,12 +10,33 @@ import {IPrivateConfig, ServerConfig} from '../../../common/config/private/IPriv
|
||||
|
||||
const LOG_TAG = '[ConfigDiagnostics]';
|
||||
|
||||
|
||||
export class ConfigDiagnostics {
|
||||
|
||||
static checkReadWritePermission(path: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// tslint:disable-next-line:no-bitwise
|
||||
fs.access(path, fs.constants.R_OK | fs.constants.W_OK, (err) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
return resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async testDatabase(databaseConfig: ServerConfig.DataBaseConfig) {
|
||||
if (databaseConfig.type !== ServerConfig.DatabaseType.memory) {
|
||||
await SQLConnection.tryConnection(databaseConfig);
|
||||
}
|
||||
if (databaseConfig.type !== ServerConfig.DatabaseType.sqlite) {
|
||||
try {
|
||||
await this.checkReadWritePermission(ProjectPath.getAbsolutePath(databaseConfig.sqlite.storage));
|
||||
} catch (e) {
|
||||
throw new Error('Cannot read or write sqlite storage file: ' +
|
||||
ProjectPath.getAbsolutePath(databaseConfig.sqlite.storage));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user