Skip to content

Commit 434e96a

Browse files
authored
Fixes pkgcache (#1306)
* changes the approach of pkgcache: instead of modifying the pkgDir it creates a copy so its guaranteed the state is preserved * typo
1 parent b12b18a commit 434e96a

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

src/nimblepkg/nimblesat.nim

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -527,50 +527,52 @@ proc saveTaggedVersions*(repoDir, pkgName: string, taggedVersions: TaggedPackage
527527
displayWarning(&"Error saving tagged versions: {e.msg}", HighPriority)
528528

529529
proc getPackageMinimalVersionsFromRepo*(repoDir: string, name: string, version: Version, downloadMethod: DownloadMethod, options: Options): seq[PackageMinimalInfo] =
530-
#This is expensive. We need to cache it. Potentially it could be also run in parallel
531-
# echo &"Discovering version for {pkgName}"
532-
gitFetchTags(repoDir, downloadMethod)
533-
let tags = getTagsList(repoDir, downloadMethod).getVersionList()
534-
template checkoutCurrentVersion() =
535-
if version.isSpecial:
536-
var specialVersion = substr($version, 1)
537-
if specialVersion == "head":
538-
specialVersion = "HEAD"
539-
doCheckout(downloadMethod, repoDir, specialVersion)
540-
else:
541-
for (ver, tag) in tags.pairs:
542-
if ver == version:
543-
doCheckout(downloadMethod, repoDir, tag)
544-
545530
result = newSeq[PackageMinimalInfo]()
546-
checkoutCurrentVersion()
531+
547532
let taggedVersions = getTaggedVersions(repoDir, name, options)
548533
if taggedVersions.isSome:
549534
return taggedVersions.get.versions
550535

551-
#First package must be the current one
536+
let tempDir = repoDir & "_versions"
552537
try:
553-
result.add getPkgInfo(repoDir, options).getMinimalInfo(options)
554-
except CatchableError as e:
555-
displayWarning(&"Error getting package info for {name}: {e.msg}", HighPriority)
556-
var checkedTags = 0
557-
for (ver, tag) in tags.pairs:
558-
if options.maxTaggedVersions > 0 and checkedTags >= options.maxTaggedVersions:
559-
# echo &"Tag limit reached for {pkgName}"
560-
break
561-
inc checkedTags
562-
#For each version, we need to parse the requires so we need to checkout and initialize the repo
538+
removeDir(tempDir)
539+
copyDir(repoDir, tempDir)
540+
541+
gitFetchTags(tempDir, downloadMethod)
542+
let tags = getTagsList(tempDir, downloadMethod).getVersionList()
543+
563544
try:
564-
doCheckout(downloadMethod, repoDir, tag)
565-
let nimbleFile = findNimbleFile(repoDir, true, options)
566-
let pkgInfo = getPkgInfoFromFile(nimbleFile, options, useCache=false)
567-
result.addUnique pkgInfo.getMinimalInfo(options)
545+
result.add getPkgInfo(repoDir, options).getMinimalInfo(options)
568546
except CatchableError as e:
569-
displayWarning(&"Error reading tag {tag}: for package {name}. This may not be relevant as it could be an old version of the package. \n {e.msg}", HighPriority)
547+
displayWarning(&"Error getting package info for {name}: {e.msg}", HighPriority)
548+
549+
# Process tagged versions in the temporary copy
550+
var checkedTags = 0
551+
for (ver, tag) in tags.pairs:
552+
if options.maxTaggedVersions > 0 and checkedTags >= options.maxTaggedVersions:
553+
break
554+
inc checkedTags
555+
556+
try:
557+
doCheckout(downloadMethod, tempDir, tag)
558+
let nimbleFile = findNimbleFile(tempDir, true, options)
559+
let pkgInfo = getPkgInfoFromFile(nimbleFile, options, useCache=false)
560+
result.addUnique pkgInfo.getMinimalInfo(options)
561+
except CatchableError as e:
562+
displayWarning(
563+
&"Error reading tag {tag}: for package {name}. This may not be relevant as it could be an old version of the package. \n {e.msg}",
564+
HighPriority)
570565

571-
checkoutCurrentVersion()
572-
573-
saveTaggedVersions(repoDir, name, TaggedPackageVersions(maxTaggedVersions: options.maxTaggedVersions, versions: result), options)
566+
saveTaggedVersions(repoDir, name,
567+
TaggedPackageVersions(
568+
maxTaggedVersions: options.maxTaggedVersions,
569+
versions: result
570+
), options)
571+
finally:
572+
try:
573+
removeDir(tempDir)
574+
except CatchableError as e:
575+
displayWarning(&"Error cleaning up temporary directory {tempDir}: {e.msg}", LowPriority)
574576

575577
proc downloadMinimalPackage*(pv: PkgTuple, options: Options): seq[PackageMinimalInfo] =
576578
if pv.name == "": return newSeq[PackageMinimalInfo]()

0 commit comments

Comments
 (0)