-
Notifications
You must be signed in to change notification settings - Fork 372
/
Copy pathSymbolStoreKey.cs
129 lines (117 loc) · 4.47 KB
/
SymbolStoreKey.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.FileFormats.PE;
namespace Microsoft.SymbolStore
{
/// <summary>
/// Symbol store key information
/// </summary>
public sealed class SymbolStoreKey
{
/// <summary>
/// Symbol server index
/// </summary>
public readonly string Index;
/// <summary>
/// Full path name
/// </summary>
public readonly string FullPathName;
/// <summary>
/// If true, this file is one of the clr special files like the DAC or SOS, but
/// the key is the normal identity key for this file.
/// </summary>
public readonly bool IsClrSpecialFile;
/// <summary>
/// Empty array of keys
/// </summary>
public static SymbolStoreKey[] EmptyArray = Array.Empty<SymbolStoreKey>();
/// <summary>
/// The checksums of the pdb file (if any)
/// </summary>
public readonly IEnumerable<PdbChecksum> PdbChecksums;
/// <summary>
/// Create key instance.
/// </summary>
/// <param name="index">index to lookup on symbol server</param>
/// <param name="fullPathName">the full path name of the file</param>
/// <param name="clrSpecialFile">if true, the file is one the clr special files</param>
/// <param name="pdbChecksums">if true, the file is one the clr special files</param>
public SymbolStoreKey(string index, string fullPathName, bool clrSpecialFile = false, IEnumerable<PdbChecksum> pdbChecksums = null)
{
Index = index ?? throw new ArgumentNullException(nameof(index));
FullPathName = fullPathName ?? throw new ArgumentNullException(nameof(fullPathName));
IsClrSpecialFile = clrSpecialFile;
PdbChecksums = pdbChecksums ?? Enumerable.Empty<PdbChecksum>();
}
/// <summary>
/// Returns the first two or three parts of the index. Allows a different file name
/// to be appended to this symbol key. Includes the trailing "/".
/// </summary>
[Obsolete]
public string IndexPrefix
{
get { return Index.Substring(0, Index.LastIndexOf("/") + 1); }
}
/// <summary>
/// Returns the hash of the index.
/// </summary>
public override int GetHashCode()
{
return Index.GetHashCode();
}
/// <summary>
/// Only the index is compared or hashed. The FileName is already
/// part of the index.
/// </summary>
public override bool Equals(object obj)
{
SymbolStoreKey right = (SymbolStoreKey)obj;
return string.Equals(Index, right.Index);
}
private static HashSet<char> s_invalidChars = new(Path.GetInvalidFileNameChars());
/// <summary>
/// Validates a symbol index.
///
/// SSQP theoretically supports a broader set of keys, but in order to ensure that all the keys
/// play well with the caching scheme we enforce additional requirements (that all current key
/// conventions also meet).
/// </summary>
/// <param name="index">symbol key index</param>
/// <returns>true if valid</returns>
public static bool IsKeyValid(string index)
{
string[] parts = index.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length < 3 || parts.Length > 4)
{
return false;
}
for (int i = 0; i < parts.Length; i++)
{
foreach (char c in parts[i])
{
if (char.IsLetterOrDigit(c))
{
continue;
}
if (!s_invalidChars.Contains(c))
{
continue;
}
return false;
}
// We need to support files with . in the name, but we don't want identifiers that
// are meaningful to the filesystem
if (parts[i] == "." || parts[i] == "..")
{
return false;
}
}
return true;
}
}
}