Skip to content

Commit 26c9102

Browse files
authored
Fix #953 (#962)
* Fix package download not using refreshed package list * Added test * Use exitCode to remove warning * Use clearer identifier names (`ignorePackageCache` instead of `clean`)
1 parent c44089b commit 26c9102

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/nimble.nim

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,14 +601,14 @@ proc processLockedDependencies(pkgInfo: PackageInfo, options: Options):
601601
raise nimbleError("Unsatisfied dependency: " & pkgInfo.basicInfo.name)
602602
603603
proc getDownloadInfo*(pv: PkgTuple, options: Options,
604-
doPrompt: bool): (DownloadMethod, string,
604+
doPrompt: bool, ignorePackageCache = false): (DownloadMethod, string,
605605
Table[string, string]) =
606606
if pv.name.isURL:
607607
let (url, metadata) = getUrlData(pv.name)
608608
return (checkUrlType(url), url, metadata)
609609
else:
610610
var pkg = initPackage()
611-
if getPackage(pv.name, options, pkg):
611+
if getPackage(pv.name, options, pkg, ignorePackageCache):
612612
let (url, metadata) = getUrlData(pkg.url)
613613
return (pkg.downloadMethod, url, metadata)
614614
else:
@@ -622,7 +622,8 @@ proc getDownloadInfo*(pv: PkgTuple, options: Options,
622622
# Once we've refreshed, try again, but don't prompt if not found
623623
# (as we've already refreshed and a failure means it really
624624
# isn't there)
625-
return getDownloadInfo(pv, options, false)
625+
# Also ignore the package cache so the old info isn't used
626+
return getDownloadInfo(pv, options, false, true)
626627
else:
627628
raise nimbleError(pkgNotFoundMsg(pv))
628629

src/nimblepkg/packageinfo.nim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ proc fetchList*(list: PackageList, options: Options) =
185185
# Cache after first call
186186
var
187187
gPackageJson: Table[string, JsonNode]
188-
proc readPackageList(name: string, options: Options): JsonNode =
188+
proc readPackageList(name: string, options: Options, ignorePackageCache = false): JsonNode =
189189
# If packages.json is not present ask the user if they want to download it.
190-
if gPackageJson.hasKey(name):
190+
if (not ignorePackageCache) and gPackageJson.hasKey(name):
191191
return gPackageJson[name]
192192

193193
if needsRefresh(options):
@@ -204,7 +204,7 @@ proc readPackageList(name: string, options: Options): JsonNode =
204204
name.toLowerAscii() & ".json")
205205
return gPackageJson[name]
206206

207-
proc getPackage*(pkg: string, options: Options, resPkg: var Package): bool
207+
proc getPackage*(pkg: string, options: Options, resPkg: var Package, ignorePackageCache = false): bool
208208
proc resolveAlias(pkg: Package, options: Options): Package =
209209
result = pkg
210210
# Resolve alias.
@@ -215,7 +215,7 @@ proc resolveAlias(pkg: Package, options: Options): Package =
215215
raise nimbleError("Alias for package not found: " &
216216
pkg.alias)
217217

218-
proc getPackage*(pkg: string, options: Options, resPkg: var Package): bool =
218+
proc getPackage*(pkg: string, options: Options, resPkg: var Package, ignorePackageCache = false): bool =
219219
## Searches any packages.json files defined in ``options.config.packageLists``
220220
## Saves the found package into ``resPkg``.
221221
##
@@ -226,7 +226,7 @@ proc getPackage*(pkg: string, options: Options, resPkg: var Package): bool =
226226
## Aliases are handled and resolved.
227227
for name, list in options.config.packageLists:
228228
display("Reading", "$1 package list" % name, priority = LowPriority)
229-
let packages = readPackageList(name, options)
229+
let packages = readPackageList(name, options, ignorePackageCache)
230230
for p in packages:
231231
if normalize(p["name"].str) == normalize(pkg):
232232
resPkg = p.fromJson()

tests/tissues.nim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,19 @@ suite "issues":
401401
else:
402402
"libissue941.so"
403403
check output.contains(expectedBinaryName)
404+
405+
test "issue #953 (Use refreshed package list)":
406+
# Remove all packages from the json file so it needs to be refreshed
407+
writeFile(installDir / "packages_official.json", "[]")
408+
removeDir(installDir / "pkgs2")
409+
410+
let (output, exitCode) = execNimble("install", "-y", "fusion")
411+
let lines = output.strip.processOutput()
412+
# Test that it needed to refresh packages and that it installed
413+
check:
414+
exitCode == QuitSuccess
415+
inLines(lines, "check internet for updated packages")
416+
inLines(lines, "fusion installed successfully")
417+
418+
# Clean up package file
419+
check execNimble(["refresh"]).exitCode == QuitSuccess

0 commit comments

Comments
 (0)