Skip to content

Commit

Permalink
Address Jason's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
daxian-dbw committed Sep 23, 2019
1 parent f7d8768 commit e7ad62d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
5 changes: 1 addition & 4 deletions PSReadLine/Cmdlets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Management.Automation;
using System.Management.Automation.Language;
using System.Reflection;
Expand Down Expand Up @@ -639,9 +638,7 @@ public string HistorySavePath
get => _historySavePath;
set
{
// Normalize the path
var altPathChar = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? '/' : '\\';
_historySavePath = value?.Replace(altPathChar, Path.DirectorySeparatorChar);
_historySavePath = GetUnresolvedProviderPathFromPSPath(value);
}
}
private string _historySavePath;
Expand Down
24 changes: 15 additions & 9 deletions PSReadLine/History.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using Microsoft.PowerShell.PSReadLine;
Expand All @@ -22,20 +23,20 @@ internal class FNV1a32Hash
private const uint FNV32_PRIME = 16777619;
private const uint FNV32_OFFSETBASIS = 2166136261;

internal static uint ComputeHash(byte[] buffer)
internal static uint ComputeHash(string input)
{
uint hash = FNV32_OFFSETBASIS;
for (int i = 0; i < buffer.Length; i++)
for (int i = 0; i < input.Length; i++)
{
hash = (hash ^ buffer[i]) * FNV32_PRIME;
char c = input[i];
uint lowByte = (uint)(c & 0x00FF);
hash = (hash ^ lowByte) * FNV32_PRIME;

uint highByte = (uint)(c >> 8);
hash = (hash ^ highByte) * FNV32_PRIME;
}
return hash;
}

internal static uint ComputeHash(string input)
{
return ComputeHash(Encoding.UTF8.GetBytes(input));
}
}

public partial class PSConsoleReadLine
Expand Down Expand Up @@ -171,7 +172,12 @@ private string GetHistorySaveFileMutexName()
{
// Return a reasonably unique name - it's not too important as there will rarely
// be any contention.
return "PSReadLineHistoryFile_" + FNV1a32Hash.ComputeHash(_options.HistorySavePath);
uint hashFromPath = FNV1a32Hash.ComputeHash(
RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? _options.HistorySavePath.ToLower()
: _options.HistorySavePath);

return "PSReadLineHistoryFile_" + hashFromPath.ToString();
}

private void IncrementalHistoryWrite()
Expand Down

0 comments on commit e7ad62d

Please sign in to comment.