From 145c321fa1812e8c4529cc0012ca6a180075d7a7 Mon Sep 17 00:00:00 2001 From: Raj Dave Date: Sat, 10 Jan 2026 18:34:34 +0300 Subject: [PATCH] Refines bandwidth limit handling for rclone copy Simplifies bandwidth limit configuration for rclone source backends by considering only the source download limit. Ensures correct type casting when comparing upload and download limits, using base 10 for parsing. Makes the temporary keys cleanup function available for external use. --- app/server/utils/restic.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/app/server/utils/restic.ts b/app/server/utils/restic.ts index cb30421b..21987af4 100644 --- a/app/server/utils/restic.ts +++ b/app/server/utils/restic.ts @@ -856,16 +856,9 @@ const copy = async ( const destUploadLimit = formatBandwidthLimit(destConfig.uploadLimit); if (sourceConfig.backend === "rclone") { - // For rclone source backends, use rclone.from.bwlimit with effective source limit - const sourceUploadLimit = formatBandwidthLimit(sourceConfig.uploadLimit); - - // Determine effective limit for source (pick smaller numeric value if both exist) + // For rclone source backends, use rclone.from.bwlimit with source download limit only let effectiveSourceLimit = ""; - if (sourceUploadLimit && sourceDownloadLimit) { - effectiveSourceLimit = parseInt(sourceUploadLimit) < parseInt(sourceDownloadLimit) ? sourceUploadLimit : sourceDownloadLimit; - } else if (sourceUploadLimit) { - effectiveSourceLimit = sourceUploadLimit; - } else if (sourceDownloadLimit) { + if (sourceDownloadLimit) { effectiveSourceLimit = sourceDownloadLimit; } @@ -960,7 +953,7 @@ export const addCommonArgs = (args: string[], env: Record, confi // Determine effective limit (choose more restrictive when both exist) let effectiveLimit = ""; if (uploadLimit && downloadLimit) { - effectiveLimit = parseInt(uploadLimit) < parseInt(downloadLimit) ? uploadLimit : downloadLimit; + effectiveLimit = parseInt(uploadLimit, 10) < parseInt(downloadLimit, 10) ? uploadLimit : downloadLimit; } else if (uploadLimit) { effectiveLimit = uploadLimit; } else if (downloadLimit) { @@ -1003,7 +996,7 @@ export const restic = { }; // Helper function to clean up temporary files -const cleanupTemporaryKeys = async (env: Record) => { +export const cleanupTemporaryKeys = async (env: Record) => { const keysToClean = ["_SFTP_KEY_PATH", "_SFTP_KNOWN_HOSTS_PATH", "RESTIC_CACERT", "GOOGLE_APPLICATION_CREDENTIALS"]; for (const key of keysToClean) {