mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-02 20:30:10 +00:00
Use content_path and add savePath/path-wait
Always use qBittorrent's content_path as the canonical downloadPath and expose savePath on DownloadInfo instead of reconstructing paths from save_path + basename. Add path-waiting logic to the monitor: track consecutive pathWaitCount polls, re-queue the monitor with exponential-ish backoff while content_path remains outside save_path (to handle TempPathEnabled races), and give up after a configurable max attempts. Extend the MonitorDownload payload and JobQueue APIs to carry pathWaitCount. Organize-files processor now attempts to refresh the stored downloadPath from the download client and updates downloadHistory if the client reports a different path (applying path mapping). Update tests to reflect the new behavior and expectations.
This commit is contained in:
@@ -32,7 +32,7 @@ function getBackoffDelay(stallCount: number): number {
|
||||
|
||||
export async function processMonitorDownload(payload: MonitorDownloadPayload): Promise<any> {
|
||||
const { requestId, downloadHistoryId, downloadClientId, downloadClient, jobId,
|
||||
lastProgress: prevProgress, stallCount: prevStallCount } = payload;
|
||||
lastProgress: prevProgress, stallCount: prevStallCount, pathWaitCount: prevPathWaitCount } = payload;
|
||||
|
||||
const logger = RMABLogger.forJob(jobId, 'MonitorDownload');
|
||||
|
||||
@@ -95,6 +95,32 @@ export async function processMonitorDownload(payload: MonitorDownloadPayload): P
|
||||
throw new Error('Download path not available from download client');
|
||||
}
|
||||
|
||||
// Detect TempPathEnabled race: content_path hasn't been relocated to save_path yet
|
||||
if (info.savePath && downloadPath) {
|
||||
const normalizedSave = info.savePath.endsWith('/') ? info.savePath : info.savePath + '/';
|
||||
if (!downloadPath.startsWith(normalizedSave)) {
|
||||
const waitCount = (prevPathWaitCount ?? 0) + 1;
|
||||
const MAX_PATH_WAIT = 30; // Give up after ~5 minutes
|
||||
|
||||
if (waitCount < MAX_PATH_WAIT) {
|
||||
const delay = Math.min(10, waitCount * 2); // 2s, 4s, 6s... up to 10s
|
||||
logger.info(`Download path still in temp location, waiting for relocation (${waitCount}/${MAX_PATH_WAIT})`, {
|
||||
downloadPath, savePath: info.savePath,
|
||||
});
|
||||
|
||||
const jobQueue = getJobQueueService();
|
||||
await jobQueue.addMonitorJob(
|
||||
requestId, downloadHistoryId, downloadClientId, downloadClient,
|
||||
delay, 100, 0, waitCount
|
||||
);
|
||||
|
||||
return { success: true, completed: false, message: 'Waiting for file relocation', pathWaitCount: waitCount };
|
||||
}
|
||||
|
||||
logger.warn(`Download path still in temp location after ${waitCount} checks, proceeding with organization`);
|
||||
}
|
||||
}
|
||||
|
||||
// Get path mapping configuration from the specific download client
|
||||
const clientConfig = await manager.getClientForProtocol(protocol);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user