@@ -51,22 +51,36 @@ public async Task GenerateVersionAsync(OpenApiDocument document, string outputDi
5151 }
5252
5353 /// <summary>
54- /// Copies the embedded HttpCommand.aplc binary resource to the output directory.
54+ /// Copies the embedded HttpCommand.aplc binary resource to the output directory,
55+ /// skipping the write if the existing file is already identical.
5556 /// </summary>
5657 public async Task CopyHttpCommandAsync ( string outputDirectory )
5758 {
5859 var destPath = Path . Combine ( outputDirectory , GeneratorConstants . AplSourceDir , "HttpCommand.aplc" ) ;
5960 Directory . CreateDirectory ( Path . GetDirectoryName ( destPath ) ! ) ;
6061
61- using var srcStream = _templateService . GetEmbeddedResourceStream ( GeneratorConstants . HttpCommandResource ) ;
62- using var destStream = File . Create ( destPath ) ;
63- await srcStream . CopyToAsync ( destStream ) ;
62+ using var srcStream = _templateService . GetEmbeddedResourceStream ( GeneratorConstants . HttpCommandResource ) ;
63+ using var memStream = new MemoryStream ( ) ;
64+ await srcStream . CopyToAsync ( memStream ) ;
65+ var srcBytes = memStream . ToArray ( ) ;
6466
67+ if ( File . Exists ( destPath ) )
68+ {
69+ var destBytes = await File . ReadAllBytesAsync ( destPath ) ;
70+ if ( srcBytes . SequenceEqual ( destBytes ) )
71+ {
72+ _logger . LogInformation ( "Unchanged: {AplSourceDir}/HttpCommand.aplc" , GeneratorConstants . AplSourceDir ) ;
73+ return ;
74+ }
75+ }
76+
77+ await File . WriteAllBytesAsync ( destPath , srcBytes ) ;
6578 _logger . LogInformation ( "Copied: {AplSourceDir}/HttpCommand.aplc" , GeneratorConstants . AplSourceDir ) ;
6679 }
6780
6881 /// <summary>
69- /// Copies the OpenAPI specification file to the output directory.
82+ /// Copies the OpenAPI specification file to the output directory,
83+ /// skipping the write if the existing file is already identical.
7084 /// </summary>
7185 /// <exception cref="IOException">Re-thrown after logging if the copy fails.</exception>
7286 public async Task CopySpecificationAsync ( string sourcePath , string outputDirectory )
@@ -76,9 +90,20 @@ public async Task CopySpecificationAsync(string sourcePath, string outputDirecto
7690
7791 try
7892 {
79- File . Copy ( sourcePath , destPath , overwrite : true ) ;
93+ var srcBytes = await File . ReadAllBytesAsync ( sourcePath ) ;
94+
95+ if ( File . Exists ( destPath ) )
96+ {
97+ var destBytes = await File . ReadAllBytesAsync ( destPath ) ;
98+ if ( srcBytes . SequenceEqual ( destBytes ) )
99+ {
100+ _logger . LogInformation ( "Unchanged: {FileName}" , fileName ) ;
101+ return ;
102+ }
103+ }
104+
105+ await File . WriteAllBytesAsync ( destPath , srcBytes ) ;
80106 _logger . LogInformation ( "Copied: {FileName}" , fileName ) ;
81- await Task . CompletedTask ; // async for consistent caller pattern
82107 }
83108 catch ( Exception ex )
84109 {
0 commit comments