MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / findExistingInstall

Function findExistingInstall

apps/desktop/src/main/cli-install.ts:236–263  ·  view source on GitHub ↗
(
  wrapper: WrapperLocation | null
)

Source from the content-addressed store, hash-verified

234}
235
236async function findExistingInstall(
237 wrapper: WrapperLocation | null
238): Promise<ExistingInstall | null> {
239 for (const dir of candidateDirs()) {
240 const candidate = path.join(dir, CLI_NAME)
241 try {
242 const linkTarget = await fsp.readlink(candidate)
243 const resolved = path.isAbsolute(linkTarget)
244 ? linkTarget
245 : path.resolve(dir, linkTarget)
246 const byUs = wrapper ? sameFile(resolved, wrapper.wrapperPath) : looksLikeOurInstall(resolved)
247 return { linkPath: candidate, installedByThisApp: byUs }
248 } catch (err) {
249 if ((err as NodeJS.ErrnoException).code === 'EINVAL') {
250 // Real file, not a symlink. Treat as a foreign install we
251 // refuse to manage.
252 try {
253 await fsp.access(candidate)
254 return { linkPath: candidate, installedByThisApp: false }
255 } catch {
256 /* fall through */
257 }
258 }
259 // ENOENT or permission errors — keep searching.
260 }
261 }
262 return null
263}
264
265function sameFile(a: string, b: string): boolean {
266 try {

Callers 3

getCliInstallStatusFunction · 0.85
installCliFunction · 0.85
uninstallCliFunction · 0.85

Calls 3

candidateDirsFunction · 0.85
sameFileFunction · 0.85
looksLikeOurInstallFunction · 0.85

Tested by

no test coverage detected