Skip to content

Commit

Permalink
C#: Fix csproj not synced on file move/removal from FS dock
Browse files Browse the repository at this point in the history
When NormalizePath was called with an absolute
path (with drive letter) on Windows, it would
prepend a file path separator to the path, e.g.:
'\C:\Program Files\'.
Apparently this was still accepted as a valid
path by DotNetGlob and it stopped working when
we switched to MSBuildGlob.

(cherry picked from commit 1db0395)
  • Loading branch information
neikeq authored and akien-mga committed Sep 13, 2020
1 parent cd62be1 commit cdc9fe1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions modules/mono/editor/GodotTools/GodotTools.Core/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;

namespace GodotTools.Core
{
Expand Down Expand Up @@ -35,7 +36,17 @@ public static string NormalizePath(this string path)

path = string.Join(Path.DirectorySeparatorChar.ToString(), parts).Trim();

return rooted ? Path.DirectorySeparatorChar + path : path;
if (!rooted)
return path;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
string maybeDrive = parts[0];
if (maybeDrive.Length == 2 && maybeDrive[1] == ':')
return path; // Already has drive letter
}

return Path.DirectorySeparatorChar + path;
}

private static readonly string DriveRoot = Path.GetPathRoot(Environment.CurrentDirectory);
Expand All @@ -49,7 +60,7 @@ public static bool IsAbsolutePath(this string path)

public static string ToSafeDirName(this string dirName, bool allowDirSeparator = false)
{
var invalidChars = new List<string> { ":", "*", "?", "\"", "<", ">", "|" };
var invalidChars = new List<string> {":", "*", "?", "\"", "<", ">", "|"};

if (allowDirSeparator)
{
Expand Down

0 comments on commit cdc9fe1

Please sign in to comment.