Skip to content

Commit

Permalink
fix: implemented safeguard for rclone enabled IMAP server
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed May 6, 2024
1 parent 4d4dd41 commit 03e660b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions helpers/get-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

const fs = require('node:fs');
const os = require('node:os');

// <https://github.com/knex/knex-schema-inspector/pull/146>
const Database = require('better-sqlite3-multiple-ciphers');
Expand All @@ -27,6 +28,8 @@ const migrateSchema = require('#helpers/migrate-schema');
const setupPragma = require('#helpers/setup-pragma');
const { acquireLock, releaseLock } = require('#helpers/lock');

const HOSTNAME = os.hostname();

const REQUIRED_PATHS = [
'INBOX',
'Drafts',
Expand Down Expand Up @@ -160,7 +163,7 @@ async function getDatabase(
//
if (readonly) {
let exists = false;
if (env.SQLITE_RCLONE_ENABLED) {
if (env.SQLITE_RCLONE_ENABLED && HOSTNAME === env.IMAP_HOST) {
try {
const stats = await fs.promises.stat(dbFilePath);
if (stats.isFile()) exists = true;
Expand Down Expand Up @@ -192,7 +195,7 @@ async function getDatabase(
// is wrong with the local file system or rclone mount
//
if (newlyCreated) {
if (env.SQLITE_RCLONE_ENABLED) {
if (env.SQLITE_RCLONE_ENABLED && HOSTNAME === env.IMAP_HOST) {
const err = new TypeError(
'Newly created and still having readonly issues'
);
Expand Down

0 comments on commit 03e660b

Please sign in to comment.