Skip to content

Commit 29fda78

Browse files
committed
fix: Prevent potential infinite import loop (and polluted source control) due to the .ldtkc being written even if the contents don't change
1 parent ffeb4ef commit 29fda78

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Assets/LDtkUnity/Editor/Utility/Artifacts/LDtkConfigData.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
34
using System.Text;
45
using UnityEditor;
56
using UnityEngine;
@@ -29,6 +30,18 @@ internal string WriteJson(string projectAssetPath)
2930

3031
LDtkPathUtility.TryCreateDirectoryForFile(writePath);
3132

33+
//Only write if the contents are actually changed! Otherwise, it's been observed to pollute source control, but also potentially results in an infinite import loop.
34+
//The potential reason for an infinite loop is that the importer is triggered by the file being written, and it repeats each time.
35+
//It's not good practice to write files to disk during a scripted importer, but it works for now.
36+
if (File.Exists(writePath))
37+
{
38+
byte[] existingBytes = File.ReadAllBytes(writePath);
39+
if (existingBytes.SequenceEqual(byteArray))
40+
{
41+
return writePath;
42+
}
43+
}
44+
3245
File.WriteAllBytes(writePath, byteArray);
3346
return writePath;
3447
}

0 commit comments

Comments
 (0)