fix more coderabbit issues

This commit is contained in:
Raj Dave 2026-01-10 14:47:58 +03:00
parent a7a4ccef6b
commit c91bce7814

View file

@ -851,31 +851,31 @@ const copy = async (
addCommonArgs(args, env, destConfig); addCommonArgs(args, env, destConfig);
// Then explicitly apply source-side bandwidth limits for the from-repo operation // Then explicitly apply source-side bandwidth limits for the from-repo operation
if (sourceConfig.uploadLimit?.enabled) { const sourceUploadLimit = formatBandwidthLimit(sourceConfig.uploadLimit);
const sourceUploadLimit = formatBandwidthLimit(sourceConfig.uploadLimit); const sourceDownloadLimit = formatBandwidthLimit(sourceConfig.downloadLimit);
if (sourceUploadLimit) {
if (sourceConfig.backend === "rclone") { // Determine effective limit for source (pick smaller numeric value if both exist)
// For rclone source backends, use rclone.bwlimit for the from-repo let effectiveLimit = "";
args.push("-o", `rclone.from.bwlimit=${sourceUploadLimit}`); if (sourceUploadLimit && sourceDownloadLimit) {
} else { effectiveLimit = parseInt(sourceUploadLimit) < parseInt(sourceDownloadLimit) ? sourceUploadLimit : sourceDownloadLimit;
// For restic source backends, the download from source becomes an upload limit } else if (sourceUploadLimit) {
args.push("--limit-upload", sourceUploadLimit); effectiveLimit = sourceUploadLimit;
} } else if (sourceDownloadLimit) {
} effectiveLimit = sourceDownloadLimit;
} }
if (sourceConfig.downloadLimit?.enabled) { if (sourceConfig.backend === "rclone") {
const sourceDownloadLimit = formatBandwidthLimit(sourceConfig.downloadLimit); // For rclone source backends, use single consolidated bwlimit
if (sourceDownloadLimit) { if (effectiveLimit) {
if (sourceConfig.backend === "rclone") { args.push("-o", `rclone.from.bwlimit=${effectiveLimit}`);
// For rclone source backends }
const sourceUploadLimit = sourceConfig.uploadLimit?.enabled ? formatBandwidthLimit(sourceConfig.uploadLimit) : ""; } else {
const effectiveLimit = sourceUploadLimit && parseInt(sourceUploadLimit) < parseInt(sourceDownloadLimit) ? sourceUploadLimit : sourceDownloadLimit; // For restic source backends, apply individual limits
args.push("-o", `rclone.from.bwlimit=${effectiveLimit}`); if (sourceConfig.uploadLimit?.enabled && sourceUploadLimit) {
} else { args.push("--limit-upload", sourceUploadLimit);
// For restic source backends, this affects reading from the source repo }
args.push("--limit-download", sourceDownloadLimit); if (sourceConfig.downloadLimit?.enabled && sourceDownloadLimit) {
} args.push("--limit-download", sourceDownloadLimit);
} }
} }
@ -915,8 +915,8 @@ const formatBandwidthLimit = (limit: BandwidthLimit): string => {
let kibibytesPerSecond: number; let kibibytesPerSecond: number;
switch (limit.unit) { switch (limit.unit) {
case "Kbps": case "Kbps":
// Kilobits per second to KiB/s: divide by 8 (bits to bytes), then by 1024 (bytes to KiB) // Kilobits per second to KiB/s: kilobits→bits→bytes→KiB
kibibytesPerSecond = limit.value / (8 * 1024); kibibytesPerSecond = (limit.value * 1000) / 8 / 1024;
break; break;
case "Mbps": case "Mbps":
// Megabits per second to KiB/s: multiply by 1000000 (Mb to bits), divide by 8 (bits to bytes), then by 1024 (bytes to KiB) // Megabits per second to KiB/s: multiply by 1000000 (Mb to bits), divide by 8 (bits to bytes), then by 1024 (bytes to KiB)
@ -951,32 +951,36 @@ export const addCommonArgs = (args: string[], env: Record<string, string>, confi
// Add bandwidth limits if configuration is provided // Add bandwidth limits if configuration is provided
if (config) { if (config) {
// Handle upload limit if (config.backend === "rclone") {
if (config.uploadLimit?.enabled) { // For rclone backends, consolidate both upload and download limits into one bwlimit
const uploadLimit = formatBandwidthLimit(config.uploadLimit); const uploadLimit = formatBandwidthLimit(config.uploadLimit);
if (uploadLimit) { const downloadLimit = formatBandwidthLimit(config.downloadLimit);
if (config.backend === "rclone") {
// For rclone backends, use --bwlimit // Determine effective limit (choose more restrictive when both exist)
args.push("-o", `rclone.bwlimit=${uploadLimit}`); let effectiveLimit = "";
} else { if (uploadLimit && downloadLimit) {
// For restic backends, use --limit-upload effectiveLimit = parseInt(uploadLimit) < parseInt(downloadLimit) ? uploadLimit : downloadLimit;
} else if (uploadLimit) {
effectiveLimit = uploadLimit;
} else if (downloadLimit) {
effectiveLimit = downloadLimit;
}
if (effectiveLimit) {
args.push("-o", `rclone.bwlimit=${effectiveLimit}`);
}
} else {
// For restic backends, handle upload and download limits separately
if (config.uploadLimit?.enabled) {
const uploadLimit = formatBandwidthLimit(config.uploadLimit);
if (uploadLimit) {
args.push("--limit-upload", uploadLimit); args.push("--limit-upload", uploadLimit);
} }
} }
}
// Handle download limit if (config.downloadLimit?.enabled) {
if (config.downloadLimit?.enabled) { const downloadLimit = formatBandwidthLimit(config.downloadLimit);
const downloadLimit = formatBandwidthLimit(config.downloadLimit); if (downloadLimit) {
if (downloadLimit) {
if (config.backend === "rclone") {
// For rclone, bwlimit affects both upload and download
// If both limits are set, use the more restrictive one
const uploadLimit = config.uploadLimit?.enabled ? formatBandwidthLimit(config.uploadLimit) : "";
const effectiveLimit = uploadLimit && parseInt(uploadLimit) < parseInt(downloadLimit) ? uploadLimit : downloadLimit;
args.push("-o", `rclone.bwlimit=${effectiveLimit}`);
} else {
// For restic backends, use --limit-download
args.push("--limit-download", downloadLimit); args.push("--limit-download", downloadLimit);
} }
} }
@ -1009,7 +1013,7 @@ const cleanupTemporaryKeys = async (env: Record<string, string>) => {
if (env[key]) { if (env[key]) {
try { try {
await fs.unlink(env[key]); await fs.unlink(env[key]);
} catch (error) { } catch (_error) {
// Ignore errors when cleaning up temporary files // Ignore errors when cleaning up temporary files
} }
} }
@ -1019,7 +1023,7 @@ const cleanupTemporaryKeys = async (env: Record<string, string>) => {
if (env.RESTIC_PASSWORD_FILE && env.RESTIC_PASSWORD_FILE !== RESTIC_PASS_FILE) { if (env.RESTIC_PASSWORD_FILE && env.RESTIC_PASSWORD_FILE !== RESTIC_PASS_FILE) {
try { try {
await fs.unlink(env.RESTIC_PASSWORD_FILE); await fs.unlink(env.RESTIC_PASSWORD_FILE);
} catch (error) { } catch (_error) {
// Ignore errors when cleaning up temporary files // Ignore errors when cleaning up temporary files
} }
} }