Skip to content

Commit cd967fc

Browse files
author
Stewart Miles
committed
Updated Version Handler manifests to most recent installed files.
Improved global tracking of obsolete files across VH package upgrades. Previously if a file was deemed obsolete due to the difference in one package's manifest it would not have been detected as obsolete in a dependent package. This commit changes manifest parsing to search for all revisions of each file and select the latest revision in all parsed manifests. Bug: 150471207 Change-Id: I07587b86fca18ec60741f9eb6f10fd2b0c06f374
1 parent da365d7 commit cd967fc

File tree

1 file changed

+48
-9
lines changed

1 file changed

+48
-9
lines changed

source/VersionHandlerImpl/src/VersionHandlerImpl.cs

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ public FileMetadata FindMetadata(string filenameCanonical,
13561356
/// <param name="addEntry">Whether to add an entry if the metadata isn't found.</param>
13571357
/// <returns>Reference to the metadata by version if successful or addEntry is true,
13581358
/// null otherwise.</returns>
1359-
private FileMetadataByVersion FindMetadataByVersion(string filenameCanonical,
1359+
public FileMetadataByVersion FindMetadataByVersion(string filenameCanonical,
13601360
bool addEntry) {
13611361
FileMetadataByVersion metadataByVersion;
13621362
if (!metadataByCanonicalFilename.TryGetValue(
@@ -1446,7 +1446,7 @@ private Dictionary<string, HashSet<string>> GetManifestAliasesByName() {
14461446
}
14471447

14481448
/// <summary>
1449-
/// Use manifest aliases to cosolidate manifest metadata.
1449+
/// Use manifest aliases to consolidate manifest metadata.
14501450
/// </summary>
14511451
/// <returns>Flattened map of highest priority manifest name by each alias of the manifest
14521452
/// name.</returns>
@@ -1752,10 +1752,13 @@ public ManifestReferences() { }
17521752
/// project. This is used to handle file renaming in the parsed
17531753
/// manifest. If the manifest contains files that have been
17541754
/// renamed it's updated with the new filenames.</param>
1755-
/// <returns>Metadata of files in the package indexed by current filename.<returns>
1756-
public Dictionary<string, FileMetadata> ParseLegacyManifest(FileMetadata metadata,
1757-
FileMetadataSet metadataSet) {
1758-
var filesInManifest = new Dictionary<string, FileMetadata>();
1755+
/// <returns>Metadata of files in the package indexed by current filename.
1756+
/// The FileMetadataByVersion will be null for files that aren't present in the
1757+
/// asset database.returns>
1758+
public Dictionary<string, KeyValuePair<FileMetadata, FileMetadataByVersion>>
1759+
ParseLegacyManifest(FileMetadata metadata, FileMetadataSet metadataSet) {
1760+
var filesInManifest =
1761+
new Dictionary<string, KeyValuePair<FileMetadata, FileMetadataByVersion>>();
17591762
StreamReader manifestFile =
17601763
new StreamReader(metadata.filename);
17611764
string line;
@@ -1769,7 +1772,11 @@ public Dictionary<string, FileMetadata> ParseLegacyManifest(FileMetadata metadat
17691772
metadataSet.FindMetadata(manifestFileMetadata.filenameCanonical, version) ??
17701773
metadataSet.FindMetadata(manifestFileMetadata.filename, version);
17711774
if (existingFileMetadata != null) manifestFileMetadata = existingFileMetadata;
1772-
filesInManifest[manifestFileMetadata.filename] = manifestFileMetadata;
1775+
filesInManifest[manifestFileMetadata.filename] =
1776+
new KeyValuePair<FileMetadata, FileMetadataByVersion>(
1777+
manifestFileMetadata,
1778+
metadataSet.FindMetadataByVersion(manifestFileMetadata.filenameCanonical,
1779+
false));
17731780
}
17741781
manifestFile.Close();
17751782
return filesInManifest;
@@ -1802,15 +1809,36 @@ public bool ParseManifests(FileMetadataByVersion metadataByVersion,
18021809
metadataByVersion.filenameCanonical), verbose: true);
18031810
this.metadataByVersion = metadataByVersion;
18041811
var filesInManifest = ParseLegacyManifest(metadata, metadataSet);
1805-
var filenames = new HashSet<string>(filesInManifest.Keys);
18061812
// If this is the most recent manifest version, remove all
18071813
// current files from the set to delete.
18081814
if (versionIndex == numberOfVersions) {
1815+
var filenames = new HashSet<string>();
1816+
// Add references to the most recent file metadata for each referenced file.
1817+
metadataByFilename = new Dictionary<string, FileMetadata>();
1818+
foreach (var kv in filesInManifest.Values) {
1819+
var fileMetadataByVersion = kv.Value;
1820+
var mostRecentMetadata =
1821+
fileMetadataByVersion != null ?
1822+
fileMetadataByVersion.MostRecentVersion : kv.Key;
1823+
metadataByFilename[mostRecentMetadata.filename] = mostRecentMetadata;
1824+
filenames.Add(mostRecentMetadata.filename);
1825+
if (fileMetadataByVersion != null) {
1826+
var versions = fileMetadataByVersion.Values;
1827+
int numberOfFileVersions = versions.Count;
1828+
int fileVersionIndex = 0;
1829+
foreach (var version in versions) {
1830+
fileVersionIndex ++;
1831+
if (fileVersionIndex == numberOfFileVersions) break;
1832+
obsoleteFiles.Add(version.filename);
1833+
}
1834+
}
1835+
}
1836+
18091837
currentFiles.UnionWith(filenames);
18101838
obsoleteFiles.ExceptWith(filenames);
18111839
currentMetadata = metadata;
1812-
metadataByFilename = filesInManifest;
18131840
} else {
1841+
var filenames = new HashSet<string>(filesInManifest.Keys);
18141842
obsoleteFiles.UnionWith(filenames);
18151843
}
18161844
}
@@ -1866,6 +1894,7 @@ public static Dictionary<string, ManifestReferences> FindAndReadManifestsByPacka
18661894
aliases.Add(alias);
18671895
}
18681896

1897+
var allObsoleteFiles = new HashSet<string>();
18691898
var manifestReferencesByPackageName = new Dictionary<string, ManifestReferences>();
18701899
foreach (var metadataByVersion in metadataSet.Values) {
18711900
ManifestReferences manifestReferences = new ManifestReferences();
@@ -1875,8 +1904,18 @@ public static Dictionary<string, ManifestReferences> FindAndReadManifestsByPacka
18751904
aliasesByName[manifestReferences.filenameCanonical];
18761905
manifestReferencesByPackageName[manifestReferences.filenameCanonical] =
18771906
manifestReferences;
1907+
allObsoleteFiles.UnionWith(manifestReferences.obsoleteFiles);
18781908
}
18791909
}
1910+
1911+
// Move globally obsolete files to the obsolete files set across all manifests.
1912+
foreach (var manifestReferences in manifestReferencesByPackageName.Values) {
1913+
var newlyObsoleteFiles = new HashSet<string>(manifestReferences.currentFiles);
1914+
newlyObsoleteFiles.IntersectWith(allObsoleteFiles);
1915+
manifestReferences.currentFiles.ExceptWith(newlyObsoleteFiles);
1916+
manifestReferences.obsoleteFiles.UnionWith(newlyObsoleteFiles);
1917+
}
1918+
18801919
return manifestReferencesByPackageName;
18811920
}
18821921

0 commit comments

Comments
 (0)