Skip to content

Commit

Permalink
Fix a bug with unlimited parallel downloads
Browse files Browse the repository at this point in the history
Previously no download workers are started when `--max-parallel-downloads`
is set to 0 which causes a crash. Now when this option is 0, a number of
workers equal to the number of packages in the lock file are started.

Related to #127
  • Loading branch information
bobeff committed Jun 1, 2021
1 parent f38feb1 commit 2794d67
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,9 @@ proc processLockedDependencies(pkgInfo: PackageInfo, options: Options):
downloadResults[].setLen(dependenciesToDownload[].len)

var downloadWorkers: seq[Future[void]]
for i in 0 ..< options.maxParallelDownloads:
let workersCount = min(
options.maxParallelDownloads, dependenciesToDownload[].len)
for i in 0 ..< workersCount:
downloadWorkers.add startDownloadWorker(
dependenciesToDownload, options, downloadResults)
waitFor all(downloadWorkers)
Expand Down
5 changes: 4 additions & 1 deletion src/nimblepkg/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,10 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
of "localdeps", "l": result.localdeps = true
of "nosslcheck": result.disableSslCertCheck = true
of "no-tarballs", "t": result.noTarballs = true
of "max-parallel-downloads", "m": result.maxParallelDownloads = parseInt(val)
of "max-parallel-downloads", "m":
result.maxParallelDownloads = parseInt(val)
if result.maxParallelDownloads == 0:
result.maxParallelDownloads = int.high
else: isGlobalFlag = false

var wasFlagHandled = true
Expand Down

0 comments on commit 2794d67

Please sign in to comment.