Skip to content

Commit 54c05ac

Browse files
goran-wlove-linger
authored andcommitted
fix: remove trailing slash in paths, to avoid failing comparisons.
This is needed since DirectoryInfo.Fullname (and .FullPath) will not "normalize" trailing slashes, so direct equality tests are error-prone. This fixes a bug in ScanRepositories.GetUnmanagedRepositories(), where not all Git repo folders were added. (Also, corrected a variable name from 'founded' to 'found'.)
1 parent 75c32c1 commit 54c05ac

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/ViewModels/ScanRepositories.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public override Task<bool> Sure()
3131
watch.Start();
3232

3333
var rootDir = new DirectoryInfo(RootDir);
34-
var founded = new List<FoundRepository>();
35-
GetUnmanagedRepositories(rootDir, founded, new EnumerationOptions()
34+
var found = new List<FoundRepository>();
35+
GetUnmanagedRepositories(rootDir, found, new EnumerationOptions()
3636
{
3737
AttributesToSkip = FileAttributes.Hidden | FileAttributes.System,
3838
IgnoreInaccessible = true,
@@ -46,11 +46,11 @@ public override Task<bool> Sure()
4646

4747
Dispatcher.UIThread.Invoke(() =>
4848
{
49-
var normalizedRoot = rootDir.FullName.Replace("\\", "/");
49+
var normalizedRoot = rootDir.FullName.Replace("\\", "/").TrimEnd('/');
5050

51-
foreach (var f in founded)
51+
foreach (var f in found)
5252
{
53-
var parent = new DirectoryInfo(f.Path).Parent!.FullName.Replace("\\", "/");
53+
var parent = new DirectoryInfo(f.Path).Parent!.FullName.Replace("\\", "/").TrimEnd('/');
5454
if (parent.Equals(normalizedRoot, StringComparison.Ordinal))
5555
{
5656
Preferences.Instance.FindOrAddNodeByRepositoryPath(f.Path, null, false);
@@ -93,7 +93,7 @@ private void GetUnmanagedRepositories(DirectoryInfo dir, List<FoundRepository> o
9393

9494
CallUIThread(() => ProgressDescription = $"Scanning {subdir.FullName}...");
9595

96-
var normalizedSelf = subdir.FullName.Replace("\\", "/");
96+
var normalizedSelf = subdir.FullName.Replace("\\", "/").TrimEnd('/');
9797
if (_managed.Contains(normalizedSelf))
9898
continue;
9999

@@ -103,7 +103,7 @@ private void GetUnmanagedRepositories(DirectoryInfo dir, List<FoundRepository> o
103103
var test = new Commands.QueryRepositoryRootPath(subdir.FullName).ReadToEnd();
104104
if (test.IsSuccess && !string.IsNullOrEmpty(test.StdOut))
105105
{
106-
var normalized = test.StdOut.Trim().Replace("\\", "/");
106+
var normalized = test.StdOut.Trim().Replace("\\", "/").TrimEnd('/');
107107
if (!_managed.Contains(normalized))
108108
outs.Add(new FoundRepository(normalized, false));
109109
}

0 commit comments

Comments
 (0)