Skip to content

Commit f3d30e1

Browse files
author
Stewart Miles
committed
Ensure FileMetadata does not attempt to update UPM files.
FileMetadata synchronizes asset labels with properties on the class which does not work with UPM as UPM will restore the files after modification, cause an asset database refresh which then causes FileMetadata to synchronize asset labels and so on. This adds the IsReadOnly property to FileMetadata to determine whether it references a file that should not be modified. This property is used to prevent modification of asset metadata by the class. In addition, this is used to simplify FileMetadataSet filtering. Bug: 150902136 Change-Id: I570456e463f694adada53f039f01f3a5265568df
1 parent 733a6d1 commit f3d30e1

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

source/VersionHandlerImpl/src/VersionHandlerImpl.cs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,17 @@ public string ManifestName {
352352
}
353353
}
354354

355+
/// <summary>
356+
/// Whether it's possible to change the asset metadata.
357+
/// </summary>
358+
/// <returns>true if the asset metadata for this file is read-only,
359+
/// false otherwise.</return>
360+
public bool IsReadOnly {
361+
get {
362+
return FileUtils.IsUnderDirectory(filename, FileUtils.PACKAGES_FOLDER);
363+
}
364+
}
365+
355366
/// <summary>
356367
/// Parse metadata from filename and store in this class.
357368
/// </summary>
@@ -646,7 +657,9 @@ public HashSet<string> GetDotNetTargets() {
646657
/// Save metadata from this class into the asset's labels.
647658
/// </summary>
648659
public void UpdateAssetLabels() {
649-
if (String.IsNullOrEmpty(AssetDatabase.AssetPathToGUID(filename))) return;
660+
if (String.IsNullOrEmpty(AssetDatabase.AssetPathToGUID(filename)) || IsReadOnly) {
661+
return;
662+
}
650663
AssetImporter importer = AssetImporter.GetAtPath(filename);
651664
var labels = new List<string>();
652665
var currentLabels = new List<string>();
@@ -1168,19 +1181,15 @@ public Dictionary<string, FileMetadata> MetadataByFilename {
11681181
public FileMetadataSet() { }
11691182

11701183
/// <summary>
1171-
/// Filter all files that were installed by the Unity Package Manager.
1184+
/// Filter all files that can't be modified.
11721185
/// </summary>
11731186
/// <param name="metadataSet">Metadata set to filter.</param>
1174-
/// <returns>New FileMetadata with Unity Package Manager files removed.</returns>
1175-
public static FileMetadataSet FilterOutUnityPackageManagerFiles(
1176-
FileMetadataSet metadataSet) {
1187+
/// <returns>New FileMetadata with files that can't be modified removed.</returns>
1188+
public static FileMetadataSet FilterOutReadOnlyFiles(FileMetadataSet metadataSet) {
11771189
var filteredMetadata = new FileMetadataSet();
11781190
foreach (var metadataByVersion in metadataSet.Values) {
11791191
foreach (var metadata in metadataByVersion.Values) {
1180-
if (!FileUtils.IsUnderDirectory(metadata.filename,
1181-
FileUtils.PACKAGES_FOLDER)) {
1182-
filteredMetadata.Add(metadata);
1183-
}
1192+
if (!metadata.IsReadOnly) filteredMetadata.Add(metadata);
11841193
}
11851194
}
11861195
return filteredMetadata;
@@ -1744,7 +1753,7 @@ public static List<ManifestReferences> FindAndReadManifests() {
17441753
/// </summary>
17451754
/// <returns>List of ManifestReferences from Assets folder</returns>
17461755
public static List<ManifestReferences> FindAndReadManifestsInAssetsFolder() {
1747-
return FindAndReadManifests(FileMetadataSet.FilterOutUnityPackageManagerFiles(
1756+
return FindAndReadManifests(FileMetadataSet.FilterOutReadOnlyFiles(
17481757
FileMetadataSet.ParseFromFilenames(FindAllAssets())));
17491758
}
17501759

@@ -2468,7 +2477,7 @@ public static void UpdateVersionedAssets(bool forceUpdate, Action complete) {
24682477

24692478
UpdateAssetsWithBuildTargets(EditorUserBuildSettings.activeBuildTarget);
24702479

2471-
var metadataSet = FileMetadataSet.FilterOutUnityPackageManagerFiles(
2480+
var metadataSet = FileMetadataSet.FilterOutReadOnlyFiles(
24722481
FileMetadataSet.ParseFromFilenames(FindAllAssets()));
24732482
// Rename linux libraries, if any are being tracked.
24742483
var linuxLibraries = new LinuxLibraryRenamer(metadataSet);

0 commit comments

Comments
 (0)