Skip to content

Commit 073ffb2

Browse files
author
Stewart Miles
committed
Added mapping of discovered files to file metadata.
This makes it possible for the Version Handler to find a file referenced by a manifest using the current file path when it's moved in the project. Bug: 150886091 Change-Id: I8f896eee6cc32f07e1f00d248fde53fc960221b0
1 parent 99fe6bf commit 073ffb2

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

source/VersionHandlerImpl/src/VersionHandlerImpl.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,16 @@ private Dictionary<string, FileMetadataByVersion>
10421042
metadataByCanonicalFilename =
10431043
new Dictionary<string, FileMetadataByVersion>();
10441044

1045+
/// <summary>
1046+
/// Dictionary of FileMetadata indexed by filename in the project and the export path if
1047+
/// it exists. This is the inverse mapping of metadataByCanonicalFilename.
1048+
/// </summary>
1049+
/// <remarks>
1050+
/// This shouldn't not be modified directly, use Add() and Clear() instead.
1051+
/// </remarks>
1052+
private Dictionary<string, FileMetadata> metadataByFilename =
1053+
new Dictionary<string, FileMetadata>();
1054+
10451055
/// <summary>
10461056
/// Get the FileMetadataByVersion for each filename bucket in this set.
10471057
/// </summary>
@@ -1050,6 +1060,13 @@ public Dictionary<string, FileMetadataByVersion>.ValueCollection
10501060
get { return metadataByCanonicalFilename.Values; }
10511061
}
10521062

1063+
/// <summary>
1064+
/// Retrieves a map of in-project filename to file metadata.
1065+
/// </summary>
1066+
public Dictionary<string, FileMetadata> MetadataByFilename {
1067+
get { return metadataByFilename; }
1068+
}
1069+
10531070
/// <summary>
10541071
/// Construct an instance.
10551072
/// </summary>
@@ -1079,6 +1096,7 @@ public static FileMetadataSet FilterOutUnityPackageManagerFiles(
10791096
/// </summary>
10801097
public void Clear() {
10811098
metadataByCanonicalFilename = new Dictionary<string, FileMetadataByVersion>();
1099+
metadataByFilename = new Dictionary<string, FileMetadata>();
10821100
}
10831101

10841102
/// <summary>
@@ -1096,6 +1114,7 @@ public void Add(FileMetadata metadata) {
10961114
/// <param name="metadata">File metadata to add to the set.</param>
10971115
public void Add(string filenameCanonical, FileMetadata metadata) {
10981116
FindMetadataByVersion(filenameCanonical, true).Add(metadata);
1117+
UpdateMetadataByFilename(metadata);
10991118
}
11001119

11011120
/// <summary>
@@ -1107,6 +1126,18 @@ public void Add(string filenameCanonical, FileMetadataByVersion metadataByVersio
11071126
var existingMetadataByVersion = FindMetadataByVersion(filenameCanonical, true);
11081127
foreach (var metadata in metadataByVersion.Values) {
11091128
existingMetadataByVersion.Add(metadata);
1129+
UpdateMetadataByFilename(metadata);
1130+
}
1131+
}
1132+
1133+
/// <summary>
1134+
/// Update the mapping of filename to metadata.
1135+
/// </summary>
1136+
/// <param name="metadata">File metadata to add to the set.</param>
1137+
private void UpdateMetadataByFilename(FileMetadata metadata) {
1138+
metadataByFilename[metadata.filename] = metadata;
1139+
if (!String.IsNullOrEmpty(metadata.exportPath)) {
1140+
metadataByFilename[metadata.exportPath] = metadata;
11101141
}
11111142
}
11121143

@@ -1121,8 +1152,11 @@ public void Add(string filenameCanonical, FileMetadataByVersion metadataByVersio
11211152
/// <returns>Reference to the metadata if successful, null otherwise.</returns>
11221153
public FileMetadata FindMetadata(string filenameCanonical,
11231154
long version) {
1124-
var metadataByVersion = FindMetadataByVersion(filenameCanonical, false);
11251155
FileMetadata metadata;
1156+
if (metadataByFilename.TryGetValue(filenameCanonical, out metadata)) {
1157+
return metadata;
1158+
}
1159+
var metadataByVersion = FindMetadataByVersion(filenameCanonical, false);
11261160
if (metadataByVersion != null) {
11271161
metadata = version > 0 ? metadataByVersion[version] :
11281162
metadataByVersion.MostRecentVersion;

0 commit comments

Comments
 (0)