File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -316,6 +316,9 @@ public static async void Output(
316316 string content ,
317317 bool forceOverwrite
318318 ) {
319+ // All files should use CRLF so we should convert before writing
320+ content = content . Replace ( "\n " , "\r \n " ) ;
321+
319322 if ( string . IsNullOrWhiteSpace ( outputDirectory ) ) {
320323 // Output to console to allow for piping
321324 Console . Out . Write ( content ) ;
@@ -324,6 +327,16 @@ bool forceOverwrite
324327
325328 var outputPath = GetOutputLocation ( sourceDirectory , outputDirectory , fileName ) ;
326329 if ( File . Exists ( outputPath ) ) {
330+ var hashEngine = System . Security . Cryptography . SHA256 . Create ( ) ;
331+ var existingFileStream = File . OpenRead ( outputPath ) ;
332+ var hash = hashEngine . ComputeHash ( existingFileStream ) ;
333+ existingFileStream . Close ( ) ;
334+ var newHash = hashEngine . ComputeHash ( Encoding . UTF8 . GetBytes ( content ) ) ;
335+ if ( hash . SequenceEqual ( newHash ) ) {
336+ Logger . Trace ( $ "File { outputPath } already exists and is identical. Skipping.") ;
337+ return ;
338+ }
339+
327340 var removeFile = forceOverwrite ;
328341 if ( ! removeFile ) {
329342 Logger . Info ( $ "File { outputPath } already exists. Overwrite? (Y/n)") ;
You can’t perform that action at this time.
0 commit comments