Skip to content

Windows installer fails when $env:TEMP uses an 8.3 short path #838

Description

@coordx3906

Description

The Windows installer aborts while cleaning up its temporary directory when $env:TEMP points to an 8.3 short path.

My Windows user profile directory contains a space:

C:\Users\David X

In the affected PowerShell session, the temporary directory resolves through the corresponding short path:

C:\Users\DAVIDX~1\...

The prebuilt binary downloads and passes SHA-256 verification successfully, but the installer then fails at the Remove-Item call in its finally block.

This is the normal prebuilt installation path. I did not use -BuildFromSource.

Steps to reproduce

Run the standard installer in the affected environment:

irm https://jcode.sh/install.ps1 | iex

Output:

PS C:\Users\David X> irm https://jcode.sh/install.ps1 | iex
Fetching latest release...
Installing jcode v0.68.0
  launcher: C:\Users\David X\AppData\Local\jcode\bin\jcode.exe
Downloading jcode-windows-x86_64.exe from https://github.com/1jehuang/jcode/releases/download/v0.68.0...
Verified SHA256: jcode-windows-x86_64.exe
Remove-Item:
Line |
1094 |      Remove-Item -Path $TempDir -Recurse -Force -ErrorAction SilentlyC …
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | An object at the specified path C:\Users\DAVIDX~1 does not exist.

Expected behavior

The installer should complete successfully even when $env:TEMP uses an 8.3 short path.

A failure to clean up the temporary directory should also not abort an otherwise successful installation or prevent subsequent steps such as updating the user PATH.

Cause

The installer creates its temporary directory from $env:TEMP:

$TempDir = Join-Path $env:TEMP "jcode-install-$(Get-Random)"
New-Item -ItemType Directory -Path $TempDir -Force | Out-Null

It later removes that directory directly by path:

finally {
    Remove-Item -Path $TempDir -Recurse -Force -ErrorAction SilentlyContinue
}

PowerShell has an existing FileSystemProvider bug where Remove-Item -Path can fail to normalize paths under $env:TEMP when an 8.3 short path is involved:

PowerShell/PowerShell#21070

The upstream issue produces essentially the same error:

An object at the specified path C:\Users\XXXXXX~1 does not exist.

Confirmed workaround

Overriding TEMP and TMP with the long path in the current PowerShell process allows the installation to complete successfully:

$oldTemp = $env:TEMP
$oldTmp  = $env:TMP

$longTemp = Join-Path $env:LOCALAPPDATA "Temp"
New-Item -ItemType Directory -LiteralPath $longTemp -Force | Out-Null

try {
    $env:TEMP = $longTemp
    $env:TMP  = $longTemp

    irm https://jcode.sh/install.ps1 | iex
}
finally {
    $env:TEMP = $oldTemp
    $env:TMP  = $oldTmp
}

With this workaround, jcode installs successfully.

Possible fix

The workaround documented in the upstream PowerShell issue is to resolve the item first and pipe the resulting object to Remove-Item:

Get-Item -LiteralPath $TempDir -ErrorAction SilentlyContinue |
    Remove-Item -Recurse -Force -ErrorAction SilentlyContinue

This could replace the current direct Remove-Item -Path $TempDir cleanup.

Alternatively, cleanup could use a .NET filesystem API, with cleanup errors handled separately so that they do not abort the remaining installation steps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    autonomous: clearHands-off: unambiguous bug, obvious fix, no decisions. Don't even look - an agent can fully solve.bugSomething isn't workingtriage: fixed-pending-releaseFixed in code/committed; will close automatically on next releasetriage: reproducibleClear repro + clear fix path

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions