From 061bbd090b786e130bfc8babffa107aced510dd8 Mon Sep 17 00:00:00 2001 From: Eden Tyler-Moss Date: Sat, 21 Mar 2020 22:13:57 +0000 Subject: [PATCH] Create data directory if it doesn't exist. Previously the application would crash if the the data directory (~/.local/share/go-music/) was not created, since better-sqlite3 expects the directory to be there when creating the database file. Changed created config directory permissions to disallow public access. --- src/api/index.ts | 2 ++ src/config.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/api/index.ts b/src/api/index.ts index a8294c1..312b52d 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,5 +1,6 @@ /* 3rd party imports */ import path from 'path'; +import fs from 'fs'; import SQLite3 from 'better-sqlite3'; import express from 'express'; import { ApolloServer } from 'apollo-server-express'; @@ -39,6 +40,7 @@ class Api { this.config = config; try { + if (!fs.existsSync(this.config.dataDirectory)) fs.mkdirSync(this.config.dataDirectory, '0700'); this.db = new SQLite3(path.join(this.config.dataDirectory, 'go-music.db')); } catch(err) { Constants.FATAL_ERROR(`Error creating SQLite3 DB: ${err}`); diff --git a/src/config.ts b/src/config.ts index 8f1c7dd..e4f89ec 100644 --- a/src/config.ts +++ b/src/config.ts @@ -51,7 +51,7 @@ export const getOrSetConfig = async function(configPath: string, config: ConfigS }; const dirCreate = async function(): Promise { const configDir = path.dirname(configPath); - return fs.promises.mkdir(configDir, '0755') + return fs.promises.mkdir(configDir, '0750') .catch(() => { throw `Could not create ${configDir}` }); }; const openFile = async function(): Promise {