Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/api/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,12 @@ export function setup(mstream) {
res.json({});

try {
dbQueue.scanVPath(input.value.vpath);
}catch (err) {
if (dbQueue.isSubdirectoryOfExistingVpath(input.value.directory)) {
winston.info(`Skipping scan for '${input.value.vpath}' — directory is a subdirectory of an existing vpath`);
} else {
dbQueue.scanVPath(input.value.vpath);
}
} catch (err) {
winston.error('/api/v1/admin/directory failed to add ', { stack: err });
}
});
Expand Down
35 changes: 32 additions & 3 deletions src/db/task-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,35 @@ function findRustParser() {
return false;
}

// ── Subdirectory filtering ──────────────────────────────────────────────────

function filterSubdirectoryVpaths(libraries) {
const normalized = libraries.map(lib => ({
...lib,
_normalRoot: path.resolve(lib.root_path) + path.sep
}));

return normalized.filter((lib, _i, all) => {
return !all.some(other =>
other.name !== lib.name
&& lib._normalRoot.startsWith(other._normalRoot)
&& lib._normalRoot !== other._normalRoot
);
});
}

function isSubdirectoryOfExistingVpath(directory) {
const normalDir = path.resolve(directory) + path.sep;
const libraries = db.getAllLibraries();
for (const lib of libraries) {
const normalRoot = path.resolve(lib.root_path) + path.sep;
if (normalDir.startsWith(normalRoot) && normalDir !== normalRoot) {
return true;
}
}
return false;
}

// ── Scan task management ────────────────────────────────────────────────────

function addScanTask(vpath, forceRescan = false) {
Expand All @@ -58,14 +87,14 @@ function addScanTask(vpath, forceRescan = false) {
}

function scanAll() {
const libraries = db.getAllLibraries();
const libraries = filterSubdirectoryVpaths(db.getAllLibraries());
for (const lib of libraries) {
addScanTask(lib.name);
}
}

function rescanAll() {
const libraries = db.getAllLibraries();
const libraries = filterSubdirectoryVpaths(db.getAllLibraries());
for (const lib of libraries) {
addScanTask(lib.name, true);
}
Expand Down Expand Up @@ -154,7 +183,7 @@ export function scanVPath(vPath) {
addScanTask(vPath);
}

export { scanAll, rescanAll };
export { scanAll, rescanAll, isSubdirectoryOfExistingVpath };

export function isScanning() {
return runningTasks.size > 0;
Expand Down