Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove js_image_layer bazel5 legacy symlink detection #1610

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 2 additions & 48 deletions js/private/image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ function findKeyByValue(entries: Entries, value: string): string | undefined {
return undefined
}

function leftStrip(p: string, p1: string, p2: string) {
if (p.startsWith(p1)) {
return p.slice(p1.length)
} else if (p.startsWith(p2)) {
return p.slice(p2.length)
}
return p
}

async function readlinkSafe(p: string) {
try {
const link = await readlink(p)
Expand All @@ -64,37 +55,6 @@ async function readlinkSafe(p: string) {
}
}

// TODO: drop once we no longer support bazel 5
async function resolveSymlinkLegacy(relativeP: string) {
let prevHop = path.resolve(relativeP)
let hopped = false
let execrootOutOfSandbox = ''
let execroot = process.env.JS_BINARY__EXECROOT!
while (true) {
let nextHop = await readlinkSafe(prevHop)

if (!execrootOutOfSandbox && !nextHop.startsWith(execroot)) {
execrootOutOfSandbox = nextHop
.replace(relativeP, '')
.replace(/\/$/, '')
prevHop = nextHop
continue
}

let relativeNextHop = leftStrip(nextHop, execroot, execrootOutOfSandbox)
let relativePrevHop = leftStrip(prevHop, execroot, execrootOutOfSandbox)

if (relativeNextHop != relativePrevHop) {
prevHop = nextHop
hopped = true
} else if (!hopped) {
return undefined
} else {
return nextHop
}
}
}

async function resolveSymlink(p: string) {
let prevHop = path.resolve(p)
let hopped = false
Expand Down Expand Up @@ -254,11 +214,7 @@ export async function build(
outputPath: string,
compression: Compression,
owner: Owner,
useLegacySymlinkDetection: boolean
) {
const resolveSymlinkFn = useLegacySymlinkDetection
? resolveSymlinkLegacy
: resolveSymlink
const output = pack()
const existing_paths = new Set<string>()

Expand Down Expand Up @@ -325,7 +281,7 @@ export async function build(
)
}

const realp = await resolveSymlinkFn(dest)
const realp = await resolveSymlink(dest)

// it's important that we don't treat any symlink pointing out of execroot since
// bazel symlinks external files into sandbox to make them available to us.
Expand Down Expand Up @@ -392,7 +348,6 @@ if (import.meta.url === pathToFileURL(process.argv[1]).href) {
outputPath,
compression,
owner,
useLegacySymlinkDetection,
] = process.argv.slice(2)
const raw_entries = await readFile(entriesPath)
const entries: Entries = JSON.parse(raw_entries.toString())
Expand All @@ -401,7 +356,6 @@ if (import.meta.url === pathToFileURL(process.argv[1]).href) {
entries,
outputPath,
compression as Compression,
{ uid, gid } as Owner,
!!useLegacySymlinkDetection
{ uid, gid } as Owner
)
}
3 changes: 0 additions & 3 deletions js/private/js_image_layer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ js_image_layer(
"""

load("@aspect_bazel_lib//lib:paths.bzl", "to_rlocation_path")
load("@aspect_bazel_lib//lib:utils.bzl", bazel_lib_utils = "utils")
load("@bazel_skylib//lib:paths.bzl", "paths")

_DOC = """Create container image layers from js_binary targets.
Expand Down Expand Up @@ -217,8 +216,6 @@ def _build_layer(ctx, type, entries, inputs):
args.add(output)
args.add(ctx.attr.compression)
args.add(ctx.attr.owner)
if not bazel_lib_utils.is_bazel_6_or_greater():
args.add("true")

ctx.actions.run(
inputs = inputs + [entries_output],
Expand Down
51 changes: 5 additions & 46 deletions js/private/js_image_layer.mjs

Large diffs are not rendered by default.

Loading