{"record":{"id":"a278e5f524d89fc9","repo":"LykosAI/StabilityMatrix","slug":"path-is-not-a-junction-point","errorCode":null,"errorMessage":"Path is not a junction point.","messagePattern":"Path is not a junction point\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/ReparsePoints/Junction.cs","lineNumber":116,"sourceCode":"            }\n        }\n        finally\n        {\n            Marshal.FreeHGlobal(inBuffer);\n        }\n    }\n    \n    /// <summary>\n    /// Deletes a junction point at the specified source directory along with the directory itself.\n    /// Does nothing if the junction point does not exist.\n    /// </summary>\n    /// <param name=\"junctionPoint\">The junction point path</param>\n    public static void Delete(string junctionPoint)\n    {\n        if (!Directory.Exists(junctionPoint))\n        {\n            if (File.Exists(junctionPoint))\n                throw new IOException(\"Path is not a junction point.\");\n\n            return;\n        }\n\n        using var fileHandle = OpenReparsePoint(junctionPoint, Win32FileAccess.GenericWrite);\n        \n        var reparseDataBuffer = new ReparseDataBuffer\n        {\n            ReparseTag = (uint) DeviceIoControlCode.ReparseTagMountPoint,\n            ReparseDataLength = 0,\n            PathBuffer = new byte[0x3ff0]\n        };\n\n        var inBufferSize = Marshal.SizeOf(reparseDataBuffer);\n        var inBuffer = Marshal.AllocHGlobal(inBufferSize);\n        try\n        {\n            Marshal.StructureToPtr(reparseDataBuffer, inBuffer, false);","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/ReparsePoints/Junction.cs#L98-L134","documentation":"Junction.Delete throws IOException(\"Path is not a junction point.\") when the given path exists but is a regular file, not a directory/junction. A junction delete only makes sense for a directory reparse point, so the library refuses to act on a file path. If the path doesn't exist at all, Delete silently returns.","triggerScenarios":"Calling Junction.Delete(junctionPoint) where the path is an existing regular file (File.Exists true, Directory.Exists false) — e.g. the junction was replaced by a file, or the wrong path was passed to cleanup code.","commonSituations":"Cleanup logic that assumed everything at the path was a junction; a tool replaced the junction with a hardlink/file; path confusion between link path and target path; leftover files from partial uninstalls.","solutions":["Check the path type first and only call Junction.Delete on directories/junctions; delete plain files with File.Delete.","Verify you are passing the junction (link) path, not the target directory path.","If a file erroneously occupies the junction path, delete the file and re-create the junction.","Use Junction.Exists or reparse-point inspection to confirm the path is a junction before deleting."],"exampleFix":"// before\nJunction.Delete(path); // throws if path is a file\n// after\nif (Directory.Exists(path)) {\n    Junction.Delete(path);\n} else if (File.Exists(path)) {\n    File.Delete(path);\n}","handlingStrategy":"type-guard","validationCode":"if (!Directory.Exists(junctionPoint)) return; // nothing to delete (or file handled separately)","typeGuard":"static bool IsDirectoryPath(string p) => Directory.Exists(p);","tryCatchPattern":"try { Junction.Delete(path); }\ncatch (IOException ex) when (ex.Message.Contains(\"not a junction\")) { File.Delete(path); }","preventionTips":["Check Directory.Exists vs File.Exists before deleting.","Pass the junction (link) path, never the target directory, to Junction.Delete.","Inspect reparse points to confirm a path is a junction before cleanup."],"tags":["filesystem","junction","windows","type-mismatch"],"backgroundTag":"path-is-not-a-directory","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}