Skip to content

Commit

Permalink
Fix cloning instances with shared stock files on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Feb 6, 2025
1 parent 644cf5f commit d3ac667
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Core/DirectoryLink.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Win32.SafeHandles;
Expand Down Expand Up @@ -71,7 +73,7 @@ public static bool TryGetTarget(string link, out string? target)
{
if (junctionInfo.ReparseTag == IO_REPARSE_TAG_MOUNT_POINT)
{
target = junctionInfo.PathBuffer.TrimStart("\\\\?\\");
target = junctionInfo.PathBuffer.TrimStart(WindowsPathPrefixes);
}
}
h.Close();
Expand Down Expand Up @@ -203,9 +205,18 @@ private static extern SafeFileHandle CreateFile([MarshalAs(UnmanagedType.LPTStr)
[MarshalAs(UnmanagedType.U4)] uint flagsAndAttributes,
IntPtr templateFile);

private static string TrimStart(this string orig, string toRemove)
=> orig.StartsWith(toRemove) ? orig.Remove(0, toRemove.Length)
: orig;
private static string TrimStart(this string orig, IEnumerable<string> toRemove)
=> toRemove.FirstOrDefault(orig.StartsWith) switch
{
string s => orig[s.Length..],
null => orig,
};

private static readonly string[] WindowsPathPrefixes = new string[]
{
@"\\?\",
@"\??\",
@"\\.\",
};
}
}

0 comments on commit d3ac667

Please sign in to comment.