Skip to content

Commit

Permalink
Don't deploy file in ldconf dir
Browse files Browse the repository at this point in the history
  • Loading branch information
impactaky committed Jan 20, 2024
1 parent bd30b7d commit d955901
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
15 changes: 14 additions & 1 deletion mimic-cross.deno/src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import $ from "daxex/mod.ts";
import { PathRefLike } from "daxex/mod.ts";
import { config } from "config/config.ts";
import { logger } from "./log.ts";
import { isElfExecutable } from "./util.ts";
import { isElfExecutable, isInPath, parseLdconf } from "./util.ts";

export async function keepOriginalBin(path: PathRefLike) {
const pathRef = $.path(path);
Expand Down Expand Up @@ -66,10 +66,23 @@ export async function deployIfHostCommands(
commands: string[],
blockList?: Set<string>,
) {
const libDirs = await parseLdconf(`${config.hostRoot}/etc/ld.so.conf`);
for (const command of commands) {
const hostPath = $.path(`${config.hostRoot}/${command}`);
if (blockList && blockList.has(command)) continue;
if (!(await isElfExecutable(hostPath))) continue;
if (isInPath(command, libDirs)) continue;
if (!isInPath(command)) {
logger.info(`(deployIfHostCommands) ${command} is not in PATH`);
}
await mimicDeploy(hostPath, command);
}
}

// export async function generateRecipe(commands: string[]) {
// for (const command of commands) {
// const hostPath = $.path(`${config.hostRoot}/${command}`);
// if (!(await isElfExecutable(hostPath))) continue;
// await mimicDeploy(hostPath, command);
// }
// }
7 changes: 6 additions & 1 deletion mimic-cross.deno/src/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import $ from "daxex/mod.ts";
import { assert, assertEquals } from "std/assert/mod.ts";
import { isElfExecutable, parseLdconf } from "./util.ts";
import { isElfExecutable, isInPath, parseLdconf } from "./util.ts";
import { config } from "../config/config.ts";

Deno.test("isElfExecutable native", async () => {
Expand All @@ -18,6 +18,11 @@ Deno.test("isElfExecutable(directory)", async () => {
assert(!ret);
});

Deno.test("isInPath", () => {
assert(!isInPath("/foo/var/cli", ["/foo"]));
assert(isInPath("/foo/var/cli", ["/foo/var"]));
});

Deno.test("parse /etc/ld.so.conf", async () => {
const dirs = await parseLdconf("/etc/ld.so.conf");
assertEquals(dirs, [
Expand Down
2 changes: 1 addition & 1 deletion mimic-cross.deno/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function isElfExecutable(path: PathRefLike): Promise<boolean> {
return false;
}

export function isInPATH(filePath: PathRefLike, paths?: string[]) {
export function isInPath(filePath: PathRefLike, paths?: string[]) {
filePath = $.path(filePath);
paths = paths ? paths : Deno.env.get("PATH")?.split(":");
if (!paths) return false;
Expand Down

0 comments on commit d955901

Please sign in to comment.