MCPcopy Index your code
hub / github.com/codeaashu/claude-code / saveInstallCountsCache

Function saveInstallCountsCache

src/utils/plugins/installCounts.ts:149–179  ·  view source on GitHub ↗

* Save the install counts cache to disk atomically. * Uses a temp file + rename pattern to prevent corruption.

(
  cache: InstallCountsCache,
)

Source from the content-addressed store, hash-verified

147 * Uses a temp file + rename pattern to prevent corruption.
148 */
149async function saveInstallCountsCache(
150 cache: InstallCountsCache,
151): Promise<void> {
152 const cachePath = getInstallCountsCachePath()
153 const tempPath = `${cachePath}.${randomBytes(8).toString('hex')}.tmp`
154
155 try {
156 // Ensure the plugins directory exists
157 const pluginsDir = getPluginsDirectory()
158 await getFsImplementation().mkdir(pluginsDir)
159
160 // Write to temp file
161 const content = jsonStringify(cache, null, 2)
162 await writeFile(tempPath, content, {
163 encoding: 'utf-8',
164 mode: 0o600,
165 })
166
167 // Atomic rename
168 await rename(tempPath, cachePath)
169 logForDebugging('Install counts cache saved successfully')
170 } catch (error) {
171 logError(error)
172 // Clean up temp file if it exists
173 try {
174 await unlink(tempPath)
175 } catch {
176 // Ignore cleanup errors
177 }
178 }
179}
180
181/**
182 * Fetch install counts from GitHub stats repository

Callers 1

getInstallCountsFunction · 0.85

Calls 9

getPluginsDirectoryFunction · 0.85
getFsImplementationFunction · 0.85
jsonStringifyFunction · 0.85
renameFunction · 0.85
logForDebuggingFunction · 0.85
unlinkFunction · 0.85
toStringMethod · 0.65
logErrorFunction · 0.50

Tested by

no test coverage detected