Skip to content

Commit

Permalink
Better handling around database paths
Browse files Browse the repository at this point in the history
* Be explicit in FirstRunConfig.js that the full database path is expected, not
  the folder that the database is in.
* If we do get a folder, check to see if the database is in it anyway, but let
  the user know a full path was expected.

Closes #24
  • Loading branch information
danrahn committed Mar 19, 2024
1 parent c164542 commit e1326e1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Server/FirstRunConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async function FirstRunConfig(dataRoot) {
}

const defaultDb = join(dataPath ? config.dataPath : defaultPath, 'Plug-in Support', 'Databases', 'com.plexapp.plugins.library.db');
const database = await askUserPath('Plex database path', rl, defaultDb, dataPath !== null);
const database = await askUserPath('Plex database file (full path)', rl, defaultDb, dataPath !== null);
if (database !== null) {
config.database = database;
}
Expand Down
22 changes: 22 additions & 0 deletions Server/PlexQueryManager.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { join } from 'path';
import { statSync } from 'fs';

import { BulkMarkerResolveType, EpisodeData, MarkerConflictResolution, MarkerData } from '../Shared/PlexTypes.js';
import { ConsoleLog, ContextualLog } from '../Shared/ConsoleLog.js';
import { MarkerEnum, MarkerType } from '../Shared/MarkerType.js';
Expand Down Expand Up @@ -219,6 +222,25 @@ FROM taggings
}

Log.info(`Verifying database ${databasePath}...`);
const dbInfo = statSync(databasePath, { throwIfNoEntry : false });
if (!dbInfo) {
throw new ServerError(`Database file "${databasePath}" could not be found.`);
}

if (dbInfo.isDirectory()) {
Log.warn(`Provided database path is a folder, expected the database itself. ` +
`Looking for database file in "${databasePath}"`);

const potentialDbPath = join(databasePath, 'com.plexapp.plugins.library.db');
const dbInfoMaybe = statSync(potentialDbPath, { throwIfNoEntry : false });
if (!dbInfoMaybe || !dbInfoMaybe.isFile()) {
Log.error(`Did not find expected database file in "${databasePath}", cannot continue`);
throw new ServerError('Database file not found.', 500);
}

databasePath = potentialDbPath;
}

/** @type {SqliteDatabase} */
let db;
try {
Expand Down

0 comments on commit e1326e1

Please sign in to comment.