Browse Source

Merge pull request #2418 from icsharpcode/realpath-fix

Fix bug in DotNetCorePathFinder on Unix systems: realpath always returned garbage.
pull/2423/head
Siegfried Pammer 4 years ago committed by GitHub
parent
commit
bfb6a49d2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs

34
ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs

@ -286,9 +286,7 @@ namespace ICSharpCode.Decompiler.Metadata @@ -286,9 +286,7 @@ namespace ICSharpCode.Decompiler.Metadata
{
if ((new FileInfo(fileName).Attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint)
{
var sb = new StringBuilder();
realpath(fileName, sb);
fileName = sb.ToString();
fileName = GetRealPath(fileName, Encoding.Default);
if (!File.Exists(fileName))
continue;
}
@ -300,7 +298,33 @@ namespace ICSharpCode.Decompiler.Metadata @@ -300,7 +298,33 @@ namespace ICSharpCode.Decompiler.Metadata
return null;
}
[DllImport("libc")]
static extern void realpath(string path, StringBuilder resolvedPath);
static unsafe string GetRealPath(string path, Encoding encoding)
{
var bytes = encoding.GetBytes(path);
fixed (byte* input = bytes)
{
byte* output = GetRealPath(input, null);
if (output == null)
{
return null;
}
int len = 0;
for (byte* c = output; *c != 0; c++)
{
len++;
}
byte[] result = new byte[len];
Marshal.Copy((IntPtr)output, result, 0, result.Length);
Free(output);
return encoding.GetString(result);
}
}
[DllImport("libc", EntryPoint = "realpath")]
static extern unsafe byte* GetRealPath(byte* path, byte* resolvedPath);
[DllImport("libc", EntryPoint = "free")]
static extern unsafe void Free(void* ptr);
}
}

Loading…
Cancel
Save