Skip to content

Commit a2e69d8

Browse files
committed
fix(yarn): Properly close the disk cache after resolution
Also open the disk cache lazily at runtime instead of the start of the application. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent db14717 commit a2e69d8

File tree

1 file changed

+8
-6
lines changed
  • plugins/package-managers/node/src/main/kotlin/yarn

1 file changed

+8
-6
lines changed

plugins/package-managers/node/src/main/kotlin/yarn/Yarn.kt

+8-6
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@ import org.ossreviewtoolkit.utils.ort.ortDataDirectory
6868
import org.semver4j.RangesList
6969
import org.semver4j.RangesListFactory
7070

71-
private val yarnInfoCache = DiskCache(
72-
directory = ortDataDirectory.resolve("cache/analyzer/yarn/info"),
73-
maxCacheSizeInBytes = 100.mebibytes,
74-
maxCacheEntryAgeInSeconds = 7.days.inWholeSeconds
75-
)
76-
7771
/** Name of the scope with the regular dependencies. */
7872
private const val DEPENDENCIES_SCOPE = "dependencies"
7973

@@ -102,6 +96,7 @@ open class Yarn(override val descriptor: PluginDescriptor = YarnFactory.descript
10296
override val globsForDefinitionFiles = listOf(NodePackageManagerType.DEFINITION_FILE)
10397

10498
private lateinit var stash: DirectoryStash
99+
private lateinit var yarnInfoCache: DiskCache
105100

106101
/** Cache for submodules identified by its moduleDir absolutePath */
107102
private val submodulesCache = ConcurrentHashMap<String, Set<File>>()
@@ -135,12 +130,19 @@ open class Yarn(override val descriptor: PluginDescriptor = YarnFactory.descript
135130
) {
136131
YarnCommand.checkVersion()
137132

133+
yarnInfoCache = DiskCache(
134+
directory = ortDataDirectory.resolve("cache/analyzer/yarn/info"),
135+
maxCacheSizeInBytes = 100.mebibytes,
136+
maxCacheEntryAgeInSeconds = 7.days.inWholeSeconds
137+
)
138+
138139
val directories = definitionFiles.mapTo(mutableSetOf()) { it.resolveSibling("node_modules") }
139140
stash = DirectoryStash(directories)
140141
}
141142

142143
override fun afterResolution(analysisRoot: File, definitionFiles: List<File>) {
143144
stash.close()
145+
yarnInfoCache.close()
144146
}
145147

146148
override fun resolveDependencies(

0 commit comments

Comments
 (0)