Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Stop the denied llama.cpp cache recovery littering, and say what Windows allows (#11220)
Daniel Han9ace1ed4570d
diff --git a/install.ps1 b/install.ps1index f86c89dba0a..92074425c5f 100644--- a/install.ps1+++ b/install.ps1@@ -4037,10 +4037,26 @@ exit 1$asideDir = "$dir.denied-$(Get-Date -Format 'yyyyMMddHHmmss')"$moved = $falsetry {- Move-Item -LiteralPath $dir -Destination $asideDir -ErrorAction Stop+ # [System.IO.Directory]::Move, not Move-Item. Move-Item falls back to+ # copy-then-delete when the rename fails, which creates $asideDir and then+ # dies on the unreadable contents, leaving a stray llama.cpp.denied-* folder+ # beside the original on every run. Directory.Move is a bare rename: it+ # either moves the tree or throws having created nothing.+ # Measured on windows-latest, denying each shape on the folder itself:+ # (OI)(CI)(RX) rename refused, Move-Item left a stray folder+ # (OI)(CI)(R) rename refused, Move-Item left a stray folder+ # (RX) rename refused, Move-Item left a stray folder+ # (DE) rename SUCCEEDED, both ways+ # So on Windows a read denial always refuses the rename (the open asks for+ # SYNCHRONIZE, which every read deny removes) and this recovery cannot fire;+ # denying DELETE, which sounds like the blocker, does not stop it. On POSIX+ # the rename needs only write+execute on the parent, so the recovery is real+ # there and is why this stays rather than being deleted.+ [System.IO.Directory]::Move($dir, $asideDir)$moved = $true} catch {- # Expected when the denial also covers rename; fall through to guidance.+ # Expected when the denial covers the rename; fall through to guidance.+ # Nothing to clean up: Directory.Move creates nothing when it throws.}if ($moved) {step "permissions" "llama.cpp install at $dir could not be read, so it was moved aside" "Yellow"diff --git a/studio/setup.ps1 b/studio/setup.ps1index f1fe3e4fef8..0055030e1fc 100644--- a/studio/setup.ps1+++ b/studio/setup.ps1@@ -783,10 +783,26 @@ function Invoke-ManagedLlamaCppPreflight {$asideDir = "$dir.denied-$(Get-Date -Format 'yyyyMMddHHmmss')"$moved = $falsetry {- Move-Item -LiteralPath $dir -Destination $asideDir -ErrorAction Stop+ # [System.IO.Directory]::Move, not Move-Item. Move-Item falls back to+ # copy-then-delete when the rename fails, which creates $asideDir and then+ # dies on the unreadable contents, leaving a stray llama.cpp.denied-* folder+ # beside the original on every run. Directory.Move is a bare rename: it+ # either moves the tree or throws having created nothing.+ # Measured on windows-latest, denying each shape on the folder itself:+ # (OI)(CI)(RX) rename refused, Move-Item left a stray folder+ # (OI)(CI)(R) rename refused, Move-Item left a stray folder+ # (RX) rename refused, Move-Item left a stray folder+ # (DE) rename SUCCEEDED, both ways+ # So on Windows a read denial always refuses the rename (the open asks for+ # SYNCHRONIZE, which every read deny removes) and this recovery cannot fire;+ # denying DELETE, which sounds like the blocker, does not stop it. On POSIX+ # the rename needs only write+execute on the parent, so the recovery is real+ # there and is why this stays rather than being deleted.+ [System.IO.Directory]::Move($dir, $asideDir)$moved = $true} catch {- # Expected when the denial also covers rename; fall through to guidance.+ # Expected when the denial covers the rename; fall through to guidance.+ # Nothing to clean up: Directory.Move creates nothing when it throws.}if ($moved) {step "permissions" "llama.cpp install at $dir could not be read, so it was moved aside" "Yellow"diff --git a/tests/studio/install/test_denied_llama_cpp_preflight.py b/tests/studio/install/test_denied_llama_cpp_preflight.pyindex 9bb3d2ec0ab..0d3769c1c42 100644--- a/tests/studio/install/test_denied_llama_cpp_preflight.py+++ b/tests/studio/install/test_denied_llama_cpp_preflight.py@@ -388,12 +388,23 @@ def test_the_security_software_holding_the_folder_is_named() -> None:def test_a_denied_cache_is_moved_aside_only_when_it_is_ours_to_move() -> None:- """Renaming needs DELETE on the folder plus write on its parent, neither of- which is read access, so it recovers denials takeown and icacls do not. It is- only allowed for the tree the guidance already tells the user to delete."""+ """The move is a bare rename, and only for the tree the guidance tells the user to delete.++ Directory.Move rather than Move-Item, which is not a style choice. Move-Item falls back+ to copy-then-delete when the rename is refused: it creates the aside folder, then dies on+ the unreadable contents, leaving a stray llama.cpp.denied-* beside the original on every+ run. Measured on windows-latest, denying each shape on the folder itself, every read+ denial ((OI)(CI)(RX), (OI)(CI)(R), (RX)) refuses the rename while (DE) alone does not, so+ on Windows this recovery cannot fire and must at least leave nothing behind. On POSIX the+ rename needs only write and execute on the parent, so it recovers there.+ """for text in (INSTALL_PS1, SETUP_PS1):body = _function_source(text, "Invoke-ManagedLlamaCppPreflight")- assert "Move-Item -LiteralPath $dir -Destination $asideDir" in body+ assert "[System.IO.Directory]::Move($dir, $asideDir)" in body+ # The fallback that litters must not come back, by any route. Code only: the+ # comment above the call names Move-Item to say why it is not used.+ code = "\n".join(line.split("#", 1)[0] for line in body.splitlines())+ assert "Move-Item" not in codeguard = "if (-not $userSupplied -and -not $homeIsCustom -and -not $isLink) {"assert guard in body# Setup never makes this a link, so a link is the user's own arrangementdiff --git a/tests/studio/test_path_probe_access_denied.ps1 b/tests/studio/test_path_probe_access_denied.ps1index 55a9363a420..9f49add2d76 100644--- a/tests/studio/test_path_probe_access_denied.ps1+++ b/tests/studio/test_path_probe_access_denied.ps1@@ -494,9 +494,11 @@ if (`$args[2] -eq "env") { `$env:UNSLOTH_LOCAL_LLAMA_CPP_DIR = `$dir }# A build supplied from inside the managed tree goes with it when the tree is# moved or deleted, so the tree is not ours to touch either.if (`$args[2] -eq "nested") { `$env:UNSLOTH_LOCAL_LLAMA_CPP_DIR = Join-Path `$dir "custom" }-# Renaming needs DELETE on the folder plus write on its parent. Taking either-# away is the denial that the move cannot recover, and the one the guidance is-# still written for.+# On POSIX, renaming needs write and execute on the PARENT, so taking write off the+# parent is the denial the move cannot recover. On Windows the read deny applied to+# every mode already refuses the rename, and denying DELETE alone does not (measured),+# so this mode is the same as the one above there -- which is why the checks that read+# it are written per platform.if (`$args[2] -eq "unmovable") {if (`$onWindows) { icacls `$dir /deny "`$env:USERDOMAIN\`${env:USERNAME}:(DE)" *>`$null }else { chmod 500 (Split-Path -Parent `$dir) }@@ -565,13 +567,30 @@ else { chmod 755 `$dir 2>`$null }if ($out -notmatch "CAN_DENY: True") {Write-Host " SKIP cannot deny access on this host (running as root/admin?) -- preflight denial checks skipped" -ForegroundColor Yellow} else {- # A cache we own and can still rename is recovered rather than reported:- # renaming needs DELETE plus write on the parent, and neither is read- # access, so this clears denials takeown and icacls cannot.- Check "a denied cache that can be renamed is moved aside, not reported" (- $out -match "DENIED_VERDICT: continue")- Check "the moved cache leaves the original path free for the reinstall" (- $out -match "ASIDE_COUNT: 1" -and $out -match "ORIGINAL_EXISTS: False")+ # A cache we own and can still rename is recovered rather than reported.+ # Whether it CAN be renamed is not the same question on both platforms, and+ # the answer was measured rather than reasoned about (windows-latest, denying+ # each shape on the folder itself, then renaming it):+ #+ # (OI)(CI)(RX) refused (OI)(CI)(R) refused (RX) refused (DE) SUCCEEDED+ #+ # So on Windows every read denial refuses the rename -- the open asks for+ # SYNCHRONIZE and any read deny removes it -- and denying DELETE, which sounds+ # like the blocker, does not stop it. The recovery therefore cannot fire on+ # Windows for the denial this harness creates, and asserting that it does was+ # asserting something the platform does not allow. On POSIX the rename needs+ # only write and execute on the parent, so the recovery is real there.+ if ($onWindows) {+ Check "a denied cache that cannot be renamed is reported, not moved aside" (+ $out -match "DENIED_VERDICT: stop")+ Check "the refused rename leaves nothing behind beside the original" (+ $out -match "ASIDE_COUNT: 0" -and $out -match "ORIGINAL_EXISTS: True")+ } else {+ Check "a denied cache that can be renamed is moved aside, not reported" (+ $out -match "DENIED_VERDICT: continue")+ Check "the moved cache leaves the original path free for the reinstall" (+ $out -match "ASIDE_COUNT: 1" -and $out -match "ORIGINAL_EXISTS: False")+ }# Everything below is the tree the move cannot rescue, which is what the# guidance was always written for.