Skip to content

Commit

Permalink
Create data directory if it doesn't exist.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
etylermoss committed Mar 21, 2020
1 parent 5323ad2 commit 061bbd0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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}`);
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const getOrSetConfig = async function(configPath: string, config: ConfigS
};
const dirCreate = async function(): Promise<void> {
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<ConfigSchema> {
Expand Down

0 comments on commit 061bbd0

Please sign in to comment.