{"record":{"id":"7def5ed7b4809bd7","repo":"LykosAI/StabilityMatrix","slug":"target-path-does-not-exist-or-is-not-a-directory","errorCode":null,"errorMessage":"Target path does not exist or is not a directory","messagePattern":"Target path does not exist or is not a directory","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/ReparsePoints/Junction.cs","lineNumber":49,"sourceCode":"        [In] IntPtr lpInBuffer, uint nInBufferSize,\n        IntPtr lpOutBuffer, uint nOutBufferSize,\n        [Out] out uint lpBytesReturned, IntPtr lpOverlapped);\n    \n    /// <summary>\n    /// Creates a junction point from the specified directory to the specified target directory.\n    /// </summary>\n    /// <param name=\"junctionPoint\">The junction point path</param>\n    /// <param name=\"targetDir\">The target directory (Must already exist)</param>\n    /// <param name=\"overwrite\">If true overwrites an existing reparse point or empty directory</param>\n    /// <exception cref=\"IOException\">Thrown when the junction point could not be created or when\n    /// an existing directory was found and <paramref name=\"overwrite\" /> if false</exception>\n    public static void Create(string junctionPoint, string targetDir, bool overwrite)\n    {\n        targetDir = Path.GetFullPath(targetDir);\n\n        if (!Directory.Exists(targetDir))\n        {\n            throw new IOException(\"Target path does not exist or is not a directory\");\n        }\n\n        if (Directory.Exists(junctionPoint))\n        {\n            if (!overwrite)\n                throw new IOException(\"Directory already exists and overwrite parameter is false.\");\n        }\n        else\n        {\n            Directory.CreateDirectory(junctionPoint);\n        }\n\n        using var fileHandle = OpenReparsePoint(junctionPoint, Win32FileAccess.GenericWrite);\n        var targetDirBytes = Encoding.Unicode.GetBytes(\n            NonInterpretedPathPrefix + Path.GetFullPath(targetDir));\n\n        var reparseDataBuffer = new ReparseDataBuffer\n        {","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/ReparsePoints/Junction.cs#L31-L67","documentation":"Junction.Create (Windows NTFS junction helper) throws IOException(\"Target path does not exist or is not a directory\") when the junction's target directory, after Path.GetFullPath normalization, does not exist or is a file rather than a directory. A junction must point at an existing directory, so the library validates the target before creating the reparse point.","triggerScenarios":"Calling Junction.Create(junctionPoint, targetDir, overwrite) where targetDir was never created, was deleted before the call, contains a typo, or points at a file.","commonSituations":"Ordering bugs where the target is created later than the junction; relative paths resolved against an unexpected working directory; case/spacing typos in the target path; target removed by a cleanup step.","solutions":["Create the target directory first: Directory.CreateDirectory(targetDir) before Junction.Create.","Verify the target path spelling and that it resolves to the intended absolute directory (print Path.GetFullPath(targetDir)).","Ensure the target is a directory, not a file; move/choose a different target if it's a file.","Check that no concurrent cleanup deleted the target between creation and junctioning."],"exampleFix":"// before\nJunction.Create(link, target, overwrite: true);\n// after\ntarget = Path.GetFullPath(target);\nDirectory.CreateDirectory(target); // idempotent\nJunction.Create(link, target, overwrite: true);","handlingStrategy":"validation","validationCode":"targetDir = Path.GetFullPath(targetDir);\nif (!Directory.Exists(targetDir)) {\n    Directory.CreateDirectory(targetDir); // or validate and fail early\n}","typeGuard":null,"tryCatchPattern":"try { Junction.Create(link, target, overwrite: true); }\ncatch (IOException ex) { Logger.Error($\"junction target invalid: {ex.Message}\"); throw; }","preventionTips":["Always create the target directory before creating a junction.","Normalize with Path.GetFullPath and log the resolved path to catch typos.","Confirm the target is a directory, not a file."],"tags":["filesystem","junction","windows","directory"],"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"}