Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function stat ({ cache, hash, pkg, resolvedPath, isDir }, verify) {
if (isDir || path.basename(resolvedPath) === '.package-map.json') {
return Object.assign(fs.lstatSync(process.tink.cache), {
mode: 16676, // read-only
size: 64
})
}
if (!cache || !hash) {
throw new Error('stat() requires a fully-resolved pkgmap file address')
}
let info
try {
info = await ccRead.hasContent(cache, hash)
} catch (err) {
await repairPackage(cache, hash, pkg)
info = await ccRead.hasContent(cache, hash)
}
if (!info) {
return false
}
const cpath = ccPath(cache, info.sri)
if (verify) {
try {
await ssri.checkStream(
fs.createReadStream(cpath),
info.sri
)
} catch (err) {
const newResolved = await repairPackage({ cache, hash, pkg, resolvedPath })