-
Notifications
You must be signed in to change notification settings - Fork 909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(GH-1047) Harden Xml serialization and deserialization #1084
(GH-1047) Harden Xml serialization and deserialization #1084
Conversation
c0badd5
to
922af62
Compare
I'm thinking I may add some unit tests around this too, but I have nothing hard group just yet |
public byte[] ComputeHash(Stream stream) | ||
{ | ||
return _algorithm.ComputeHash(stream); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -1,4 +1,4 @@ | |||
// Copyright � 2011 - Present RealDimensions Software, LLC | |||
// Copyright � 2011 - Present RealDimensions Software, LLC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you dropped this from UTF-8. Very much dislike when Visual Studio does this. 👎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Darn't. Did even notice that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix both occurences
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great so far. I am concerned that the files did change from UTF8 (no BOM) to ANSI. If you could fix those files that were changed by VS and squash that back into this, that would be good.
@@ -1,4 +1,4 @@ | |||
// Copyright � 2011 - Present RealDimensions Software, LLC | |||
// Copyright � 2011 - Present RealDimensions Software, LLC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here :/
} | ||
throw; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is the meat - just compares the stream versus the file before it creates the old file? This would be great in low access environments so there is no error message when it can't create the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was exactly the idea! No more Failed to write chocolatey.config.update
permission errors :D
Minor nitpicks to your git commit:
The other change I would request is to keep the same |
6502951
to
63cdb82
Compare
memoryStream.CopyTo(updateFileStream); | ||
} | ||
_fileSystem.replace_file(tempUpdateFile, xmlFilePath, xmlFilePath + ".backup"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notes for me. We should probably delete the backup file when things are successful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mostly keep it because it allows us to recover if a future operation fails for some reason.
textWriter.Flush(); | ||
// Write the updated file to memory | ||
using(var memoryStream = new MemoryStream()) | ||
using(var textWriter = new StreamWriter(memoryStream, encoding: new UTF8Encoding(encoderShouldEmitUTF8Identifier: true))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nit - textWriter is probably now streamWriter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also instead of using
, I actually prefer to be explicit when it comes to doing file writes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean with that second comment? Neither stream is personally involved in writing the file to disk.
Allows for the more correct replacement and backup of files on the filesystem.
63cdb82
to
ab4af16
Compare
ab4af16
to
ce4181f
Compare
Aside from your |
Merged into stable at 5134b46. Thanks for the contributions!! This is going to add quite a bit in what it provides! |
Rewrites the XML serialization service in a few specific ways:
Closes #1047