Skip to content

Commit 6226535

Browse files
committed
Address Jason's comments
1 parent a241e35 commit 6226535

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

PSReadLine/Cmdlets.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Collections.ObjectModel;
99
using System.Diagnostics.CodeAnalysis;
1010
using System.Globalization;
11-
using System.IO;
1211
using System.Management.Automation;
1312
using System.Management.Automation.Language;
1413
using System.Reflection;
@@ -648,9 +647,7 @@ public string HistorySavePath
648647
get => _historySavePath;
649648
set
650649
{
651-
// Normalize the path
652-
var altPathChar = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? '/' : '\\';
653-
_historySavePath = value?.Replace(altPathChar, Path.DirectorySeparatorChar);
650+
_historySavePath = GetUnresolvedProviderPathFromPSPath(value);
654651
}
655652
}
656653
private string _historySavePath;

PSReadLine/History.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.IO;
99
using System.Linq;
1010
using System.Management.Automation;
11+
using System.Runtime.InteropServices;
1112
using System.Text;
1213
using System.Text.RegularExpressions;
1314
using System.Threading;
@@ -24,20 +25,20 @@ internal class FNV1a32Hash
2425
private const uint FNV32_PRIME = 16777619;
2526
private const uint FNV32_OFFSETBASIS = 2166136261;
2627

27-
internal static uint ComputeHash(byte[] buffer)
28+
internal static uint ComputeHash(string input)
2829
{
2930
uint hash = FNV32_OFFSETBASIS;
30-
for (int i = 0; i < buffer.Length; i++)
31+
for (int i = 0; i < input.Length; i++)
3132
{
32-
hash = (hash ^ buffer[i]) * FNV32_PRIME;
33+
char c = input[i];
34+
uint lowByte = (uint)(c & 0x00FF);
35+
hash = (hash ^ lowByte) * FNV32_PRIME;
36+
37+
uint highByte = (uint)(c >> 8);
38+
hash = (hash ^ highByte) * FNV32_PRIME;
3339
}
3440
return hash;
3541
}
36-
37-
internal static uint ComputeHash(string input)
38-
{
39-
return ComputeHash(Encoding.UTF8.GetBytes(input));
40-
}
4142
}
4243

4344
public partial class PSConsoleReadLine
@@ -207,7 +208,12 @@ private string GetHistorySaveFileMutexName()
207208
{
208209
// Return a reasonably unique name - it's not too important as there will rarely
209210
// be any contention.
210-
return "PSReadLineHistoryFile_" + FNV1a32Hash.ComputeHash(_options.HistorySavePath);
211+
uint hashFromPath = FNV1a32Hash.ComputeHash(
212+
RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
213+
? _options.HistorySavePath.ToLower()
214+
: _options.HistorySavePath);
215+
216+
return "PSReadLineHistoryFile_" + hashFromPath.ToString();
211217
}
212218

213219
private void IncrementalHistoryWrite()

0 commit comments

Comments
 (0)