Skip to content

Commit

Permalink
search now simply returns without yielding if path doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
toebeann committed Aug 28, 2024
1 parent 564049d commit b1f01d2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/utils/unity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readFile, stat } from "node:fs/promises";
import { basename, dirname, extname, join, normalize, sep } from "node:path";
import { exists } from "../fs/exists.ts";
import { booleanRace } from "./booleanRace.ts";
import {
getValue,
Expand All @@ -19,16 +20,23 @@ export const search = async function* (
) {
const parts = normalize(path).split(sep);
const index = parts.lastIndexOf("Contents");
const isDir = stat(path).then((stats) => stats.isDirectory());
const pathExists = exists(path);
const isDir = pathExists
.then((exists) => exists && stat(path).then((stats) => stats.isDirectory()))
.catch(() => false);
const searchDir =
(extname(path) === ".app" || basename(path) === "Contents") && await isDir
? path
: index >= 0
? parts.slice(0, index + 1).join(sep)
: !await pathExists
? undefined
: await isDir
? path
: dirname(path);

if (!searchDir) return;

for await (const path of searchPlists(searchDir)) {
if (await hasUnityAppIndicators(path, indicators)) {
const plist = await readPlist(path);
Expand Down

0 comments on commit b1f01d2

Please sign in to comment.