mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
Allow macOS installer cleanup despite unrelated mount warnings (#62582)
## Why On macOS, `lsof` can warn about inaccessible mounts even when its search is scoped to the releases directory. Treating every warning as an inspection failure can prevent the installer from pruning unused releases. ## What changed Keep `lsof` matches when stderr contains only complete mount warnings for paths outside the releases tree and its ancestors, on devices different from the releases directory. Continue to reject warnings that could affect release inspection, incomplete warnings, and unexpected errors. ## Testing Extend the mocked macOS `lsof` test to verify that an unrelated mount warning preserves matches and that same-device, ancestor-mount, truncated, and mixed diagnostics fail inspection. GitOrigin-RevId: 006e2a38335c33ce7c974f74d3bb871d818fdd1f
This commit is contained in:
@@ -813,7 +813,31 @@ record_standalone_releases_in_use() {
|
||||
# Keep those matches, but reject other failures and any stderr below.
|
||||
[ "$?" -eq 1 ] || return 1
|
||||
fi
|
||||
[ ! -s "$tmp_dir/lsof-error" ] || return 1
|
||||
if [ -s "$tmp_dir/lsof-error" ]; then
|
||||
# lsof inspects every mount even with +D. An inaccessible, unrelated
|
||||
# filesystem cannot hide files on the releases device; reject all other
|
||||
# warnings, including any failure to inspect the releases mount itself.
|
||||
device="$(stat -c '%d' "$releases" 2>/dev/null || stat -f '%d' "$releases")" || return 1
|
||||
device="$(printf '%x' "$device")" || return 1
|
||||
LC_ALL=C RELEASES="$releases" RELEASE_DEVICE="$device" awk '
|
||||
NR % 3 == 1 {
|
||||
if ($0 !~ /^lsof: WARNING: can\047t stat\(\) [^[:space:]]+ file system \//) exit 1
|
||||
mount = $0; sub(/^lsof: WARNING: can\047t stat\(\) [^[:space:]]+ file system /, "", mount)
|
||||
releases = ENVIRON["RELEASES"]
|
||||
if (mount == "/" || index(releases "/", mount "/") == 1 ||
|
||||
index(mount "/", releases "/") == 1) exit 1
|
||||
next
|
||||
}
|
||||
NR % 3 == 2 { if ($0 != " Output information may be incomplete.") exit 1; next }
|
||||
{
|
||||
if ($0 !~ /^ assuming "dev=[0-9a-fA-F]+" from mount table$/) exit 1
|
||||
dev = $0; sub(/^.*dev=/, "", dev); sub(/".*$/, "", dev)
|
||||
dev = tolower(dev); sub(/^0+/, "", dev)
|
||||
if (dev == ENVIRON["RELEASE_DEVICE"] || dev == "") exit 1
|
||||
}
|
||||
END { if (NR % 3 != 0) exit 1 }
|
||||
' "$tmp_dir/lsof-error" || return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -390,10 +390,32 @@ class InstallShTest(unittest.TestCase):
|
||||
function = "record_standalone_releases_in_use() {" + function + "\n}\n"
|
||||
function = function.replace("/usr/sbin/lsof ", "mock_lsof ")
|
||||
matches = "p123\nn/releases/active/bin/codex\n"
|
||||
device = os.stat(tempfile.gettempdir()).st_dev
|
||||
warning = (
|
||||
"lsof: WARNING: can't stat() hfs file system {mount}\n"
|
||||
" Output information may be incomplete.\n"
|
||||
' assuming "dev={device}" from mount table\n'
|
||||
)
|
||||
unrelated = warning.format(mount="/Volumes/unrelated", device=f"{device + 1:x}")
|
||||
for status, output, error, expected in (
|
||||
(0, matches, "", 0),
|
||||
(1, "", "", 0),
|
||||
(1, matches, "", 0),
|
||||
(1, matches, unrelated, 0),
|
||||
(
|
||||
1,
|
||||
matches,
|
||||
warning.format(mount="/Volumes/unrelated", device=f"00{device:X}"),
|
||||
1,
|
||||
),
|
||||
(
|
||||
1,
|
||||
matches,
|
||||
warning.format(mount=tempfile.gettempdir(), device=f"{device + 1:x}"),
|
||||
1,
|
||||
),
|
||||
(1, matches, unrelated.rsplit("\n", 2)[0] + "\n", 1),
|
||||
(1, matches, unrelated + "inspection failed\n", 1),
|
||||
(0, matches, "inspection failed\n", 1),
|
||||
(1, matches, "inspection failed\n", 1),
|
||||
(2, "", "", 1),
|
||||
@@ -404,7 +426,7 @@ class InstallShTest(unittest.TestCase):
|
||||
script = (
|
||||
"set -eu\n"
|
||||
"os=macos\n"
|
||||
"releases=/releases\n"
|
||||
f"releases={shlex.quote(temp_dir)}\n"
|
||||
f"tmp_dir={shlex.quote(temp_dir)}\n"
|
||||
# Avoid depending on other processes on the test host.
|
||||
'ps() { printf "%s codex\\n" "$(id -u)"; }\n'
|
||||
|
||||
Reference in New Issue
Block a user