final issue i promise
This commit is contained in:
parent
51e0526622
commit
07a925b9f3
1 changed files with 29 additions and 29 deletions
|
|
@ -846,42 +846,42 @@ const copy = async (
|
||||||
args.push("latest");
|
args.push("latest");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply bandwidth limits from both source and destination configs
|
// Apply common args without automatic bandwidth limit injection to prevent duplication
|
||||||
// First apply destination config limits (for the main operation)
|
addCommonArgs(args, env, destConfig, { skipBandwidth: true });
|
||||||
addCommonArgs(args, env, destConfig);
|
|
||||||
|
|
||||||
// Then explicitly apply source-side bandwidth limits for the from-repo operation
|
// Manually handle bandwidth limits with correct copy semantics:
|
||||||
// Guard the formatBandwidthLimit calls and compute values upfront
|
// --limit-download uses sourceConfig.downloadLimit (limiting downloads from source repo)
|
||||||
const sourceUploadLimit = sourceConfig.uploadLimit ? formatBandwidthLimit(sourceConfig.uploadLimit) : "";
|
// --limit-upload uses destConfig.uploadLimit (limiting uploads to destination repo)
|
||||||
const sourceDownloadLimit = sourceConfig.downloadLimit ? formatBandwidthLimit(sourceConfig.downloadLimit) : "";
|
const sourceDownloadLimit = formatBandwidthLimit(sourceConfig.downloadLimit);
|
||||||
|
const destUploadLimit = formatBandwidthLimit(destConfig.uploadLimit);
|
||||||
// Determine effective limit for source (pick smaller numeric value if both exist)
|
|
||||||
let effectiveLimit = "";
|
|
||||||
if (sourceUploadLimit && sourceDownloadLimit) {
|
|
||||||
effectiveLimit = parseInt(sourceUploadLimit) < parseInt(sourceDownloadLimit) ? sourceUploadLimit : sourceDownloadLimit;
|
|
||||||
} else if (sourceUploadLimit) {
|
|
||||||
effectiveLimit = sourceUploadLimit;
|
|
||||||
} else if (sourceDownloadLimit) {
|
|
||||||
effectiveLimit = sourceDownloadLimit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sourceConfig.backend === "rclone") {
|
if (sourceConfig.backend === "rclone") {
|
||||||
// For rclone source backends, use single consolidated bwlimit
|
// For rclone source backends, use rclone.from.bwlimit with effective source limit
|
||||||
if (effectiveLimit) {
|
const sourceUploadLimit = formatBandwidthLimit(sourceConfig.uploadLimit);
|
||||||
args.push("-o", `rclone.from.bwlimit=${effectiveLimit}`);
|
|
||||||
|
// Determine effective limit for source (pick smaller numeric value if both exist)
|
||||||
|
let effectiveSourceLimit = "";
|
||||||
|
if (sourceUploadLimit && sourceDownloadLimit) {
|
||||||
|
effectiveSourceLimit = parseInt(sourceUploadLimit) < parseInt(sourceDownloadLimit) ? sourceUploadLimit : sourceDownloadLimit;
|
||||||
|
} else if (sourceUploadLimit) {
|
||||||
|
effectiveSourceLimit = sourceUploadLimit;
|
||||||
|
} else if (sourceDownloadLimit) {
|
||||||
|
effectiveSourceLimit = sourceDownloadLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (effectiveSourceLimit) {
|
||||||
|
args.push("-o", `rclone.from.bwlimit=${effectiveSourceLimit}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// For restic source backends, apply individual limits using the computed values
|
// For restic source backends, apply download limit from source
|
||||||
if (sourceUploadLimit) {
|
|
||||||
args.push("--limit-upload", sourceUploadLimit);
|
|
||||||
}
|
|
||||||
if (sourceDownloadLimit) {
|
if (sourceDownloadLimit) {
|
||||||
args.push("--limit-download", sourceDownloadLimit);
|
args.push("--limit-download", sourceDownloadLimit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourceConfig.backend === "sftp" && sourceEnv._SFTP_SSH_ARGS) {
|
// Apply upload limit to destination for all backends
|
||||||
args.push("-o", `sftp.args=${sourceEnv._SFTP_SSH_ARGS}`);
|
if (destUploadLimit) {
|
||||||
|
args.push("--limit-upload", destUploadLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(`Copying snapshots from ${sourceRepoUrl} to ${destRepoUrl}...`);
|
logger.info(`Copying snapshots from ${sourceRepoUrl} to ${destRepoUrl}...`);
|
||||||
|
|
@ -935,7 +935,7 @@ const formatBandwidthLimit = (limit?: BandwidthLimit): string => {
|
||||||
return `${Math.floor(kibibytesPerSecond)}`;
|
return `${Math.floor(kibibytesPerSecond)}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addCommonArgs = (args: string[], env: Record<string, string>, config?: RepositoryConfig) => {
|
export const addCommonArgs = (args: string[], env: Record<string, string>, config?: RepositoryConfig, options?: { skipBandwidth?: boolean }) => {
|
||||||
args.push("--json");
|
args.push("--json");
|
||||||
|
|
||||||
if (env._SFTP_SSH_ARGS) {
|
if (env._SFTP_SSH_ARGS) {
|
||||||
|
|
@ -950,8 +950,8 @@ export const addCommonArgs = (args: string[], env: Record<string, string>, confi
|
||||||
args.push("--cacert", env.RESTIC_CACERT);
|
args.push("--cacert", env.RESTIC_CACERT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add bandwidth limits if configuration is provided
|
// Add bandwidth limits if configuration is provided and not skipped
|
||||||
if (config) {
|
if (config && !options?.skipBandwidth) {
|
||||||
if (config.backend === "rclone") {
|
if (config.backend === "rclone") {
|
||||||
// For rclone backends, consolidate both upload and download limits into one bwlimit
|
// For rclone backends, consolidate both upload and download limits into one bwlimit
|
||||||
const uploadLimit = formatBandwidthLimit(config.uploadLimit);
|
const uploadLimit = formatBandwidthLimit(config.uploadLimit);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue