Repository navigation
Linux/macOS: tell an unreadable llama.cpp install apart from someone else's - #7771
Conversation
…else's setup.ps1 learned this in #7735 and #7757; setup.sh never did. A tree that is ours, carrying our own marker, reads as somebody else's the moment it stops being searchable, because every probe inside it reports the marker absent. The ownership guard then said the folder is not an Unsloth-owned install and told the user to move it aside or pick an empty UNSLOTH_STUDIO_HOME, when the actual fix is a permission change. Search (+x) is what those probes need, not read (+r): a directory can be readable and unsearchable (mode 444) or searchable and unreadable (mode 111), so the new probe tests search. The two destructive replaces also ran blind. Under errexit a failing rm -rf aborts on a raw permission error with no [TAURI:ERROR], so the desktop app shows a bare exit code and the freshly built llama.cpp is left in the temp directory with nothing saying where. Both sites now tolerate the failed remove, check that the directory is actually gone, and report either the permission problem or where the new build was left, exiting 3 as the Windows side does for a build that succeeded but could not be installed. Neither message tells the user to delete a folder Unsloth cannot prove is its own, matching the rule the Windows guard follows.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7a3290347d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # Without this the raw rm error aborts under errexit and the desktop | ||
| # app shows a bare exit code, with the fresh build silently stranded. | ||
| rm -rf "$LLAMA_CPP_DIR" 2>/dev/null || true | ||
| if [ -e "$LLAMA_CPP_DIR" ]; then |
There was a problem hiding this comment.
Treat surviving dangling symlinks as existing
When LLAMA_CPP_DIR is a dangling symlink from an earlier --with-llama-cpp-dir run and rm -rf cannot unlink it—for example, because the parent became non-writable during the build—[ -e "$LLAMA_CPP_DIR" ] is false even though the directory entry remains. The code consequently skips the new failure reporter and reaches mv, which aborts with the same raw error this change is intended to replace and does not tell the user where the completed build was left. Include a symlink check in this postcondition.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The -e/-L semantics are right, and I reproduced the shape: a dangling link with a non-writable parent gives -e: no -L: yes, skips the reporter, and mv aborts raw.
Rejecting on reachability. _BUILD_TMP="${LLAMA_CPP_DIR}.build.$$" is a sibling of the install dir and the source build clones into it, so the parent has to be writable when the build starts. Getting here needs it to become non-writable between the clone and the swap, which is a mid-build chmod or remount rather than input. In that state mv cannot write to the same parent either, so the run fails regardless and only the wording differs.
The link site cannot reach it at all: [ -L "$LLAMA_CPP_DIR" ] && rm -f runs first and aborts under errexit before the postcondition.
| if _studio_dir_unsearchable "$LLAMA_CPP_DIR"; then | ||
| _path_access_denied "$LLAMA_CPP_DIR" "llama.cpp install" |
There was a problem hiding this comment.
Preserve the stranded-build location in permission failures
When a source build succeeds but removal leaves an unsearchable install directory—for example, on an ACL- or mount-restricted default install—this call exits immediately through _path_access_denied with status 1. It therefore never reaches the status-3 failure below that reports $_BUILD_TMP, leaving the freshly completed build stranded without telling the user where it is despite that being the purpose of the new swap guard. Pass the build location through this permission failure or report it before exiting.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed the build does survive unnamed on that path, but the message is incomplete rather than wrong, and this is deliberate parity with the Windows side being ported. setup.ps1 does the same: the Denied branch calls Exit-PathAccessDenied and exits 1 without the build path, and only the non-denied branch reports the location. Diverging here would leave the two installers giving different answers to the same state.
Nothing regressed either: before this PR the same state aborted on a raw rm error with no location and no [TAURI:ERROR] at all.
The related point about losing the rm stderr was right, and that one is fixed.
| if _studio_dir_unsearchable "$LLAMA_CPP_DIR"; then | ||
| _path_access_denied "$LLAMA_CPP_DIR" "llama.cpp install" |
There was a problem hiding this comment.
Retain permission details for inaccessible descendants
When deletion fails because a populated child directory is unsearchable while the install root itself remains searchable—for example, llama.cpp/build has mode 000—this probe returns false because cd "$LLAMA_CPP_DIR" still succeeds. Since the preceding rm now discards stderr, setup suppresses the only Permission denied detail and reports only a generic link-replacement failure, so the user is no longer told that permissions are the cause or which subtree needs repair. Capture and inspect the removal error or probe the surviving descendants before selecting the generic failure.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, and it is a regression this PR introduced: before it, the raw rm error was the only thing the user saw, and it names the exact subpath. My generic message can only name the install root.
Dropping the stderr redirect and keeping || true gets both:
/bin/rm: cannot remove '.../llama.cpp/build': Permission denied
STEP|llama.cpp|built, but the existing install could not be replaced
FAIL exit=3 | ... could not be replaced. The new build is at .../llama.cpp.build.999.
Fixed at both replace sites, with an assertion that the redirect does not come back.
The redirect this PR added swallowed the one line that names which subtree refused to go. rm reports the deepest failing path, llama.cpp/build say, while the message below it can only name the install root, so a user whose build directory alone is locked lost the part that told them where to look. || true is what keeps errexit from aborting; the redirect was never doing that job, so stderr stays.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
setup.ps1learned to handle an unreadable llama.cpp install in #7735 and #7757.setup.shnever did, and it fails differently rather than better: POSIX probes return false instead of throwing, so the failure is a wrong answer rather than a crash.An install that is ours reads as somebody else's
_assert_studio_owned_or_absentdecides ownership by probing for.unsloth-studio-ownedinside the tree. A directory that cannot be searched reports every child absent, so a tree that IS ours, with our marker sitting in it, produces:Wrong cause and wrong remedy: nothing needs moving aside, the permissions need fixing. Driving the real function against the same directory before and after a
chmod 000shows it flip from accepted to rejected with no change to its contents. This is the same misdiagnosisGet-StudioAdoptableStatehad on Windows until #7757.Search (
+x) is the permission those probes need, not read (+r), and the two are independent:[ -f dir/marker ]( cd dir )ls -A dirA read probe would be wrong in both directions, so the new helper tests search.
Both destructive replaces ran blind
and the
--with-llama-cpp-direquivalent withln -sfn. Neither checked that the remove worked. Underset -euo pipefaila failingrm -rfaborts on a rawwith no
[TAURI:ERROR], so the desktop app shows a bare exit code with no reason, and a llama.cpp build that just succeeded is left in$_BUILD_TMPwith nothing saying where. That is the same user-visible symptom #7735 removed on Windows.Both sites now tolerate the failed remove, check the directory is actually gone, and report either the permission problem or where the new build was left. A build that succeeded but could not be installed exits 3, matching the Windows side;
setup.shalready uses that code.Neither new message tells the user to delete a folder Unsloth cannot prove is its own, which is the rule the Windows guard follows.
Tests
tests/sh/test_setup_sh_denied_install_tree.sh, 16 checks: static anchors for both guards, plus behaviour driven against a realchmod 000tree using the functions extracted fromsetup.shitself. It asserts a readable tree of ours is still accepted, an unowned readable tree still stops on ownership exactly as before, and an unreadable tree reports permissions without blaming ownership or advising deletion. It carries a negative control that skips rather than passing vacuously if the host cannot make a directory unsearchable.Each guard was mutation-tested and is load-bearing:
ls) instead of search (cd)Windows is untouched.
bash -nclean, and the shell suite runs 31 files with only the pre-existingtest_install_host_defaults.shfailure, which is unrelated and already quarantined intests/run_all.sh.