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

Function checkMcpbChanged

src/utils/plugins/mcpbHandler.ts:622–686  ·  view source on GitHub ↗
(
  source: string,
  pluginPath: string,
)

Source from the content-addressed store, hash-verified

620 * Check if an MCPB source has changed and needs re-extraction
621 */
622export async function checkMcpbChanged(
623 source: string,
624 pluginPath: string,
625): Promise<boolean> {
626 const fs = getFsImplementation()
627 const cacheDir = getMcpbCacheDir(pluginPath)
628 const metadata = await loadCacheMetadata(cacheDir, source)
629
630 if (!metadata) {
631 // No cache metadata, needs loading
632 return true
633 }
634
635 // Check if extraction directory still exists
636 try {
637 await fs.stat(metadata.extractedPath)
638 } catch (error) {
639 const code = getErrnoCode(error)
640 if (code === 'ENOENT') {
641 logForDebugging(`MCPB extraction path missing: ${metadata.extractedPath}`)
642 } else {
643 logForDebugging(
644 `MCPB extraction path inaccessible: ${metadata.extractedPath}: ${error}`,
645 { level: 'error' },
646 )
647 }
648 return true
649 }
650
651 // For local files, check mtime
652 if (!isUrl(source)) {
653 const localPath = join(pluginPath, source)
654 let stats
655 try {
656 stats = await fs.stat(localPath)
657 } catch (error) {
658 const code = getErrnoCode(error)
659 if (code === 'ENOENT') {
660 logForDebugging(`MCPB source file missing: ${localPath}`)
661 } else {
662 logForDebugging(
663 `MCPB source file inaccessible: ${localPath}: ${error}`,
664 { level: 'error' },
665 )
666 }
667 return true
668 }
669
670 const cachedTime = new Date(metadata.cachedAt).getTime()
671 // Floor to match the ms precision of cachedAt (ISO string). Sub-ms
672 // precision on mtimeMs would make a freshly-cached file appear "newer"
673 // than its own cache timestamp when both happen in the same millisecond.
674 const fileTime = Math.floor(stats.mtimeMs)
675
676 if (fileTime > cachedTime) {
677 logForDebugging(
678 `MCPB file modified: ${new Date(fileTime)} > ${new Date(cachedTime)}`,
679 )

Callers 1

loadMcpbFileFunction · 0.85

Calls 6

getFsImplementationFunction · 0.85
getMcpbCacheDirFunction · 0.85
loadCacheMetadataFunction · 0.85
getErrnoCodeFunction · 0.85
logForDebuggingFunction · 0.85
isUrlFunction · 0.85

Tested by

no test coverage detected