MCPcopy Create free account
hub / github.com/isomorphic-git/isomorphic-git / checkAndWriteBlob

Function checkAndWriteBlob

src/utils/walkerToTreeEntryMap.js:31–58  ·  view source on GitHub ↗
(fs, gitdir, dir, filepath, oid = null)

Source from the content-addressed store, hash-verified

29
30// make sure filepath, blob type and blob object (from loose objects) plus oid are in sync and valid
31async function checkAndWriteBlob(fs, gitdir, dir, filepath, oid = null) {
32 const currentFilepath = join(dir, filepath)
33 const stats = await fs.lstat(currentFilepath)
34 if (!stats) throw new NotFoundError(currentFilepath)
35 if (stats.isDirectory())
36 throw new InternalError(
37 `${currentFilepath}: file expected, but found directory`
38 )
39
40 // Look for it in the loose object directory.
41 const objContent = oid
42 ? await readObjectLoose({ fs, gitdir, oid })
43 : undefined
44 let retOid = objContent ? oid : undefined
45 if (!objContent) {
46 await acquireLock({ fs, gitdir, currentFilepath }, async () => {
47 const object = stats.isSymbolicLink()
48 ? await fs.readlink(currentFilepath).then(posixifyPathBuffer)
49 : await fs.read(currentFilepath)
50
51 if (object === null) throw new NotFoundError(currentFilepath)
52
53 retOid = await _writeObject({ fs, gitdir, type: 'blob', object })
54 })
55 }
56
57 return retOid
58}
59
60async function processTreeEntries({ fs, dir, gitdir, entries }) {
61 // make sure each tree entry has valid oid

Callers 1

processTreeEntryFunction · 0.85

Calls 7

joinFunction · 0.90
readObjectLooseFunction · 0.90
_writeObjectFunction · 0.90
lstatMethod · 0.80
readlinkMethod · 0.80
acquireLockFunction · 0.70
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…