Skip to content

Commit 31d97ad

Browse files
committed
don't overwrite user files that happened to be called the same as the input actions target
1 parent e6254ab commit 31d97ad

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,18 @@ private static void GenerateWrapperCode(AssetImportContext ctx, InputActionAsset
247247
if (!Directory.Exists(dir))
248248
Directory.CreateDirectory(dir);
249249

250+
// Check for the case where the target file already exists.
251+
// If it does, we don't want to overwrite it unless it's been generated by us before.
252+
if (File.Exists(wrapperFilePath))
253+
{
254+
var text = File.ReadAllText(wrapperFilePath);
255+
var autoGeneratedMarker = "This code was auto-generated by com.unity.inputsystem";
256+
if (!text.Contains(autoGeneratedMarker))
257+
{
258+
throw new Exception($"The target file for Input Actions code generation already exists: {wrapperFilePath}. Since it doesn't look to contain Input generated code that we can safely overwrite, we stopped to prevent any data loss. Consider renaming. ");
259+
}
260+
}
261+
250262
var options = new InputActionCodeGenerator.Options
251263
{
252264
sourceAssetPath = ctx.assetPath,

0 commit comments

Comments
 (0)