LykosAI/StabilityMatrix · error · IOException

Failed to delete junction point

Error message

Failed to delete junction point {targetDirectory}

What it means

PackageManagerViewModel.DeleteDirectory removes junction points with Directory.Delete(path, false) (non-recursive, junction-only). If Windows throws an IOException — e.g. the junction is in use, broken, or access-denied — it is rethrown wrapped as 'Failed to delete junction point {targetDirectory}'.

Solutions

  1. Close any programs (terminals, Explorer windows, editors) that are inside the package directory or its junction, then retry the delete.
  2. Run the app elevated if the junction sits in a protected location and access was denied.
  3. Delete the junction manually (rmdir on the junction path, which removes only the link) and retry the package delete.
  4. Reboot or use SysInternals 'handle' to find and release the process holding a handle, then retry.

Example fix

// manual fallback when app delete fails
cmd /c rmdir "C:\path\to\junction"   # removes the link, not the target
// then retry the package deletion in Stability Matrix
Defensive patterns

Strategy: try-catch

Validate before calling

if ((new DirectoryInfo(path).Attributes & FileAttributes.ReparsePoint) != 0 &&
    IsDirectoryInUse(path)) return; // defer delete until handles are released

Type guard

static bool IsJunction(string path) =>
    Directory.Exists(path) &&
    (new DirectoryInfo(path).Attributes & FileAttributes.ReparsePoint) != 0;

Try / catch

try { await vm.DeleteDirectoryAsync(path); }
catch (IOException ex) when (ex.Message.StartsWith("Failed to delete junction point"))
{
    logger.Warning(ex, "Junction delete failed; retrying after handle release");
    // close locking processes or rmdir the junction, then retry
}

Prevention

When it happens

Trigger: Deleting a package whose directory contains a junction/symlink, when Directory.Delete on the junction itself fails: a process holds a handle inside the target, the junction target is unavailable, or access is denied.

Common situations: A game/terminal/Explorer window has its working directory inside the junction; OneDrive/antivirus locking files under the link; the symlink target was removed leaving a broken junction that some filesystem states refuse to delete; deleting packages on a network drive.

Related errors


AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12). Data as JSON: /api/errors/3538a7a68fe90d15. Report an issue: GitHub.

Appendix: source

Thrown at StabilityMatrix/ViewModels/PackageManagerViewModel.cs:246

    private void DeleteDirectory(string targetDirectory)
    {
        // Skip if directory does not exist
        if (!Directory.Exists(targetDirectory))
        {
            return;
        }
        // For junction points, delete with recursive false
        if (new DirectoryInfo(targetDirectory).LinkTarget != null)
        {
            logger.LogInformation("Removing junction point {TargetDirectory}", targetDirectory);
            try
            {
                Directory.Delete(targetDirectory, false);
                return;
            }
            catch (IOException ex)
            {
                throw new IOException($"Failed to delete junction point {targetDirectory}", ex);
            }
        }
        // Recursively delete all subdirectories
        var subdirectoryEntries = Directory.GetDirectories(targetDirectory);
        foreach (var subdirectoryPath in subdirectoryEntries)
        {
            DeleteDirectory(subdirectoryPath);
        }
        // Delete all files in the directory
        var fileEntries = Directory.GetFiles(targetDirectory);
        foreach (var filePath in fileEntries)
        {
            try
            {
                File.SetAttributes(filePath, FileAttributes.Normal);
                File.Delete(filePath);
            }
            catch (IOException ex)

View on GitHub (pinned to af93d6ef57)